This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efm2.
View the commit online.
commit b876965918f2e67b3ca34ffedc3a8aa61fbd69da
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Thu Apr 25 07:44:27 2024 +0100
share error handling in central func
so - too much error handling all over the place - massive switch/cse
blocks. not sustainable. handle all errors in one place. less code. yay!
---
src/backends/default/mv.c | 338 ++++++++++++++--------------------------------
1 file changed, 105 insertions(+), 233 deletions(-)
diff --git a/src/backends/default/mv.c b/src/backends/default/mv.c
index 430576d..c964ba0 100644
--- a/src/backends/default/mv.c
+++ b/src/backends/default/mv.c
@@ -26,6 +26,86 @@
static const char *config_dir = NULL;
+// generic error handler. special case handling all errnos for everything is
+// pretty insane - so handle non-errors in switches and otherwise pass to
+// this tio handle the reast in a generic way.
+static void
+_error_handle(const char *src, const char *dst, int errno_in)
+{
+ switch (errno_in)
+ {
+ case EACCES:
+ status_error(src, dst, "Move - Access denied");
+ return;
+ case EFAULT:
+ status_error(src, dst, "Move - Memory Fault");
+ return;
+ case ELOOP:
+ status_error(src, dst, "Move - Too many symlinks");
+ return;
+ case ENAMETOOLONG:
+ status_error(src, dst, "Move - Name too long");
+ return;
+ case ENOMEM:
+ status_error(src, dst, "Move - Out of memory");
+ return;
+ case ENOTDIR:
+ status_error(src, dst, "Move - Path component is not a directory");
+ return;
+ case EOVERFLOW:
+ status_error(src, dst, "Move - Overflow");
+ return;
+ case EDQUOT:
+ status_error(src, dst, "Move - Over quota");
+ return;
+ case EINVAL:
+ status_error(src, dst, "Move - Inmvalid value");
+ return;
+ case EMLINK:
+ status_error(src, dst, "Move - Too many source links");
+ return;
+ case ENOENT:
+ status_error(src, dst, "Move - File does not exist");
+ return;
+ case ENOSPC:
+ status_error(src, dst, "Move - Disk full");
+ return;
+ case EPERM:
+ status_error(src, dst, "Move - Permission denied");
+ return;
+ case EROFS:
+ status_error(src, dst, "Move - Read only filesystem");
+ return;
+ case EBADF:
+ status_error(src, dst, "Move - Bad file descriptor");
+ return;
+ case EIO:
+ status_error(src, dst, "Move - I/O error");
+ return;
+ case EISDIR:
+ status_error(src, dst, "Move - Destination is dir");
+ return;
+ case EFBIG:
+ status_error(src, dst, "Move - File too big");
+ return;
+ case ETXTBSY:
+ status_error(src, dst, "Move - Text file busy");
+ return;
+ case EBUSY:
+ status_error(src, dst, "Move - File busy");
+ return;
+ case ENOTEMPTY:
+ status_error(src, dst, "Move - Destination not empty");
+ return;
+ case EEXIST:
+ status_error(src, dst, "Move - File exists");
+ return;
+ default: // WAT? we should not get here - we handled everything...
+ status_error(src, dst, "Move - Unknown error");
+ break;
+ }
+}
+
// this scans a tree to build a potential operation progress count. it may
// not be 100% right as the fs can change while the scan happens and after
// so any move that devolves into a cp + rm isn't going to be atomic and
@@ -44,39 +124,11 @@ fs_scan(const char *src)
{
switch (errno)
{
- case EACCES:
- status_error(src, NULL, "Move - Permission denied for source");
- return EINA_FALSE;
- break;
- case EFAULT:
- status_error(src, NULL, "Move - Memory Fault");
- return EINA_FALSE;
- break;
- case ELOOP:
- status_error(src, NULL, "Move - Too many symlinks");
- return EINA_FALSE;
- break;
- case ENAMETOOLONG:
- status_error(src, NULL, "Move - Name too long");
- return EINA_FALSE;
- break;
case ENOENT: // ignore this error - file removed during scan ?
return EINA_TRUE;
- break;
- case ENOMEM:
- status_error(src, NULL, "Move - Out of memory");
- return EINA_FALSE;
- break;
- case ENOTDIR:
- status_error(src, NULL, "Move - Source path component is not a directory");
- return EINA_FALSE;
- break;
- case EOVERFLOW:
- status_error(src, NULL, "Move - Overflow");
- return EINA_FALSE;
- break;
default:
- break;
+ _error_handle(src, NULL, errno);
+ return EINA_FALSE;
}
}
if (S_ISDIR(st.st_mode))
@@ -168,28 +220,8 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err)
case ENOENT: // ignore this error - file removed during scan ?
status_pos(1, "Move - File vanished");
break;
- case EACCES:
- status_error(src, dst, "Move - Permission denied for source");
- return EINA_FALSE;
- case EFAULT:
- status_error(src, dst, "Move - Memory Fault");
- return EINA_FALSE;
- case ELOOP:
- status_error(src, dst, "Move - Too many symlinks");
- return EINA_FALSE;
- case ENAMETOOLONG:
- status_error(src, dst, "Move - Name too long");
- return EINA_FALSE;
- case ENOMEM:
- status_error(src, dst, "Move - Out of memory");
- return EINA_FALSE;
- case ENOTDIR:
- status_error(src, dst, "Move - Source path component is not a directory");
- return EINA_FALSE;
- case EOVERFLOW:
- status_error(src, dst, "Move - Overflow");
- return EINA_FALSE;
- default: // WAT?
+ default:
+ _error_handle(src, dst, errno);
return EINA_FALSE;
}
}
@@ -202,46 +234,8 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err)
{
case EEXIST: // ignore - mv would mv over this anyway
break;
- case EACCES:
- res = EINA_FALSE;
- goto err;
- case EDQUOT:
- res = EINA_FALSE;
- goto err;
- case EFAULT:
- res = EINA_FALSE;
- goto err;
- case EINVAL:
- res = EINA_FALSE;
- goto err;
- case ELOOP:
- res = EINA_FALSE;
- goto err;
- case EMLINK:
- res = EINA_FALSE;
- goto err;
- case ENAMETOOLONG:
- res = EINA_FALSE;
- goto err;
- case ENOENT:
- res = EINA_FALSE;
- goto err;
- case ENOMEM:
- res = EINA_FALSE;
- goto err;
- case ENOSPC:
- res = EINA_FALSE;
- goto err;
- case ENOTDIR:
- res = EINA_FALSE;
- goto err;
- case EPERM:
- res = EINA_FALSE;
- goto err;
- case EROFS:
- res = EINA_FALSE;
- goto err;
default: // WAT
+ _error_handle(NULL, dst, errno);
res = EINA_FALSE;
goto err;
}
@@ -282,10 +276,23 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err)
{
if (symlink(link, dst) < 0)
{ // XXX: soft error? e.g. mv on FAT fs?
+ status_pos(1, "Move - Error creating symlink");
}
}
else if (lnsz < 0)
{ // XXX: handle read link err
+ switch (errno)
+ {
+ case ENOENT: // ignore this error - file removed during scan ?
+ status_pos(1, "Move - File vanished");
+ break;
+ default:
+ _error_handle(src, dst, errno);
+ return EINA_FALSE;
+ }
+ }
+ else // 0 sized symlink ... WAT?
+ {
}
}
else if (S_ISFIFO(st.st_mode))
@@ -341,22 +348,8 @@ again_read:
case EAGAIN:
case EINTR:
goto again_read;
- case EBADF:
- res = EINA_FALSE;
- goto err_copy;
- case EFAULT:
- res = EINA_FALSE;
- goto err_copy;
- case EINVAL:
- res = EINA_FALSE;
- goto err_copy;
- case EIO:
- res = EINA_FALSE;
- goto err_copy;
- case EISDIR:
- res = EINA_FALSE;
- goto err_copy;
- default: // WAT
+ default:
+ _error_handle(src, NULL, errno);
res = EINA_FALSE;
goto err_copy;
}
@@ -373,40 +366,8 @@ again_write:
case EAGAIN:
case EINTR:
goto again_write;
- case EBADF:
- res = EINA_FALSE;
- goto err_copy;
- case EDQUOT:
- res = EINA_FALSE;
- goto err_copy;
- break;
- case EFAULT:
- res = EINA_FALSE;
- goto err_copy;
- break;
- case EFBIG:
- res = EINA_FALSE;
- goto err_copy;
- break;
- case EINVAL:
- res = EINA_FALSE;
- goto err_copy;
- break;
- case EIO:
- res = EINA_FALSE;
- goto err_copy;
- break;
- case ENOSPC:
- res = EINA_FALSE;
- goto err_copy;
- break;
- case EPERM:
- res = EINA_FALSE;
- goto err_copy;
- break;
- case EDESTADDRREQ: // WAT
- case EPIPE: // WAT
- default: // WAT
+ default:
+ _error_handle(NULL, dst, errno);
res = EINA_FALSE;
goto err_copy;
}
@@ -430,36 +391,8 @@ again_write:
old_copy = EINA_TRUE;
break;
case EBADF:
- res = EINA_FALSE;
- goto err_copy;
- case EFBIG:
- res = EINA_FALSE;
- goto err_copy;
- case EINVAL:
- res = EINA_FALSE;
- goto err_copy;
- case EIO:
- res = EINA_FALSE;
- goto err_copy;
- case EISDIR:
- res = EINA_FALSE;
- goto err_copy;
- case ENOMEM:
- res = EINA_FALSE;
- goto err_copy;
- case ENOSPC:
- res = EINA_FALSE;
- goto err_copy;
- case EOVERFLOW:
- res = EINA_FALSE;
- goto err_copy;
- case EPERM:
- res = EINA_FALSE;
- goto err_copy;
- case ETXTBSY:
- res = EINA_FALSE;
- goto err_copy;
default: // WAT
+ _error_handle(src, dst, errno);
res = EINA_FALSE;
goto err_copy;
}
@@ -519,72 +452,11 @@ fs_mv(const char *src, const char *dst, Eina_Bool report_err)
{
switch (errno)
{
- case EACCES:
- case EPERM: // permission denied
- if (report_err) status_error(src, dst, "Move - Permission denied");
- res = EINA_FALSE;
- break;
- case EBUSY: // file or dir is busy
- if (report_err) status_error(src, dst, "Move - File busy");
- res = EINA_FALSE;
- break;
- case EDQUOT: // no quota left
- if (report_err) status_error(src, dst, "Move - Over quota");
- res = EINA_FALSE;
- break;
- case EFAULT: // should not happen - but src or dst outside addr space
- if (report_err) status_error(src, dst, "Move - Address fault");
- res = EINA_FALSE;
- break;
- case EINVAL: // moving into a sub path of itself - invalid
- if (report_err) status_error(src, dst, "Move on top of itself");
- res = EINA_FALSE;
- break;
- case EISDIR: // moving file/dir into itself
- if (report_err) status_error(src, dst, "Move - Destination is dir");
- res = EINA_FALSE;
- break;
- case ELOOP: // too many symlinks in a loop
- if (report_err) status_error(src, dst, "Move - Too many symlinks");
- res = EINA_FALSE;
- break;
- case EMLINK: // max links exceeded
- if (report_err) status_error(src, dst, "Move - Too many source links");
- res = EINA_FALSE;
- break;
- case ENAMETOOLONG: // path too long (src or dst)
- if (report_err) status_error(src, dst, "Move - Path too long");
- res = EINA_FALSE;
- break;
- case ENOENT: // src or dst doesn't exist
- if (report_err) status_error(src, dst, "Move - File does not exist");
- res = EINA_FALSE;
- break;
- case ENOMEM: // out of mem
- if (report_err) status_error(src, dst, "Move - Out of memory");
- res = EINA_FALSE;
- break;
- case ENOSPC: // out of space on disk
- if (report_err) status_error(src, dst, "Move - Disk full");
- res = EINA_FALSE;
- break;
- case ENOTDIR: // moving dir on top of file
- if (report_err) status_error(src, dst, "Move - On top of itself");
- res = EINA_FALSE;
- break;
- case ENOTEMPTY:
- case EEXIST: // dst is not an empty dir
- if (report_err) status_error(src, dst, "Move - Destination not empty");
- res = EINA_FALSE;
- break;
- case EROFS: // read only disk
- if (report_err) status_error(src, dst, "Move - Read only filesystem");
- res = EINA_FALSE;
- break;
case EXDEV: // revert to cp + rm
return fs_cp_rm(src, dst, report_err);
break;
- default: // WAT???
+ default:
+ if (report_err) _error_handle(src, dst, errno);
res = EINA_FALSE;
break;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.