don't show size if is folder
This commit is contained in:
parent
4d929160d1
commit
09161611d0
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.burning.moe/celediel/gt/internal/filter"
|
"git.burning.moe/celediel/gt/internal/filter"
|
||||||
|
@ -20,6 +21,7 @@ type File struct {
|
||||||
name, path string
|
name, path string
|
||||||
filesize int64
|
filesize int64
|
||||||
modified time.Time
|
modified time.Time
|
||||||
|
isdir bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Files []File
|
type Files []File
|
||||||
|
@ -29,6 +31,7 @@ func (f File) Path() string { return f.path }
|
||||||
func (f File) Filename() string { return filepath.Join(f.path, f.name) }
|
func (f File) Filename() string { return filepath.Join(f.path, f.name) }
|
||||||
func (f File) Modified() time.Time { return f.modified }
|
func (f File) Modified() time.Time { return f.modified }
|
||||||
func (f File) Filesize() int64 { return f.filesize }
|
func (f File) Filesize() int64 { return f.filesize }
|
||||||
|
func (f File) IsDir() bool { return f.isdir }
|
||||||
|
|
||||||
func (fls Files) Table(width int) string {
|
func (fls Files) Table(width int) string {
|
||||||
// sort newest on top
|
// sort newest on top
|
||||||
|
@ -36,8 +39,13 @@ func (fls Files) Table(width int) string {
|
||||||
|
|
||||||
data := [][]string{}
|
data := [][]string{}
|
||||||
for _, file := range fls {
|
for _, file := range fls {
|
||||||
t := humanize.Time(file.modified)
|
var t, b string
|
||||||
b := humanize.Bytes(uint64(file.filesize))
|
t = humanize.Time(file.modified)
|
||||||
|
if file.isdir {
|
||||||
|
b = strings.Repeat("─", 3)
|
||||||
|
} else {
|
||||||
|
b = humanize.Bytes(uint64(file.filesize))
|
||||||
|
}
|
||||||
data = append(data, []string{
|
data = append(data, []string{
|
||||||
file.name,
|
file.name,
|
||||||
file.path,
|
file.path,
|
||||||
|
@ -101,6 +109,7 @@ func walk_dir(dir string, f *filter.Filter) (files Files) {
|
||||||
name: name,
|
name: name,
|
||||||
filesize: i.Size(),
|
filesize: i.Size(),
|
||||||
modified: i.ModTime(),
|
modified: i.ModTime(),
|
||||||
|
isdir: i.IsDir(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("ignoring file %s (%s)", name, info.ModTime())
|
log.Debugf("ignoring file %s (%s)", name, info.ModTime())
|
||||||
|
@ -139,6 +148,7 @@ func read_dir(dir string, f *filter.Filter) (files Files) {
|
||||||
path: path,
|
path: path,
|
||||||
modified: info.ModTime(),
|
modified: info.ModTime(),
|
||||||
filesize: info.Size(),
|
filesize: info.Size(),
|
||||||
|
isdir: info.IsDir(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("ignoring file %s (%s)", name, info.ModTime())
|
log.Debugf("ignoring file %s (%s)", name, info.ModTime())
|
||||||
|
|
|
@ -34,6 +34,7 @@ DeletionDate={date}`
|
||||||
type Info struct {
|
type Info struct {
|
||||||
name, ogpath string
|
name, ogpath string
|
||||||
path, trashinfo string
|
path, trashinfo string
|
||||||
|
isdir bool
|
||||||
trashed time.Time
|
trashed time.Time
|
||||||
filesize int64
|
filesize int64
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,7 @@ func (i Info) OGPath() string { return i.ogpath }
|
||||||
func (i Info) TrashInfo() string { return i.trashinfo }
|
func (i Info) TrashInfo() string { return i.trashinfo }
|
||||||
func (i Info) Trashed() time.Time { return i.trashed }
|
func (i Info) Trashed() time.Time { return i.trashed }
|
||||||
func (i Info) Filesize() int64 { return i.filesize }
|
func (i Info) Filesize() int64 { return i.filesize }
|
||||||
|
func (i Info) IsDir() bool { return i.isdir }
|
||||||
|
|
||||||
func (is Infos) Table(width int) string {
|
func (is Infos) Table(width int) string {
|
||||||
|
|
||||||
|
@ -53,8 +55,13 @@ func (is Infos) Table(width int) string {
|
||||||
slices.SortStableFunc(is, SortByTrashedReverse)
|
slices.SortStableFunc(is, SortByTrashedReverse)
|
||||||
out := [][]string{}
|
out := [][]string{}
|
||||||
for _, file := range is {
|
for _, file := range is {
|
||||||
t := humanize.Time(file.trashed)
|
var t, b string
|
||||||
b := humanize.Bytes(uint64(file.filesize))
|
t = humanize.Time(file.trashed)
|
||||||
|
if file.isdir {
|
||||||
|
b = strings.Repeat("─", 3)
|
||||||
|
} else {
|
||||||
|
b = humanize.Bytes(uint64(file.filesize))
|
||||||
|
}
|
||||||
out = append(out, []string{
|
out = append(out, []string{
|
||||||
file.name,
|
file.name,
|
||||||
filepath.Dir(file.ogpath),
|
filepath.Dir(file.ogpath),
|
||||||
|
@ -119,6 +126,7 @@ func FindFiles(trashdir, ogdir string, f *filter.Filter) (files Infos, outerr er
|
||||||
ogpath: basepath,
|
ogpath: basepath,
|
||||||
trashinfo: path,
|
trashinfo: path,
|
||||||
trashed: date,
|
trashed: date,
|
||||||
|
isdir: info.IsDir(),
|
||||||
filesize: info.Size(),
|
filesize: info.Size(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue