From d92f85d1ddd7a4ccb8c7be0d539a6a621afd177c Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sun, 18 Feb 2024 11:22:41 +0100 Subject: [PATCH] WebClient: improve error message when trying to move non-empty folder Signed-off-by: Nicola Murino --- internal/common/connection.go | 6 +++--- internal/vfs/azblobfs.go | 4 ++-- internal/vfs/gcsfs.go | 5 +++-- internal/vfs/s3fs.go | 4 ++-- static/locales/en/translation.json | 6 ++++-- static/locales/it/translation.json | 6 ++++-- templates/webclient/files.html | 6 ++++++ 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/internal/common/connection.go b/internal/common/connection.go index a8374f64..dd49008f 100644 --- a/internal/common/connection.go +++ b/internal/common/connection.go @@ -1728,9 +1728,9 @@ func (c *BaseConnection) GetGenericError(err error) error { } return sftp.ErrSSHFxFailure default: - if err == ErrPermissionDenied || err == ErrNotExist || err == ErrOpUnsupported || - err == ErrQuotaExceeded || err == ErrReadQuotaExceeded || err == vfs.ErrStorageSizeUnavailable || - err == ErrShuttingDown { + if errors.Is(err, ErrPermissionDenied) || errors.Is(err, ErrNotExist) || errors.Is(err, ErrOpUnsupported) || + errors.Is(err, ErrQuotaExceeded) || errors.Is(err, ErrReadQuotaExceeded) || + errors.Is(err, vfs.ErrStorageSizeUnavailable) || errors.Is(err, ErrShuttingDown) { return err } c.Log(logger.LevelError, "generic error: %+v", err) diff --git a/internal/vfs/azblobfs.go b/internal/vfs/azblobfs.go index a091eaf8..83e80ae9 100644 --- a/internal/vfs/azblobfs.go +++ b/internal/vfs/azblobfs.go @@ -482,7 +482,7 @@ func (*AzureBlobFs) IsNotSupported(err error) bool { if err == nil { return false } - return err == ErrVfsUnsupported + return errors.Is(err, ErrVfsUnsupported) } 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 } 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 { diff --git a/internal/vfs/gcsfs.go b/internal/vfs/gcsfs.go index 5dd1874d..994914bf 100644 --- a/internal/vfs/gcsfs.go +++ b/internal/vfs/gcsfs.go @@ -19,6 +19,7 @@ package vfs import ( "context" + "errors" "fmt" "io" "mime" @@ -448,7 +449,7 @@ func (*GCSFs) IsNotSupported(err error) bool { if err == nil { return false } - return err == ErrVfsUnsupported + return errors.Is(err, ErrVfsUnsupported) } // 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 } 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 { diff --git a/internal/vfs/s3fs.go b/internal/vfs/s3fs.go index ece051a3..a7d7177e 100644 --- a/internal/vfs/s3fs.go +++ b/internal/vfs/s3fs.go @@ -482,7 +482,7 @@ func (*S3Fs) IsNotSupported(err error) bool { if err == nil { return false } - return err == ErrVfsUnsupported + return errors.Is(err, ErrVfsUnsupported) } // 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 } 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 { diff --git a/static/locales/en/translation.json b/static/locales/en/translation.json index cb89e2c3..e0dba7b9 100644 --- a/static/locales/en/translation.json +++ b/static/locales/en/translation.json @@ -328,7 +328,8 @@ "err_generic": "Error moving files/directories", "err_403": "$t(fs.move.err_generic). $t(fs.err_403)", "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": { "title": "Rename \"{{- name}}\"", @@ -336,7 +337,8 @@ "err_generic": "Unable to rename \"{{- name}}\"", "err_403": "$t(fs.rename.err_generic). $t(fs.err_403)", "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": { "text": "Upload Files", diff --git a/static/locales/it/translation.json b/static/locales/it/translation.json index f73fd873..4ae125e7 100644 --- a/static/locales/it/translation.json +++ b/static/locales/it/translation.json @@ -328,7 +328,8 @@ "err_generic": "Errore nello spostamento di file/directory", "err_403": "$t(fs.move.err_generic). $t(fs.err_403)", "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": { "title": "Rinomina \"{{- name}}\"", @@ -336,7 +337,8 @@ "err_generic": "Impossibile rinominare \"{{- name}}\"", "err_403": "$t(fs.rename.err_generic): $t(fs.err_403)", "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": { "text": "Carica file", diff --git a/templates/webclient/files.html b/templates/webclient/files.html index 21582359..bff366df 100644 --- a/templates/webclient/files.html +++ b/templates/webclient/files.html @@ -1428,6 +1428,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). let errorMessage = ""; if (error && error.response) { switch (error.response.status) { + case 400: + errorMessage = "fs.move.err_unsupported"; + break; case 403: errorMessage = "fs.move.err_403"; break; @@ -1640,6 +1643,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). let errorMessage; if (error && error.response) { switch (error.response.status) { + case 400: + errorMessage = "fs.rename.err_unsupported"; + break; case 403: errorMessage = "fs.rename.err_403"; break;