From 9a9ef040e3be057227b14d43c0be1549bf5b1d67 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 6 Dec 2022 11:54:44 +0000 Subject: [PATCH] vfs: fix reload: failed to add virtual dir entry: file does not exist This error happened on a restart of the VFS with files to upload into a new directory on a bucket based backend. Rclone was assuming that directories created before the restart would still exist, but this is a bad assumption for bucket based backends which don't really have directories. This change creates the pretend directory and thus the directory cache if the parent directory does not exist when adding a virtual on a backend which can't have empty directories. See: https://forum.rclone.org/t/that-pesky-failed-to-reload-error-message/34527 --- vfs/vfs.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/vfs/vfs.go b/vfs/vfs.go index f12e6c3ad..00faadf2e 100644 --- a/vfs/vfs.go +++ b/vfs/vfs.go @@ -737,8 +737,17 @@ func (vfs *VFS) ReadFile(filename string) (b []byte, err error) { } // AddVirtual adds the object (file or dir) to the directory cache -func (vfs *VFS) AddVirtual(remote string, size int64, isDir bool) error { - dir, leaf, err := vfs.StatParent(remote) +func (vfs *VFS) AddVirtual(remote string, size int64, isDir bool) (err error) { + remote = strings.TrimRight(remote, "/") + var dir *Dir + var parent, leaf string + if vfs.f.Features().CanHaveEmptyDirectories { + dir, leaf, err = vfs.StatParent(remote) + } else { + // Create parent of virtual directory since backend can't have empty directories + parent, leaf = path.Split(remote) + dir, err = vfs.mkdirAll(parent, vfs.Opt.DirPerms) + } if err != nil { return err }