From 015d2841db94f9641d8618b257c341e3919cd06d Mon Sep 17 00:00:00 2001 From: nova1751 Date: Sun, 27 Sep 2026 18:09:34 +0800 Subject: [PATCH] fix(onedrive): refresh root folder after storage update - Clear the cached OneDrive root when a driver is dropped and reinitialized. - Invalidate storage directory and detail caches for every configuration update. Co-authored-by: Codex <267193182+codex@users.noreply.github.com> --- drivers/onedrive/driver.go | 8 ++++++-- internal/op/storage.go | 12 +++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) 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 {