-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfileinfo.go
53 lines (45 loc) · 1.3 KB
/
fileinfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// fileinfo.go contains FileInfo struct with what is known
// of individual file/folder in the list and methods to fetch this info
package main
import (
"os"
humanize "github.com/dustin/go-humanize"
)
// FileInfo is to store everything known about the file object
type FileInfo struct {
f os.FileInfo
special string // description for symlinks, device files and named pipes or unix domain sockets, empty otherwise
description string
hidden bool
}
// Description yeilds description line appropriate to the running mode
func (fi FileInfo) Description() (description string) {
switch {
case mode.size:
description = fi.representSize()
case mode.time && mode.long:
description = fi.representTimeDetailed()
case mode.time:
description = fi.representTime()
case mode.summary:
description = fi.special
if fi.description != "" {
description += "[DEFAULT](" + fi.description + ")"
}
default:
description = fi.description
}
return
}
func (fi FileInfo) representSize() string {
if fi.f.IsDir() {
return fi.description
}
return humanize.Bytes(uint64(fi.f.Size()))
}
func (fi FileInfo) representTimeDetailed() string {
return humanize.Time(fi.f.ModTime()) + " (" + fi.f.ModTime().String() + ")"
}
func (fi FileInfo) representTime() string {
return humanize.Time(fi.f.ModTime())
}