Skip to content

Commit

Permalink
accounts/keystore: rename skipKeyFile to nonKeyFile to better reveal …
Browse files Browse the repository at this point in the history
…the function purpose (ethereum#17290)
  • Loading branch information
gzliudan committed Jan 6, 2025
1 parent 6207595 commit f5e1b17
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions accounts/keystore/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er

var newLastMod time.Time
for _, fi := range files {
// Skip any non-key files from the folder
path := filepath.Join(keyDir, fi.Name())
fiInfo, err := fi.Info()
if err != nil {
log.Warn("scan get FileInfo", "err", err, "path", path)
}
if fiInfo == nil || skipKeyFile(fiInfo) {
// Skip any non-key files from the folder
if nonKeyFile(fi) {
log.Trace("Ignoring file on account scan", "path", path)
continue
}
// Gather the set of all and fresly modified files
all.Add(path)

modified := fiInfo.ModTime()
info, err := fi.Info()
if err != nil {
return nil, nil, nil, err
}
modified := info.ModTime()
if modified.After(fc.lastMod) {
mods.Add(path)
}
Expand All @@ -91,15 +91,14 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
return creates, deletes, updates, nil
}

// skipKeyFile ignores editor backups, hidden files and folders/symlinks.
func skipKeyFile(fi os.FileInfo) bool {
// nonKeyFile ignores editor backups, hidden files and folders/symlinks.
func nonKeyFile(fi os.DirEntry) bool {
// Skip editor backups and UNIX-style hidden files.
name := fi.Name()
if strings.HasSuffix(name, "~") || strings.HasPrefix(name, ".") {
if strings.HasSuffix(fi.Name(), "~") || strings.HasPrefix(fi.Name(), ".") {
return true
}
// Skip misc special files, directories (yes, symlinks too).
if fi.IsDir() || fi.Mode()&os.ModeType != 0 {
if fi.IsDir() || !fi.Type().IsRegular() {
return true
}
return false
Expand Down

0 comments on commit f5e1b17

Please sign in to comment.