]> Cypherpunks.ru repositories - nncp.git/commitdiff
ioutil is deprecated since 1.16/1.17
authorSergey Matveev <stargrave@stargrave.org>
Sat, 29 Apr 2023 09:03:41 +0000 (12:03 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 29 Apr 2023 09:03:41 +0000 (12:03 +0300)
src/cfgdir.go
src/cmd/nncp-bundle/main.go
src/cmd/nncp-cfgdir/main.go
src/cmd/nncp-cfgenc/main.go
src/ctx.go
src/toss.go
src/toss_test.go
src/tx_test.go

index 7dd18f9a92643fb6bbaacd40eb7e453bfcd92491..c1346e27a4d67f1e10b97be6167ea0002f5f24ee 100644 (file)
@@ -19,7 +19,6 @@ package nncp
 
 import (
        "fmt"
-       "io/ioutil"
        "os"
        "path/filepath"
        "sort"
@@ -65,7 +64,7 @@ func cfgDirSave(v interface{}, dst ...string) error {
        if strings.HasSuffix(dst[len(dst)-1], "prv") {
                mode = os.FileMode(0600)
        }
-       return ioutil.WriteFile(filepath.Join(dst...), []byte(r+"\n"), mode)
+       return os.WriteFile(filepath.Join(dst...), []byte(r+"\n"), mode)
 }
 
 func cfgDirTouch(dst ...string) error {
@@ -433,7 +432,7 @@ func CfgToDir(dst string, cfg *CfgJSON) (err error) {
 }
 
 func cfgDirLoad(src ...string) (v string, exists bool, err error) {
-       b, err := ioutil.ReadFile(filepath.Join(src...))
+       b, err := os.ReadFile(filepath.Join(src...))
        if err != nil {
                if os.IsNotExist(err) {
                        return "", false, nil
@@ -531,7 +530,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                cfg.MCDRxIfis = strings.Split(*sp, "\n")
        }
 
-       fis, err := ioutil.ReadDir(filepath.Join(src, "mcd-send"))
+       fis, err := os.ReadDir(filepath.Join(src, "mcd-send"))
        if err != nil && !os.IsNotExist(err) {
                return nil, err
        }
@@ -543,7 +542,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                if n[0] == '.' {
                        continue
                }
-               b, err := ioutil.ReadFile(filepath.Join(src, "mcd-send", fi.Name()))
+               b, err := os.ReadFile(filepath.Join(src, "mcd-send", fi.Name()))
                if err != nil {
                        return nil, err
                }
@@ -565,7 +564,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                        return nil, err
                }
        }
-       fis, err = ioutil.ReadDir(filepath.Join(src, "notify", "exec"))
+       fis, err = os.ReadDir(filepath.Join(src, "notify", "exec"))
        if err != nil && !os.IsNotExist(err) {
                return nil, err
        }
@@ -582,7 +581,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                cfg.Notify = &notify
        }
 
-       if _, err = ioutil.ReadDir(filepath.Join(src, "self")); err == nil {
+       if _, err = os.ReadDir(filepath.Join(src, "self")); err == nil {
                self := NodeOurJSON{}
                if self.Id, err = cfgDirLoadMust(src, "self", "id"); err != nil {
                        return nil, err
@@ -611,7 +610,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
        }
 
        cfg.Neigh = make(map[string]NodeJSON)
-       fis, err = ioutil.ReadDir(filepath.Join(src, "neigh"))
+       fis, err = os.ReadDir(filepath.Join(src, "neigh"))
        if err != nil && !os.IsNotExist(err) {
                return nil, err
        }
@@ -638,7 +637,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                }
 
                node.Exec = make(map[string][]string)
-               fis2, err := ioutil.ReadDir(filepath.Join(src, "neigh", n, "exec"))
+               fis2, err := os.ReadDir(filepath.Join(src, "neigh", n, "exec"))
                if err != nil && !os.IsNotExist(err) {
                        return nil, err
                }
@@ -697,7 +696,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                }
 
                node.Addrs = make(map[string]string)
-               fis2, err = ioutil.ReadDir(filepath.Join(src, "neigh", n, "addrs"))
+               fis2, err = os.ReadDir(filepath.Join(src, "neigh", n, "addrs"))
                if err != nil && !os.IsNotExist(err) {
                        return nil, err
                }
@@ -747,7 +746,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                        node.MaxOnlineTime = &i
                }
 
-               fis2, err = ioutil.ReadDir(filepath.Join(src, "neigh", n, "calls"))
+               fis2, err = os.ReadDir(filepath.Join(src, "neigh", n, "calls"))
                if err != nil && !os.IsNotExist(err) {
                        return nil, err
                }
@@ -861,7 +860,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
        }
 
        cfg.Areas = make(map[string]AreaJSON)
-       fis, err = ioutil.ReadDir(filepath.Join(src, "areas"))
+       fis, err = os.ReadDir(filepath.Join(src, "areas"))
        if err != nil && !os.IsNotExist(err) {
                return nil, err
        }
@@ -890,7 +889,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                }
 
                area.Exec = make(map[string][]string)
-               fis2, err := ioutil.ReadDir(filepath.Join(src, "areas", n, "exec"))
+               fis2, err := os.ReadDir(filepath.Join(src, "areas", n, "exec"))
                if err != nil && !os.IsNotExist(err) {
                        return nil, err
                }
@@ -916,7 +915,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                cfg.Areas[n] = area
        }
 
-       fis, err = ioutil.ReadDir(filepath.Join(src, "yggdrasil-aliases"))
+       fis, err = os.ReadDir(filepath.Join(src, "yggdrasil-aliases"))
        if err != nil && !os.IsNotExist(err) {
                return nil, err
        }
@@ -928,7 +927,7 @@ func DirToCfg(src string) (*CfgJSON, error) {
                if n[0] == '.' {
                        continue
                }
-               b, err := ioutil.ReadFile(filepath.Join(src, "yggdrasil-aliases", fi.Name()))
+               b, err := os.ReadFile(filepath.Join(src, "yggdrasil-aliases", fi.Name()))
                if err != nil {
                        return nil, err
                }
index 5b43abb24066a59ea031c1a5670893d3deb7c7b4..e00da48002f49efe3c19c4d39b1684ab4daeb8c8 100644 (file)
@@ -26,7 +26,6 @@ import (
        "flag"
        "fmt"
        "io"
-       "io/ioutil"
        "log"
        "os"
        "path/filepath"
@@ -461,7 +460,7 @@ func main() {
                                }
                        } else {
                                if *dryRun {
-                                       if _, err = nncp.CopyProgressed(ioutil.Discard, tarR, "Rx", les, ctx.ShowPrgrs); err != nil {
+                                       if _, err = nncp.CopyProgressed(io.Discard, tarR, "Rx", les, ctx.ShowPrgrs); err != nil {
                                                log.Fatalln("Error during copying:", err)
                                        }
                                } else {
index 6a8366d97c8578dc6f1c4b290fa86a144be93bd0..5697feec32bc384f372be2ad86d11632810876fd 100644 (file)
@@ -21,7 +21,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
 
@@ -63,7 +62,7 @@ func main() {
        }
 
        if *doDump {
-               cfgRaw, err := ioutil.ReadFile(*cfgPath)
+               cfgRaw, err := os.ReadFile(*cfgPath)
                if err != nil {
                        log.Fatalln(err)
                }
index 5fc83e2a519ee6ccece1e17dd861d1c061c895e2..c1ac70e40565b646de9fc7af33900790cbe9bdd1 100644 (file)
@@ -23,7 +23,6 @@ import (
        "errors"
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "os"
 
@@ -70,7 +69,7 @@ func main() {
                os.Exit(1)
        }
 
-       data, err := ioutil.ReadFile(flag.Arg(0))
+       data, err := os.ReadFile(flag.Arg(0))
        if err != nil {
                log.Fatalln("Can not read data:", err)
        }
index cb1f1f4109ce443aed8ed148f99e5295694cdd34..6232972d47a28cd6d77b5ebea6b359026b7327e2 100644 (file)
@@ -20,7 +20,6 @@ package nncp
 import (
        "errors"
        "fmt"
-       "io/ioutil"
        "os"
        "path/filepath"
        "strconv"
@@ -119,7 +118,7 @@ func CtxFromCmdline(
                        return nil, err
                }
        } else {
-               cfgRaw, err := ioutil.ReadFile(cfgPath)
+               cfgRaw, err := os.ReadFile(cfgPath)
                if err != nil {
                        return nil, err
                }
index 2d7eeede063884e855cfe119b9f8cb9c2cca64f3..2fab0a2e8cb3a304323e2e65a6c5bfdf687430d5 100644 (file)
@@ -24,7 +24,6 @@ import (
        "errors"
        "fmt"
        "io"
-       "io/ioutil"
        "log"
        "mime"
        "os"
@@ -475,7 +474,7 @@ func jobProcess(
                        )
                        return err
                }
-               dstRaw, err := ioutil.ReadAll(pipeR)
+               dstRaw, err := io.ReadAll(pipeR)
                if err != nil {
                        ctx.LogE("rx-read", les, err, func(les LEs) string {
                                return fmt.Sprintf(
index 966b2b84ae4a0914d42ad2681e64dbca6b4e4bc1..aea765d9ec602057ec9cc6193966bf374417a823 100644 (file)
@@ -22,7 +22,6 @@ import (
        "crypto/rand"
        "fmt"
        "io"
-       "io/ioutil"
        "os"
        "path/filepath"
        "strconv"
@@ -56,7 +55,7 @@ func TestTossExec(t *testing.T) {
                for i, recipient := range recipients {
                        recipients[i] = recipient % 8
                }
-               spool, err := ioutil.TempDir("", "testtoss")
+               spool, err := os.MkdirTemp("", "testtoss")
                if err != nil {
                        panic(err)
                }
@@ -138,7 +137,7 @@ func TestTossExec(t *testing.T) {
                                return false
                        }
                }
-               mbox, err := ioutil.ReadFile(filepath.Join(spool, "mbox"))
+               mbox, err := os.ReadFile(filepath.Join(spool, "mbox"))
                if err != nil {
                        return false
                }
@@ -174,7 +173,7 @@ func TestTossFile(t *testing.T) {
                        }
                        files[strconv.Itoa(i)] = data
                }
-               spool, err := ioutil.TempDir("", "testtoss")
+               spool, err := os.MkdirTemp("", "testtoss")
                if err != nil {
                        panic(err)
                }
@@ -200,7 +199,7 @@ func TestTossFile(t *testing.T) {
                        hasher.Write(fileData)
                        fileName := Base32Codec.EncodeToString(hasher.Sum(nil))
                        src := filepath.Join(spool, fileName)
-                       if err := ioutil.WriteFile(src, fileData, os.FileMode(0600)); err != nil {
+                       if err := os.WriteFile(src, fileData, os.FileMode(0600)); err != nil {
                                panic(err)
                        }
                        if err := ctx.TxFile(
@@ -236,7 +235,7 @@ func TestTossFile(t *testing.T) {
                        hasher := MTHNew(0, 0)
                        hasher.Write(fileData)
                        fileName := Base32Codec.EncodeToString(hasher.Sum(nil))
-                       data, err := ioutil.ReadFile(filepath.Join(incomingPath, fileName))
+                       data, err := os.ReadFile(filepath.Join(incomingPath, fileName))
                        if err != nil {
                                panic(err)
                        }
@@ -254,7 +253,7 @@ func TestTossFile(t *testing.T) {
 func TestTossFileSameName(t *testing.T) {
        f := func(filesRaw uint8) bool {
                files := int(filesRaw)%8 + 1
-               spool, err := ioutil.TempDir("", "testtoss")
+               spool, err := os.MkdirTemp("", "testtoss")
                if err != nil {
                        panic(err)
                }
@@ -275,7 +274,7 @@ func TestTossFileSameName(t *testing.T) {
                }
                ctx.Neigh[*nodeOur.Id] = nodeOur.Their()
                srcPath := filepath.Join(spool, "junk")
-               if err = ioutil.WriteFile(
+               if err = os.WriteFile(
                        srcPath,
                        []byte("doesnotmatter"),
                        os.FileMode(0600),
@@ -327,7 +326,7 @@ func TestTossFreq(t *testing.T) {
                if len(fileSizes) == 0 {
                        return true
                }
-               spool, err := ioutil.TempDir("", "testtoss")
+               spool, err := os.MkdirTemp("", "testtoss")
                if err != nil {
                        panic(err)
                }
@@ -387,7 +386,7 @@ func TestTossFreq(t *testing.T) {
                        return false
                }
                for fileName, fileData := range files {
-                       if err := ioutil.WriteFile(
+                       if err := os.WriteFile(
                                filepath.Join(spool, fileName),
                                fileData,
                                os.FileMode(0600),
@@ -445,7 +444,7 @@ func TestTossTrns(t *testing.T) {
                        }
                        datum[i] = data
                }
-               spool, err := ioutil.TempDir("", "testtoss")
+               spool, err := os.MkdirTemp("", "testtoss")
                if err != nil {
                        panic(err)
                }
@@ -491,7 +490,7 @@ func TestTossTrns(t *testing.T) {
                        }
                        hasher := MTHNew(0, 0)
                        hasher.Write(dst.Bytes())
-                       if err := ioutil.WriteFile(
+                       if err := os.WriteFile(
                                filepath.Join(rxPath, Base32Codec.EncodeToString(hasher.Sum(nil))),
                                dst.Bytes(),
                                os.FileMode(0600),
@@ -505,7 +504,7 @@ func TestTossTrns(t *testing.T) {
                        return false
                }
                for _, filename := range dirFiles(txPath) {
-                       dataRead, err := ioutil.ReadFile(filepath.Join(txPath, filename))
+                       dataRead, err := os.ReadFile(filepath.Join(txPath, filename))
                        if err != nil {
                                panic(err)
                        }
index ffe0edeade53ff0ce3d25ee440268614ed4309c2..4523b6343b8ba6ed17acea1b6f7662a82837af0d 100644 (file)
@@ -21,7 +21,6 @@ import (
        "bytes"
        "crypto/rand"
        "io"
-       "io/ioutil"
        "os"
        "path"
        "testing"
@@ -48,7 +47,7 @@ func TestTx(t *testing.T) {
                        pathSrc = pathSrc[:MaxPathSize]
                }
                hops = hops % 4
-               spool, err := ioutil.TempDir("", "testtx")
+               spool, err := os.MkdirTemp("", "testtx")
                if err != nil {
                        panic(err)
                }