]> Sergey Matveev's repositories - glocate.git/blobdiff - diff.go
Raise copyright years
[glocate.git] / diff.go
diff --git a/diff.go b/diff.go
index 61ba1ac9f83e9f80cb3ac2a7b81e88079e1e9a2d3a8e8afabd34f0485b739d9f..15de2cde8a6963476915f84f26a69044160d6aa7cf27ce732082a37292257fd4 100644 (file)
--- a/diff.go
+++ b/diff.go
@@ -1,3 +1,20 @@
+/*
+glocate -- ZFS-diff-friendly locate-like utility
+Copyright (C) 2022-2023 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 (
@@ -61,6 +78,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
                }
@@ -105,7 +123,7 @@ func updateWithDiff(dbPath, strip string) *os.File {
        mods := make([]*Ent, 0, len(modsNames)+len(rens))
        if len(rens) > 0 {
                sort.Sort(BySrc(rens))
-               go reader(bufio.NewReaderSize(db, 1<<17), entsReader)
+               go reader(db, entsReader)
                var ent Ent
                var ok, met bool
                for {
@@ -175,7 +193,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)
        }
@@ -183,7 +201,7 @@ func updateWithDiff(dbPath, strip string) *os.File {
        entsReader = make(chan Ent, 1<<10)
        entsDirSizer := make(chan Ent, 1<<10)
        entsWriter := make(chan Ent, 1<<10)
-       go reader(bufio.NewReaderSize(db, 1<<17), entsReader)
+       go reader(db, entsReader)
 
        dirSizerJob := make(chan struct{})
        var dirSizes []int64
@@ -193,10 +211,9 @@ func updateWithDiff(dbPath, strip string) *os.File {
                close(dirSizerJob)
        }()
 
-       bw := bufio.NewWriterSize(tmp0, 1<<17)
        writerJob := make(chan struct{})
        go func() {
-               writer(bw, entsWriter)
+               writer(tmp0, entsWriter)
                close(writerJob)
        }()
 
@@ -223,6 +240,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 {
@@ -243,9 +263,6 @@ func updateWithDiff(dbPath, strip string) *os.File {
        <-dirSizerJob
        close(entsWriter)
        <-writerJob
-       if err = bw.Flush(); err != nil {
-               log.Fatalln(err)
-       }
 
        tmp1 := applyDirSizes(tmp0, dirSizes)
        tmp0.Close()