]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-reass/main.go
Use more efficient ReadDir instead of Readdir
[nncp.git] / src / cmd / nncp-reass / main.go
index ac52eeb2e853f098ab75f811c0ebcc3cd5548467..fc71bd05e47e5ab793583705bcf5c374636d872b 100644 (file)
@@ -125,7 +125,8 @@ func process(ctx *nncp.Ctx, path string, keep, dryRun, stdout, dumpMeta bool) bo
                }
                var badSize bool
                if chunkNum+1 == len(chunksPaths) {
-                       badSize = uint64(fi.Size()) != metaPkt.FileSize%metaPkt.ChunkSize
+                       left := metaPkt.FileSize % metaPkt.ChunkSize
+                       badSize = left != 0 && uint64(fi.Size()) != left
                } else {
                        badSize = uint64(fi.Size()) != metaPkt.ChunkSize
                }
@@ -300,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