22 lines
486 B
Go
22 lines
486 B
Go
//go:build linux
|
|||
|
|
|
||
|
|
package platform
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
)
|
||
|
|
|
||
|
|
// GetHostsFilePath returns the absolute path to the system hosts file on Linux.
|
||
|
|
// Returns an error if the file does not exist or cannot be accessed.
|
||
|
|
func GetHostsFilePath() (string, error) {
|
||
|
|
path := "/etc/hosts"
|
||
|
|
if _, err := os.Stat(path); err != nil {
|
||
|
|
if os.IsNotExist(err) {
|
||
|
|
return "", fmt.Errorf("file does not exist: %s", path)
|
||
|
|
}
|
||
|
|
return "", fmt.Errorf("accessing hosts file: %w", err)
|
||
|
|
}
|
||
|
|
return path, nil
|
||
|
|
}
|