2 glocate -- ZFS-diff-friendly locate-like utility
3 Copyright (C) 2022-2023 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 "github.com/dustin/go-humanize"
29 func printerSimple(ents chan Ent) {
30 for ent := range ents {
31 fmt.Println(nameJoin(ent.name))
35 func printerMachine(ents chan Ent) {
36 for ent := range ents {
38 strconv.FormatUint(uint64(ent.size), 10),
39 time.Unix(int64(ent.mtime), 0).Format("2006-01-02T15:04:05"),
45 type TreePrintEnt struct {
50 func laster(ents chan Ent, trees chan TreePrintEnt) {
52 for ent := range ents {
53 tree := TreePrintEnt{ent: entPrev}
54 if len(ent.name) < len(entPrev.name) {
60 trees <- TreePrintEnt{ent: entPrev}
64 func printerTree(ents chan Ent) {
65 trees := make(chan TreePrintEnt, 1<<10)
66 go laster(ents, trees)
69 for ent := range trees {
72 "%s\t[%s]\n", nameJoin(ent.ent.name),
73 humanize.IBytes(uint64(ent.ent.size)),
83 fmt.Printf("%s%s %s\t[%s] %s\n",
84 strings.Repeat("│ ", len(ent.ent.name)-2), box,
85 nameJoin(ent.ent.name), humanize.IBytes(uint64(ent.ent.size)),
86 time.Unix(ent.ent.mtime, 0).Format("2006-01-02"),