in lib/store/base/file_op.go [116:152]
func (op *localFileOp) reloadFileEntryHelper(name string) (reloaded bool, err error) {
if op.s.fileMap.Contains(name) {
return false, nil
}
// Check if file exists on disk.
// TODO: The states need to be guaranteed to be topologically sorted.
for state := range op.states {
fileEntry, err := op.s.fileEntryFactory.Create(name, state)
if err != nil {
return false, fmt.Errorf("create: %s", err)
}
// Try load before acquiring lock first.
if err = fileEntry.Reload(); err != nil {
continue
}
// Try to store file entry into memory.
if stored := op.s.fileMap.TryStore(name, fileEntry, func(name string, entry FileEntry) bool {
// Verify the file is still on disk.
err = entry.Reload()
return err == nil
}); err != nil {
if os.IsNotExist(err) {
continue
}
return false, err
} else if !stored {
// The entry was just reloaded by another goroutine, return true.
// Since TryStore() updates LAT of existing entry, it's unlikely
// that the entry would be deleted before this function returns.
return true, nil
}
return true, nil
}
return false, os.ErrNotExist
}