fix(storage): Fixed a potential null value issue with not checking firstMount.

- Added a check to see if `firstMount` is null to prevent logic errors.
- Adjusted the loading logic of `GetAllRoles` and `GetAllUsers` to only execute when `firstMount` is non-null.
- Fixed the `usedBy` check logic to ensure that an error message is returned under the correct conditions.
- Optimized code structure to reduce unnecessary execution paths.
pull/9322/head
okatu-loli 2025-09-12 14:22:13 +08:00
parent 3e2be10cf7
commit 66fd8d5ec8
1 changed files with 23 additions and 21 deletions

View File

@ -280,6 +280,7 @@ func DeleteStorageById(ctx context.Context, id uint) error {
return errors.WithMessage(err, "failed get storage")
}
firstMount := firstPathSegment(storage.MountPath)
if firstMount != "" {
roles, err := db.GetAllRoles()
if err != nil {
return errors.WithMessage(err, "failed to load roles")
@ -305,6 +306,7 @@ func DeleteStorageById(ctx context.Context, id uint) error {
if len(usedBy) > 0 {
return errors.Errorf("storage is used by %s, please cancel usage first", strings.Join(usedBy, ", "))
}
}
if !storage.Disabled {
storageDriver, err := GetStorageByMountPath(storage.MountPath)
if err != nil {