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 f4b20c1fd870a032a642e2dbd3194c17b64133b2
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Tue Apr 30 14:46:11 2024 +0100

    handle errs properly in fs code without logic holes
---
 src/backends/default/fs.c | 83 +++++++++++++++++++++++++++++------------------
 1 file changed, 52 insertions(+), 31 deletions(-)

diff --git a/src/backends/default/fs.c b/src/backends/default/fs.c
index d64fccc..1cb8db9 100644
--- a/src/backends/default/fs.c
+++ b/src/backends/default/fs.c
@@ -125,6 +125,7 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err, Eina_Bool cp,
   mode_t         old_umask;
   struct timeval times[2];
   const char    *op = "";
+  Eina_Strbuf   *sbuf = NULL;
 
   if (strlen(src) < 1) return EINA_FALSE;
 
@@ -135,19 +136,25 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err, Eina_Bool cp,
   else if (!rm && cp) op = "Copy";
   else if (rm && !cp) op = "Delete";
 
+  old_umask = umask(0);
   if (lstat(src, &st) != 0)
     {
       switch (errno)
         {
         case ENOENT: // ignore this error - file removed during scan ?
-          status_pos(1, "Move - File vanished");
-          break;
+          eina_strbuf_reset(sbuf);
+          eina_strbuf_append(sbuf, op);
+          eina_strbuf_append(sbuf, ": ");
+          eina_strbuf_append(sbuf, "File vanished");
+          status_pos(1, eina_strbuf_string_get(sbuf));
+          goto err;
         default:
           _error_handle(src, dst, op, errno);
-          return EINA_FALSE;
+          res = EINA_FALSE;
+          goto err;
         }
     }
-  old_umask = umask(0);
+  sbuf = eina_strbuf_new();
   if (S_ISDIR(st.st_mode))
     { // it's a dir - scan this recursively
       if (cp)
@@ -180,8 +187,8 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err, Eina_Bool cp,
                     eina_strbuf_append(buf, dst);
                     eina_strbuf_append(buf, "/");
                     eina_strbuf_append(buf, fs);
-                    if (!fs_cp_rm(s, eina_strbuf_string_get(buf), report_err,
-                                  cp, rm))
+                    if (!fs_cp_rm(s, eina_strbuf_string_get(buf),
+                                  report_err, cp, rm))
                       res = EINA_FALSE;
                   }
                 eina_strbuf_free(buf);
@@ -190,21 +197,6 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err, Eina_Bool cp,
           }
           eina_iterator_free(it);
         }
-      if ((rm) && (res))
-        {
-          if (rmdir(src) != 0)
-            {
-              switch (errno)
-                {
-                case ENOENT: // ignore missing
-                  break;
-                default:
-                  _error_handle(src, NULL, op, errno);
-                  res = EINA_FALSE;
-                  goto err;
-                }
-            }
-        }
     }
   else if (S_ISLNK(st.st_mode))
     {
@@ -217,16 +209,24 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err, Eina_Bool cp,
           if ((lnsz > 0) && (lnsz < (ssize_t)sizeof(link)))
             {
               if (symlink(link, dst) < 0)
-                { // XXX: soft error? e.g. mv on FAT fs?
-                  status_pos(1, "Move - Error creating symlink");
+                { // soft error? e.g. mv on FAT fs? report but move on
+                  eina_strbuf_reset(sbuf);
+                  eina_strbuf_append(sbuf, op);
+                  eina_strbuf_append(sbuf, ": ");
+                  eina_strbuf_append(sbuf, "Error creating symlink");
+                  status_pos(1, eina_strbuf_string_get(sbuf));
                 }
             }
           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");
+                  eina_strbuf_reset(sbuf);
+                  eina_strbuf_append(sbuf, op);
+                  eina_strbuf_append(sbuf, ": ");
+                  eina_strbuf_append(sbuf, "File vanished");
+                  status_pos(1, eina_strbuf_string_get(sbuf));
                   break;
                 default:
                   _error_handle(src, dst, op, errno);
@@ -234,7 +234,12 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err, Eina_Bool cp,
                 }
             }
           else // 0 sized symlink ... WAT?
-            {  // XXX: handle this
+            {
+              eina_strbuf_reset(sbuf);
+              eina_strbuf_append(sbuf, op);
+              eina_strbuf_append(sbuf, ": ");
+              eina_strbuf_append(sbuf, "Zero sized symlink");
+              status_error(src, NULL, eina_strbuf_string_get(sbuf));
             }
         }
     }
@@ -243,7 +248,7 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err, Eina_Bool cp,
       if (cp)
         {
           if (mkfifo(dst, st.st_mode) < 0)
-            { // XXX: soft error? ignore?
+            { // soft error? ignore?
             }
         }
     }
@@ -259,7 +264,7 @@ fs_cp_rm(const char *src, const char *dst, Eina_Bool report_err, Eina_Bool cp,
       if (cp)
         {
           if (mknod(dst, st.st_mode, st.st_dev) < 0)
-            { // XXX: soft error? ignore?
+            { // soft error? ignore?
             }
         }
     }
@@ -361,8 +366,23 @@ err_copy:
           if (fd_in >= 0) close(fd_in);
           if (fd_ou >= 0) close(fd_ou);
         }
-      if ((rm) && (res))
+    }
+  if ((rm) && (res))
+    {
+      if (S_ISDIR(st.st_mode))
         {
+          if (rmdir(src) != 0)
+            {
+              switch (errno)
+                {
+                case ENOENT: // ignore missing
+                  break;
+                default:
+                  _error_handle(src, NULL, op, errno);
+                  res = EINA_FALSE;
+                  goto err;
+                }
+            }
           if (unlink(src) != 0)
             {
               switch (errno)
@@ -378,7 +398,7 @@ err_copy:
         }
     }
 err_unlink:
-  chown(dst, st.st_uid, st.st_gid);
+  chown(dst, st.st_uid, st.st_gid); // ignore err
 #ifdef STAT_NSEC
 #ifdef st_mtime
 #define STAT_NSEC_ATIME(st) (unsigned long long)((st)->st_atim.tv_nsec)
@@ -398,9 +418,10 @@ err_unlink:
   times[0].tv_usec = STAT_NSEC_ATIME(st) * 1000;
   times[1].tv_sec  = st.st_mtime;
   times[1].tv_usec = STAT_NSEC_MTIME(st) * 1000;
-  utimes(dst, times);
+  utimes(dst, times); // ingore err
 err:
   umask(old_umask);
+  if (sbuf) eina_strbuf_free(sbuf);
   return res;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to