mirror of
https://github.com/AlistGo/alist.git
synced 2025-12-19 02:50:06 +08:00
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.
This commit is contained in:
parent
3e2be10cf7
commit
66fd8d5ec8
@ -280,6 +280,7 @@ func DeleteStorageById(ctx context.Context, id uint) error {
|
|||||||
return errors.WithMessage(err, "failed get storage")
|
return errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
firstMount := firstPathSegment(storage.MountPath)
|
firstMount := firstPathSegment(storage.MountPath)
|
||||||
|
if firstMount != "" {
|
||||||
roles, err := db.GetAllRoles()
|
roles, err := db.GetAllRoles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed to load roles")
|
return errors.WithMessage(err, "failed to load roles")
|
||||||
@ -305,6 +306,7 @@ func DeleteStorageById(ctx context.Context, id uint) error {
|
|||||||
if len(usedBy) > 0 {
|
if len(usedBy) > 0 {
|
||||||
return errors.Errorf("storage is used by %s, please cancel usage first", strings.Join(usedBy, ", "))
|
return errors.Errorf("storage is used by %s, please cancel usage first", strings.Join(usedBy, ", "))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if !storage.Disabled {
|
if !storage.Disabled {
|
||||||
storageDriver, err := GetStorageByMountPath(storage.MountPath)
|
storageDriver, err := GetStorageByMountPath(storage.MountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user