From 98bf65c43b7409e525af00afab616c180fcd3349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Wed, 2 May 2018 15:28:17 +0200 Subject: [PATCH] vfs: fix ChangeNotify for new or changed folders Fixes #2251 --- vfs/vfs.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vfs/vfs.go b/vfs/vfs.go index 053363483..3813a0817 100644 --- a/vfs/vfs.go +++ b/vfs/vfs.go @@ -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) +}