-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request 386: 430-fix-system-hosts-file-path
Closes #430. Squashed commit of the following: commit 9f9870f Author: Stanislav Chzhen <[email protected]> Date: Fri Dec 27 17:16:17 2024 +0300 handler: imp docs commit f80639a Author: Stanislav Chzhen <[email protected]> Date: Fri Dec 27 16:49:41 2024 +0300 handler: imp tests commit ef2dd46 Author: Stanislav Chzhen <[email protected]> Date: Fri Dec 27 16:37:59 2024 +0300 handler: imp code commit 0f4241d Author: Stanislav Chzhen <[email protected]> Date: Fri Dec 27 16:00:08 2024 +0300 handler: fix ptr commit 64cc591 Author: Stanislav Chzhen <[email protected]> Date: Fri Dec 27 14:22:15 2024 +0300 all: imp code commit d16be8a Author: Stanislav Chzhen <[email protected]> Date: Thu Dec 26 22:01:30 2024 +0300 all: fix system hosts file path
- Loading branch information
Showing
7 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package netutil | ||
|
||
// DefaultHostsPaths returns the slice of default paths to system hosts files. | ||
// | ||
// TODO(s.chzhen): Since [fs.FS] is no longer needed, update the | ||
// [hostsfile.DefaultHostsPaths] from golibs. | ||
func DefaultHostsPaths() (paths []string, err error) { | ||
return defaultHostsPaths() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//go:build unix | ||
|
||
package netutil | ||
|
||
import "github.com/AdguardTeam/golibs/hostsfile" | ||
|
||
// defaultHostsPaths returns default paths to hosts files for UNIX. | ||
func defaultHostsPaths() (paths []string, err error) { | ||
paths, err = hostsfile.DefaultHostsPaths() | ||
if err != nil { | ||
// Should not happen because error is always nil. | ||
panic(err) | ||
} | ||
|
||
res := make([]string, 0, len(paths)) | ||
for _, p := range paths { | ||
res = append(res, "/"+p) | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build windows | ||
|
||
package netutil | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
// defaultHostsPaths returns default paths to hosts files for Windows. | ||
func defaultHostsPaths() (paths []string, err error) { | ||
sysDir, err := windows.GetSystemDirectory() | ||
if err != nil { | ||
return []string{}, fmt.Errorf("getting system directory: %w", err) | ||
} | ||
|
||
p := path.Join(sysDir, "drivers", "etc", "hosts") | ||
|
||
return []string{p}, nil | ||
} |