UpdateStorage update storage get old storage first drop the storage then reinitialize
(ctx context.Context, storage model.Storage)
| 220 | // get old storage first |
| 221 | // drop the storage then reinitialize |
| 222 | func UpdateStorage(ctx context.Context, storage model.Storage) error { |
| 223 | oldStorage, err := db.GetStorageById(storage.ID) |
| 224 | if err != nil { |
| 225 | return errors.WithMessage(err, "failed get old storage") |
| 226 | } |
| 227 | if oldStorage.Driver != storage.Driver { |
| 228 | return errors.Errorf("driver cannot be changed") |
| 229 | } |
| 230 | storage.Modified = time.Now() |
| 231 | storage.MountPath = utils.FixAndCleanPath(storage.MountPath) |
| 232 | err = db.UpdateStorage(&storage) |
| 233 | if err != nil { |
| 234 | return errors.WithMessage(err, "failed update storage in database") |
| 235 | } |
| 236 | if storage.Disabled { |
| 237 | return nil |
| 238 | } |
| 239 | storageDriver, err := GetStorageByMountPath(oldStorage.MountPath) |
| 240 | if oldStorage.MountPath != storage.MountPath { |
| 241 | // mount path renamed, need to drop the storage |
| 242 | storagesMap.Delete(oldStorage.MountPath) |
| 243 | Cache.DeleteDirectoryTree(storageDriver, "/") |
| 244 | Cache.InvalidateStorageDetails(storageDriver) |
| 245 | } |
| 246 | if err != nil { |
| 247 | return errors.WithMessage(err, "failed get storage driver") |
| 248 | } |
| 249 | err = storageDriver.Drop(ctx) |
| 250 | if err != nil { |
| 251 | return errors.Wrapf(err, "failed drop storage") |
| 252 | } |
| 253 | |
| 254 | err = initStorage(ctx, storage, storageDriver) |
| 255 | go callStorageHooks("update", storageDriver) |
| 256 | log.Debugf("storage %+v is update", storageDriver) |
| 257 | return err |
| 258 | } |
| 259 | |
| 260 | func DeleteStorageById(ctx context.Context, id uint) error { |
| 261 | storage, err := db.GetStorageById(id) |
no test coverage detected