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/>.
24 "github.com/dustin/go-humanize"
27 func printerSimple(ents chan Ent) {
28 for ent := range ents {
29 fmt.Println(nameJoin(ent.name))
33 func printerMachine(ents chan Ent) {
34 for ent := range ents {
36 strconv.FormatUint(uint64(ent.size), 10),
37 time.Unix(int64(ent.mtime), 0).Format("2006-01-02T15:04:05"),
43 type TreePrintEnt struct {
48 func laster(ents chan Ent, trees chan TreePrintEnt) {
50 for ent := range ents {
51 tree := TreePrintEnt{ent: entPrev}
52 if len(ent.name) < len(entPrev.name) {
58 trees <- TreePrintEnt{ent: entPrev}
62 func printerTree(ents chan Ent) {
63 trees := make(chan TreePrintEnt, 1<<10)
64 go laster(ents, trees)
67 for ent := range trees {
70 "%s\t[%s]\n", nameJoin(ent.ent.name),
71 humanize.IBytes(uint64(ent.ent.size)),
81 fmt.Printf("%s%s %s\t[%s] %s\n",
82 strings.Repeat("│ ", len(ent.ent.name)-2), box,
83 nameJoin(ent.ent.name), humanize.IBytes(uint64(ent.ent.size)),
84 time.Unix(ent.ent.mtime, 0).Format("2006-01-02"),