diff --git a/drivers/onedrive/driver.go b/drivers/onedrive/driver.go index e01c1f7c1d..1d82b8c28a 100644 --- a/drivers/onedrive/driver.go +++ b/drivers/onedrive/driver.go @@ -52,16 +52,20 @@ func (d *Onedrive) InitReference(refStorage driver.Driver) error { } func (d *Onedrive) Drop(ctx context.Context) error { + d.mutex.Lock() + defer d.mutex.Unlock() + // RootFolderPath may change before this driver instance is reinitialized. + d.root = nil d.ref = nil return nil } func (d *Onedrive) GetRoot(ctx context.Context) (model.Obj, error) { + d.mutex.Lock() + defer d.mutex.Unlock() if d.root != nil { return d.root, nil } - d.mutex.Lock() - defer d.mutex.Unlock() root := &Object{ ObjThumb: model.ObjThumb{ Object: model.Object{ diff --git a/internal/op/storage.go b/internal/op/storage.go index da4c84e31b..42b8c9d8e3 100644 --- a/internal/op/storage.go +++ b/internal/op/storage.go @@ -237,14 +237,16 @@ func UpdateStorage(ctx context.Context, storage model.Storage) error { return nil } storageDriver, err := GetStorageByMountPath(oldStorage.MountPath) + if err != nil { + return errors.WithMessage(err, "failed get storage driver") + } + // Storage settings may change which objects are exposed at the same mount + // path, so cached entries must be discarded before reinitializing the driver. + Cache.DeleteDirectoryTree(storageDriver, "/") + Cache.InvalidateStorageDetails(storageDriver) if oldStorage.MountPath != storage.MountPath { // mount path renamed, need to drop the storage storagesMap.Delete(oldStorage.MountPath) - Cache.DeleteDirectoryTree(storageDriver, "/") - Cache.InvalidateStorageDetails(storageDriver) - } - if err != nil { - return errors.WithMessage(err, "failed get storage driver") } err = storageDriver.Drop(ctx) if err != nil {