diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-29 01:48:06 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-02-01 16:55:02 +0100 |
commit | fdf117deebe23b32bb4cdd4f84abb072dc4eb0cd (patch) | |
tree | 6ffa20f6a25e5f7ab76e2fbf49f2c08068587c92 /conf | |
parent | conf: don't sleep before failure in dns resolution (diff) | |
download | wireguard-windows-fdf117deebe23b32bb4cdd4f84abb072dc4eb0cd.tar.xz wireguard-windows-fdf117deebe23b32bb4cdd4f84abb072dc4eb0cd.zip |
global: move away from ioutil
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conf')
-rw-r--r-- | conf/migration_windows.go | 17 | ||||
-rw-r--r-- | conf/store.go | 14 |
2 files changed, 22 insertions, 9 deletions
diff --git a/conf/migration_windows.go b/conf/migration_windows.go index 0034d1f5..091efa32 100644 --- a/conf/migration_windows.go +++ b/conf/migration_windows.go @@ -7,7 +7,7 @@ package conf import ( "errors" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -30,7 +30,7 @@ func migrateUnencryptedConfigs(sharingBase int) { if err != nil { return } - files, err := ioutil.ReadDir(configFileDir) + files, err := os.ReadDir(configFileDir) if err != nil { return } @@ -41,13 +41,20 @@ func migrateUnencryptedConfigs(sharingBase int) { if len(name) <= len(configFileUnencryptedSuffix) || !strings.HasSuffix(name, configFileUnencryptedSuffix) { continue } - if !file.Mode().IsRegular() || file.Mode().Perm()&0444 == 0 { + if !file.Type().IsRegular() { + continue + } + info, err := file.Info() + if err != nil { + continue + } + if info.Mode().Perm()&0444 == 0 { continue } var bytes []byte var config *Config - // We don't use ioutil's ReadFile, because we actually want RDWR, so that we can take advantage + // We don't use os.ReadFile, because we actually want RDWR, so that we can take advantage // of Windows file locking for ensuring the file is finished being written. f, err := os.OpenFile(path, os.O_RDWR, 0) if err != nil { @@ -65,7 +72,7 @@ func migrateUnencryptedConfigs(sharingBase int) { } goto error } - bytes, err = ioutil.ReadAll(f) + bytes, err = io.ReadAll(f) f.Close() if err != nil { goto error diff --git a/conf/store.go b/conf/store.go index 7337a6ab..f6f450c6 100644 --- a/conf/store.go +++ b/conf/store.go @@ -7,7 +7,6 @@ package conf import ( "errors" - "io/ioutil" "os" "path/filepath" "strings" @@ -23,7 +22,7 @@ func ListConfigNames() ([]string, error) { if err != nil { return nil, err } - files, err := ioutil.ReadDir(configFileDir) + files, err := os.ReadDir(configFileDir) if err != nil { return nil, err } @@ -34,7 +33,14 @@ func ListConfigNames() ([]string, error) { if len(name) <= len(configFileSuffix) || !strings.HasSuffix(name, configFileSuffix) { continue } - if !file.Mode().IsRegular() || file.Mode().Perm()&0444 == 0 { + if !file.Type().IsRegular() { + continue + } + info, err := file.Info() + if err != nil { + continue + } + if info.Mode().Perm()&0444 == 0 { continue } name = strings.TrimSuffix(name, configFileSuffix) @@ -60,7 +66,7 @@ func LoadFromPath(path string) (*Config, error) { if err != nil { return nil, err } - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { return nil, err } |