MCPcopy Create free account
hub / github.com/gokcehan/lf / newFile

Function newFile

nav.go:48–128  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

46}
47
48func newFile(path string) *file {
49 lstat, err := os.Lstat(path)
50 if err != nil {
51 log.Printf("getting file information: %s", err)
52 return &file{
53 FileInfo: &fakeStat{name: filepath.Base(path)},
54 linkState: notLink,
55 path: path,
56 dirCount: -1,
57 dirSize: -1,
58 accessTime: time.Unix(0, 0),
59 birthTime: time.Unix(0, 0),
60 changeTime: time.Unix(0, 0),
61 err: err,
62 }
63 }
64
65 var linkState linkState
66 var linkTarget string
67
68 if lstat.Mode()&os.ModeSymlink != 0 {
69 stat, err := os.Stat(path)
70 if err == nil {
71 linkState = working
72 lstat = stat
73 } else {
74 linkState = broken
75 }
76 linkTarget, err = os.Readlink(path)
77 if err != nil {
78 log.Printf("reading link target: %s", err)
79 }
80 }
81
82 ts := times.Get(lstat)
83 at := ts.AccessTime()
84 // from [times.Timespec] docs:
85 // ChangeTime() panics unless HasChangeTime() is true and
86 // BirthTime() panics unless HasBirthTime() is true.
87
88 // default to ModTime if BirthTime cannot be determined
89 bt := lstat.ModTime()
90 if ts.HasBirthTime() {
91 bt = ts.BirthTime()
92 }
93 // default to ModTime if ChangeTime cannot be determined
94 ct := lstat.ModTime()
95 if ts.HasChangeTime() {
96 ct = ts.ChangeTime()
97 }
98
99 dirCount := -1
100 if lstat.IsDir() && getDirCounts(filepath.Dir(path)) {
101 d, err := os.Open(path)
102 if err != nil {
103 log.Printf("opening file: %s", err)
104 } else {
105 names, err := d.Readdirnames(10000)

Callers 2

readdirFunction · 0.85
processUpdateMethod · 0.85

Calls 5

getDirCountsFunction · 0.85
getFileExtensionFunction · 0.85
ModeMethod · 0.45
ModTimeMethod · 0.45
IsDirMethod · 0.45

Tested by

no test coverage detected