vfs: fix ChangeNotify for new or changed folders

Fixes #2251
This commit is contained in:
Fabian Möller 2018-05-02 15:28:17 +02:00 committed by Nick Craig-Wood
parent 3b5e70c8c6
commit 98bf65c43b

View File

@ -224,7 +224,7 @@ func New(f fs.Fs, opt *Options) *VFS {
// Start polling if required
if vfs.Opt.PollInterval > 0 {
if do := vfs.f.Features().ChangeNotify; do != nil {
do(vfs.root.ForgetPath, vfs.Opt.PollInterval)
do(vfs.notifyFunc, vfs.Opt.PollInterval)
} else {
fs.Infof(f, "poll-interval is not supported by this remote")
}
@ -495,3 +495,13 @@ func (vfs *VFS) Statfs() (total, used, free int64) {
}
return
}
// notifyFunc removes the last path segement for directories and calls ForgetPath with the result.
//
// This ensures that new or renamed directories appear in their parent.
func (vfs *VFS) notifyFunc(relativePath string, entryType fs.EntryType) {
if entryType == fs.EntryDirectory {
relativePath = path.Dir(relativePath)
}
vfs.root.ForgetPath(relativePath, entryType)
}