Skip to content

Commit

Permalink
fix: store storage in map whether error or not
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 31, 2022
1 parent d31faab commit 8e1ed40
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/op/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func CreateStorage(ctx context.Context, storage model.Storage) error {
}
// already has an id
err = storageDriver.Init(ctx, storage)
storagesMap.Store(storage.MountPath, storageDriver)
if err != nil {
storageDriver.GetStorage().SetStatus(fmt.Sprintf("%+v", err.Error()))
MustSaveDriverStorage(storageDriver)
Expand All @@ -58,7 +59,6 @@ func CreateStorage(ctx context.Context, storage model.Storage) error {
MustSaveDriverStorage(storageDriver)
}
log.Debugf("storage %+v is created", storageDriver)
storagesMap.Store(storage.MountPath, storageDriver)
return nil
}

Expand All @@ -73,11 +73,11 @@ func LoadStorage(ctx context.Context, storage model.Storage) error {
}
storageDriver := driverNew()
err = storageDriver.Init(ctx, storage)
storagesMap.Store(storage.MountPath, storageDriver)
if err != nil {
return errors.Wrapf(err, "failed init storage but storage is already created")
}
log.Debugf("storage %+v is created", storageDriver)
storagesMap.Store(storage.MountPath, storageDriver)
return nil
}

Expand All @@ -93,10 +93,10 @@ func EnableStorage(ctx context.Context, id uint) error {
if err != nil {
return errors.WithMessage(err, "failed load storage")
}
// reget storage from db, because it maybe hava updated
// re-get storage from db, because it maybe hava updated
storage, err = db.GetStorageById(id)
if err != nil {
return errors.WithMessage(err, "failed reget storage again")
return errors.WithMessage(err, "failed re-get storage again")
}
storage.Disabled = false
err = db.UpdateStorage(storage)
Expand Down

0 comments on commit 8e1ed40

Please sign in to comment.