MCPcopy Index your code
hub / github.com/OpenListTeam/OpenList / UpdateStorage

Function UpdateStorage

internal/op/storage.go:222–258  ·  view source on GitHub ↗

UpdateStorage update storage get old storage first drop the storage then reinitialize

(ctx context.Context, storage model.Storage)

Source from the content-addressed store, hash-verified

220// get old storage first
221// drop the storage then reinitialize
222func 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
260func DeleteStorageById(ctx context.Context, id uint) error {
261 storage, err := db.GetStorageById(id)

Callers 1

UpdateStorageFunction · 0.92

Calls 11

GetStorageByIdFunction · 0.92
FixAndCleanPathFunction · 0.92
UpdateStorageFunction · 0.92
initStorageFunction · 0.85
callStorageHooksFunction · 0.85
DeleteDirectoryTreeMethod · 0.80
GetStorageByMountPathFunction · 0.70
NowMethod · 0.65
DeleteMethod · 0.65
DropMethod · 0.65

Tested by

no test coverage detected