1 // glocate -- ZFS-diff-friendly locate-like utility
2 // Copyright (C) 2022-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
30 func walker(sink chan Ent, root []string) error {
31 files, err := os.ReadDir(path.Join(root...)) // it is already sorted
36 ents := make([]Ent, 0, len(files))
37 for _, file := range files {
38 ent := Ent{name: append([]string{}, append(root, file.Name())...)}
39 info, err = file.Info()
42 ent.name[len(ent.name)-1] += "/"
43 } else if info.Mode().IsRegular() {
44 ent.size = info.Size()
46 ent.mtime = info.ModTime().Unix()
48 log.Println("can not stat:", path.Join(ent.name...), ":", err)
50 ents = append(ents, ent)
52 for _, ent := range ents {
60 err = walker(sink, ent.name)
62 log.Println("can not stat:", path.Join(ent.name...), ":", err)