WebClient: improve error message when trying to move non-empty folder

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2024-02-18 11:22:41 +01:00
parent 5a319dc64f
commit d92f85d1dd
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF
7 changed files with 24 additions and 13 deletions

View file

@ -1728,9 +1728,9 @@ func (c *BaseConnection) GetGenericError(err error) error {
} }
return sftp.ErrSSHFxFailure return sftp.ErrSSHFxFailure
default: default:
if err == ErrPermissionDenied || err == ErrNotExist || err == ErrOpUnsupported || if errors.Is(err, ErrPermissionDenied) || errors.Is(err, ErrNotExist) || errors.Is(err, ErrOpUnsupported) ||
err == ErrQuotaExceeded || err == ErrReadQuotaExceeded || err == vfs.ErrStorageSizeUnavailable || errors.Is(err, ErrQuotaExceeded) || errors.Is(err, ErrReadQuotaExceeded) ||
err == ErrShuttingDown { errors.Is(err, vfs.ErrStorageSizeUnavailable) || errors.Is(err, ErrShuttingDown) {
return err return err
} }
c.Log(logger.LevelError, "generic error: %+v", err) c.Log(logger.LevelError, "generic error: %+v", err)

View file

@ -482,7 +482,7 @@ func (*AzureBlobFs) IsNotSupported(err error) bool {
if err == nil { if err == nil {
return false return false
} }
return err == ErrVfsUnsupported return errors.Is(err, ErrVfsUnsupported)
} }
func (*AzureBlobFs) isBadRequestError(err error) bool { func (*AzureBlobFs) isBadRequestError(err error) bool {
@ -782,7 +782,7 @@ func (fs *AzureBlobFs) renameInternal(source, target string, fi os.FileInfo, rec
return numFiles, filesSize, err return numFiles, filesSize, err
} }
if hasContents { if hasContents {
return numFiles, filesSize, fmt.Errorf("cannot rename non empty directory: %q", source) return numFiles, filesSize, fmt.Errorf("%w: cannot rename non empty directory: %q", ErrVfsUnsupported, source)
} }
} }
if err := fs.mkdirInternal(target); err != nil { if err := fs.mkdirInternal(target); err != nil {

View file

@ -19,6 +19,7 @@ package vfs
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"mime" "mime"
@ -448,7 +449,7 @@ func (*GCSFs) IsNotSupported(err error) bool {
if err == nil { if err == nil {
return false return false
} }
return err == ErrVfsUnsupported return errors.Is(err, ErrVfsUnsupported)
} }
// CheckRootPath creates the specified local root directory if it does not exists // CheckRootPath creates the specified local root directory if it does not exists
@ -774,7 +775,7 @@ func (fs *GCSFs) renameInternal(source, target string, fi os.FileInfo, recursion
return numFiles, filesSize, err return numFiles, filesSize, err
} }
if hasContents { if hasContents {
return numFiles, filesSize, fmt.Errorf("cannot rename non empty directory: %q", source) return numFiles, filesSize, fmt.Errorf("%w: cannot rename non empty directory: %q", ErrVfsUnsupported, source)
} }
} }
if err := fs.mkdirInternal(target); err != nil { if err := fs.mkdirInternal(target); err != nil {

View file

@ -482,7 +482,7 @@ func (*S3Fs) IsNotSupported(err error) bool {
if err == nil { if err == nil {
return false return false
} }
return err == ErrVfsUnsupported return errors.Is(err, ErrVfsUnsupported)
} }
// CheckRootPath creates the specified local root directory if it does not exists // CheckRootPath creates the specified local root directory if it does not exists
@ -700,7 +700,7 @@ func (fs *S3Fs) renameInternal(source, target string, fi os.FileInfo, recursion
return numFiles, filesSize, err return numFiles, filesSize, err
} }
if hasContents { if hasContents {
return numFiles, filesSize, fmt.Errorf("cannot rename non empty directory: %q", source) return numFiles, filesSize, fmt.Errorf("%w: cannot rename non empty directory: %q", ErrVfsUnsupported, source)
} }
} }
if err := fs.mkdirInternal(target); err != nil { if err := fs.mkdirInternal(target); err != nil {

View file

@ -328,7 +328,8 @@
"err_generic": "Error moving files/directories", "err_generic": "Error moving files/directories",
"err_403": "$t(fs.move.err_generic). $t(fs.err_403)", "err_403": "$t(fs.move.err_generic). $t(fs.err_403)",
"err_429": "$t(fs.move.err_generic). $t(fs.err_429)", "err_429": "$t(fs.move.err_generic). $t(fs.err_429)",
"err_exists": "$t(fs.move.err_generic). $t(fs.err_exists)" "err_exists": "$t(fs.move.err_generic). $t(fs.err_exists)",
"err_unsupported": "Unsupported: if you want to move a directory make sure it is empty"
}, },
"rename": { "rename": {
"title": "Rename \"{{- name}}\"", "title": "Rename \"{{- name}}\"",
@ -336,7 +337,8 @@
"err_generic": "Unable to rename \"{{- name}}\"", "err_generic": "Unable to rename \"{{- name}}\"",
"err_403": "$t(fs.rename.err_generic). $t(fs.err_403)", "err_403": "$t(fs.rename.err_generic). $t(fs.err_403)",
"err_429": "$t(fs.rename.err_generic). $t(fs.err_429)", "err_429": "$t(fs.rename.err_generic). $t(fs.err_429)",
"err_exists": "$t(fs.rename.err_generic). $t(fs.err_exists)" "err_exists": "$t(fs.rename.err_generic). $t(fs.err_exists)",
"err_unsupported": "Unsupported: if you want to rename a directory make sure it is empty"
}, },
"upload": { "upload": {
"text": "Upload Files", "text": "Upload Files",

View file

@ -328,7 +328,8 @@
"err_generic": "Errore nello spostamento di file/directory", "err_generic": "Errore nello spostamento di file/directory",
"err_403": "$t(fs.move.err_generic). $t(fs.err_403)", "err_403": "$t(fs.move.err_generic). $t(fs.err_403)",
"err_429": "$t(fs.move.err_generic). $t(fs.err_429)", "err_429": "$t(fs.move.err_generic). $t(fs.err_429)",
"err_exists": "$t(fs.move.err_generic). $t(fs.err_exists)" "err_exists": "$t(fs.move.err_generic). $t(fs.err_exists)",
"err_unsupported": "Non supportato: se vuoi spostare una directory assicurati che sia vuota"
}, },
"rename": { "rename": {
"title": "Rinomina \"{{- name}}\"", "title": "Rinomina \"{{- name}}\"",
@ -336,7 +337,8 @@
"err_generic": "Impossibile rinominare \"{{- name}}\"", "err_generic": "Impossibile rinominare \"{{- name}}\"",
"err_403": "$t(fs.rename.err_generic): $t(fs.err_403)", "err_403": "$t(fs.rename.err_generic): $t(fs.err_403)",
"err_429": "$t(fs.rename.err_generic): $t(fs.err_429)", "err_429": "$t(fs.rename.err_generic): $t(fs.err_429)",
"err_exists": "$t(fs.rename.err_generic). $t(fs.err_exists)" "err_exists": "$t(fs.rename.err_generic). $t(fs.err_exists)",
"err_unsupported": "Non supportato: se vuoi rinominare una directory assicurati che sia vuota"
}, },
"upload": { "upload": {
"text": "Carica file", "text": "Carica file",

View file

@ -1428,6 +1428,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
let errorMessage = ""; let errorMessage = "";
if (error && error.response) { if (error && error.response) {
switch (error.response.status) { switch (error.response.status) {
case 400:
errorMessage = "fs.move.err_unsupported";
break;
case 403: case 403:
errorMessage = "fs.move.err_403"; errorMessage = "fs.move.err_403";
break; break;
@ -1640,6 +1643,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
let errorMessage; let errorMessage;
if (error && error.response) { if (error && error.response) {
switch (error.response.status) { switch (error.response.status) {
case 400:
errorMessage = "fs.rename.err_unsupported";
break;
case 403: case 403:
errorMessage = "fs.rename.err_403"; errorMessage = "fs.rename.err_403";
break; break;