Skip to content

Commit

Permalink
Fallback to ModTime if ChangeTime cannot be determined
Browse files Browse the repository at this point in the history
Also directly add ChangeTime to the file struct instead
`times.Timespec`
  • Loading branch information
caninemwenja committed Sep 13, 2019
1 parent a4489ec commit c1614cd
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const (

type file struct {
os.FileInfo
linkState linkState
path string
dirCount int
times times.Timespec
linkState linkState
path string
dirCount int
changeTime time.Time
}

func readdir(path string) ([]*file, error) {
Expand Down Expand Up @@ -65,17 +65,19 @@ func readdir(path string) ([]*file, error) {
}
}

// fall back to ModTime if ChangeTime cannot be determined
ct := lstat.ModTime()
ts, err := times.Stat(fpath)
if err != nil {
return files, err
if err == nil {
ct = ts.ChangeTime()
}

files = append(files, &file{
FileInfo: lstat,
linkState: linkState,
path: fpath,
dirCount: -1,
times: ts,
FileInfo: lstat,
linkState: linkState,
path: fpath,
dirCount: -1,
changeTime: ct,
})
}

Expand Down Expand Up @@ -135,7 +137,7 @@ func (dir *dir) sort() {
})
case ctimeSort:
sort.SliceStable(dir.files, func(i, j int) bool {
return dir.files[i].times.ChangeTime().Before(dir.files[j].times.ChangeTime())
return dir.files[i].changeTime.Before(dir.files[j].changeTime)
})
}

Expand Down

0 comments on commit c1614cd

Please sign in to comment.