MCPcopy
hub / github.com/direnv/direnv / Check

Method Check

internal/cmd/file_times.go:120–142  ·  view source on GitHub ↗

Check verifies that the file is good and hasn't changed

()

Source from the content-addressed store, hash-verified

118
119// Check verifies that the file is good and hasn't changed
120func (times *FileTime) Check() (err error) {
121 stat, err := getLatestStat(times.Path)
122
123 switch {
124 case os.IsNotExist(err):
125 if times.Exists {
126 logDebug("Stat Check: %s: gone", times.Path)
127 return checkFailed{fmt.Sprintf("File %q is missing (Stat)", times.Path)}
128 }
129 case err != nil:
130 logDebug("Stat Check: %s: ERR: %v", times.Path, err)
131 return err
132 case !times.Exists:
133 logDebug("Check: %s: appeared", times.Path)
134 return checkFailed{fmt.Sprintf("File %q newly created", times.Path)}
135 case stat.ModTime().Unix() != times.Modtime:
136 logDebug("Check: %s: stale (stat: %v, lastcheck: %v)",
137 times.Path, stat.ModTime().Unix(), times.Modtime)
138 return checkFailed{fmt.Sprintf("File %q has changed", times.Path)}
139 }
140 logDebug("Check: %s: up to date", times.Path)
141 return nil
142}
143
144// Formatted shows the times in a user-friendly format.
145func (times *FileTime) Formatted(relDir string) string {

Callers 3

CheckMethod · 0.45
CheckOneMethod · 0.45
exportCommandFunction · 0.45

Calls 2

getLatestStatFunction · 0.85
logDebugFunction · 0.85

Tested by

no test coverage detected