]> Cypherpunks.ru repositories - nncp.git/commitdiff
Use more efficient ReadDir instead of Readdir
authorSergey Matveev <stargrave@stargrave.org>
Sun, 4 Jun 2023 08:38:43 +0000 (11:38 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 4 Jun 2023 08:38:43 +0000 (11:38 +0300)
src/cmd/nncp-reass/main.go
src/cmd/nncp-xfer/main.go

index e92a2e59307f1d5f2c5580d5d8992053106cb0a6..fc71bd05e47e5ab793583705bcf5c374636d872b 100644 (file)
@@ -301,16 +301,16 @@ func findMetas(ctx *nncp.Ctx, dirPath string) []string {
                return nil
        }
        defer dir.Close()
-       fis, err := dir.Readdir(0)
+       entries, err := dir.ReadDir(0)
        dir.Close()
        if err != nil {
                ctx.LogE("reass", nncp.LEs{{K: "Path", V: dirPath}}, err, logMsg)
                return nil
        }
        metaPaths := make([]string, 0)
-       for _, fi := range fis {
-               if strings.HasSuffix(fi.Name(), nncp.ChunkedSuffixMeta) {
-                       metaPaths = append(metaPaths, filepath.Join(dirPath, fi.Name()))
+       for _, entry := range entries {
+               if strings.HasSuffix(entry.Name(), nncp.ChunkedSuffixMeta) {
+                       metaPaths = append(metaPaths, filepath.Join(dirPath, entry.Name()))
                }
        }
        return metaPaths
index 016c441510cda5215a363b06ecec1805616a2ab6..73a6fc223b6d70d194485496cc53af7f0ec0c61c 100644 (file)
@@ -106,7 +106,7 @@ func main() {
        selfPath := filepath.Join(flag.Arg(0), ctx.SelfId.String())
        isBad := false
        var dir *os.File
-       var fis []os.FileInfo
+       var entries []os.DirEntry
        var les nncp.LEs
        var logMsg func(les nncp.LEs) string
        if *txOnly {
@@ -141,7 +141,7 @@ func main() {
                isBad = true
                goto Tx
        }
-       fis, err = dir.Readdir(0)
+       entries, err = dir.ReadDir(0)
        dir.Close()
        if err != nil {
                ctx.LogE("xfer-self-read", les, err, func(les nncp.LEs) string {
@@ -150,12 +150,12 @@ func main() {
                isBad = true
                goto Tx
        }
-       for _, fi := range fis {
-               if !fi.IsDir() {
+       for _, entry := range entries {
+               if !entry.IsDir() {
                        continue
                }
-               nodeId, err := nncp.NodeIdFromString(fi.Name())
-               les := append(les, nncp.LE{K: "Node", V: fi.Name()})
+               nodeId, err := nncp.NodeIdFromString(entry.Name())
+               les := append(les, nncp.LE{K: "Node", V: entry.Name()})
                logMsg := func(les nncp.LEs) string {
                        return "Packet transfer, received from " + ctx.NodeName(nodeId)
                }
@@ -177,7 +177,7 @@ func main() {
                        })
                        continue
                }
-               dir, err = os.Open(filepath.Join(selfPath, fi.Name()))
+               dir, err = os.Open(filepath.Join(selfPath, entry.Name()))
                if err != nil {
                        ctx.LogE("xfer-rx-open", les, err, func(les nncp.LEs) string {
                                return logMsg(les) + ": opening"