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 | |
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>
-rw-r--r-- | conf/migration_windows.go | 17 | ||||
-rw-r--r-- | conf/store.go | 14 | ||||
-rw-r--r-- | gotext.go | 7 | ||||
-rw-r--r-- | manager/legacystore.go | 4 | ||||
-rw-r--r-- | ui/tunnelspage.go | 6 | ||||
-rw-r--r-- | updater/winhttp/winhttp_test.go | 3 |
6 files changed, 31 insertions, 20 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 } @@ -10,7 +10,6 @@ package main import ( "encoding/json" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -20,7 +19,7 @@ import ( ) func main() { - langDirs, err := ioutil.ReadDir("locales") + langDirs, err := os.ReadDir("locales") if err != nil { panic(err) } @@ -30,7 +29,7 @@ func main() { continue } lang := dir.Name() - if jsonData, err := ioutil.ReadFile(filepath.Join("locales", lang, "messages.gotext.json")); err == nil { + if jsonData, err := os.ReadFile(filepath.Join("locales", lang, "messages.gotext.json")); err == nil { var translations pipeline.Messages if err := json.Unmarshal(jsonData, &translations); err != nil { panic(err) @@ -50,7 +49,7 @@ func main() { if len(langs) == 0 { panic("no locales found") } - gotext, err := ioutil.TempFile("", "gotext*.exe") + gotext, err := os.CreateTemp("", "gotext*.exe") if err != nil { panic(err) } diff --git a/manager/legacystore.go b/manager/legacystore.go index 524861d2..4125cb86 100644 --- a/manager/legacystore.go +++ b/manager/legacystore.go @@ -7,8 +7,8 @@ package manager import ( "fmt" - "io/ioutil" "log" + "os" "path/filepath" "regexp" "strings" @@ -26,7 +26,7 @@ func moveConfigsFromLegacyStore() { return } oldC := filepath.Join(oldRoot, "WireGuard", "Configurations") - files, err := ioutil.ReadDir(oldC) + files, err := os.ReadDir(oldC) if err != nil { return } diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go index f8eba2ef..10bf2f8e 100644 --- a/ui/tunnelspage.go +++ b/ui/tunnelspage.go @@ -9,7 +9,7 @@ import ( "archive/zip" "errors" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "sort" @@ -297,7 +297,7 @@ func (tp *TunnelsPage) importFiles(paths []string) { for _, path := range paths { switch strings.ToLower(filepath.Ext(path)) { case ".conf": - textConfig, err := ioutil.ReadFile(path) + textConfig, err := os.ReadFile(path) if err != nil { lastErr = err continue @@ -321,7 +321,7 @@ func (tp *TunnelsPage) importFiles(paths []string) { lastErr = err continue } - textConfig, err := ioutil.ReadAll(rc) + textConfig, err := io.ReadAll(rc) rc.Close() if err != nil { lastErr = err diff --git a/updater/winhttp/winhttp_test.go b/updater/winhttp/winhttp_test.go index 96b17021..41fbeb6b 100644 --- a/updater/winhttp/winhttp_test.go +++ b/updater/winhttp/winhttp_test.go @@ -8,7 +8,6 @@ package winhttp import ( "fmt" "io" - "io/ioutil" "runtime" "testing" ) @@ -40,7 +39,7 @@ func TestResponse(t *testing.T) { t.Fatal(err) } fmt.Printf("The length is %d\n", length) - bytes, err := ioutil.ReadAll(r) + bytes, err := io.ReadAll(r) if err != nil { t.Fatal(err) } |