add dirtyfiles to windows

cc #729
This commit is contained in:
Gokcehan 2022-01-17 13:07:24 +03:00
parent 286bf75aa9
commit ac4bdccf8d
2 changed files with 28 additions and 28 deletions

28
nav.go
View File

@ -554,6 +554,34 @@ func (nav *nav) previewLoop(ui *ui) {
}
}
func isDirty(f os.FileInfo, path string, dirtyfiles []string) bool {
dirty := false
for _, pattern := range dirtyfiles {
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
if strings.HasPrefix(pattern, "!") && matched {
dirty = false
} else if matched {
dirty = true
}
}
return dirty
}
func matchPattern(pattern, name, path string) bool {
s := name
pattern = replaceTilde(pattern)
if filepath.IsAbs(pattern) {
s = filepath.Join(path, name)
}
// pattern errors are checked when 'hiddenfiles' option is set
matched, _ := filepath.Match(pattern, s)
return matched
}
func (nav *nav) preview(path string, win *win) {
reg := &reg{loadTime: time.Now(), path: path}
defer func() { nav.regChan <- reg }()

28
os.go
View File

@ -136,19 +136,6 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
return hidden
}
func isDirty(f os.FileInfo, path string, dirtyfiles []string) bool {
dirty := false
for _, pattern := range dirtyfiles {
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
if strings.HasPrefix(pattern, "!") && matched {
dirty = false
} else if matched {
dirty = true
}
}
return dirty
}
func userName(f os.FileInfo) string {
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil {
@ -174,21 +161,6 @@ func linkCount(f os.FileInfo) string {
return ""
}
func matchPattern(pattern, name, path string) bool {
s := name
pattern = replaceTilde(pattern)
if filepath.IsAbs(pattern) {
s = filepath.Join(path, name)
}
// pattern errors are checked when 'hiddenfiles' option is set
matched, _ := filepath.Match(pattern, s)
return matched
}
func errCrossDevice(err error) bool {
return err.(*os.LinkError).Err.(syscall.Errno) == syscall.EXDEV
}