]> Sergey Matveev's repositories - glocate.git/blobdiff - diff.go
Use Go 1.24
[glocate.git] / diff.go
diff --git a/diff.go b/diff.go
index dda4fd9ded52ee8109d30cbf1974527600de590be43819023d0df4ab8fbb91f4..fcbd08a2185245514d4e0871da192cc6d6713e49cfa604f44fb0f727538eab48 100644 (file)
--- a/diff.go
+++ b/diff.go
@@ -1,3 +1,18 @@
+// glocate -- ZFS-diff-friendly locate-like utility
+// Copyright (C) 2022-2025 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
 package main
 
 import (
@@ -5,6 +20,7 @@ import (
        "io"
        "log"
        "os"
+       "slices"
        "sort"
        "strings"
 )
@@ -61,6 +77,7 @@ func updateWithDiff(dbPath, strip string) *os.File {
                }
                isDir = cols[1] == "/"
                name := deoctalize(strings.TrimPrefix(cols[2], strip))
+               name = strings.TrimRight(name, "/")
                if name == "" {
                        continue
                }
@@ -117,10 +134,7 @@ func updateWithDiff(dbPath, strip string) *os.File {
                        if len(rens) > 0 {
                                if hasPrefix(ent.name, rens[0].src) {
                                        dels = append(dels, ent.name)
-                                       dst := append(
-                                               append([]string{}, rens[0].dst...),
-                                               ent.name[len(rens[0].src):]...,
-                                       )
+                                       dst := slices.Concat(rens[0].dst, ent.name[len(rens[0].src):])
                                        adds = append(adds, dst)
                                        mods = append(mods, &Ent{name: dst})
                                        if !met {
@@ -175,7 +189,7 @@ func updateWithDiff(dbPath, strip string) *os.File {
        if err != nil {
                log.Fatalln(err)
        }
-       tmp0, err := os.CreateTemp("", "glocate-idx")
+       tmp0, err := os.CreateTemp(TmpDir, "glocate-idx")
        if err != nil {
                log.Fatalln(err)
        }
@@ -222,6 +236,9 @@ func updateWithDiff(dbPath, strip string) *os.File {
                        ent.size = mods[0].size
                        mods = mods[1:]
                }
+               if ent.IsDir() {
+                       ent.size = 0
+               }
                entsDirSizer <- ent
        }
        for len(adds) > 0 {