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
This commit is contained in:
Nick Craig-Wood 2022-12-06 11:54:44 +00:00
parent ca403dc90e
commit 9a9ef040e3
1 changed files with 11 additions and 2 deletions

View File

@ -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
}