E17:
authorVincent Torri <vincent.torri@gmail.com>
Thu, 25 Oct 2012 17:43:52 +0000 (17:43 +0000)
committerVincent Torri <vincent.torri@gmail.com>
Thu, 25 Oct 2012 17:43:52 +0000 (17:43 +0000)
I. Simplification, andif we cannot stat(), the best
thing to do is toswitch to a copy-delete operation.

II.Just stuff...

III. There is a problem with _e_fm_op_random_char().
When wewant to randomize a string we do srand(time())
foreachcharacter, so if the file is small enough
to be deleted inless than a second, it's not randomized.
And even if it's bigger, it's not goodly randomized.Sorry.

Patch by Maxime Villard rustyBSD

SVN revision: 78469

src/bin/e_fm_op.c

index 4321eb2ddd614885323e56d136c5ca7ee7b51bf5..12a64c936d85de50400f1d9c77975b0b45b8f925 100644 (file)
@@ -106,7 +106,7 @@ static int           _e_fm_op_remove_atom(E_Fm_Op_Task *task);
 static int           _e_fm_op_rename_atom(E_Fm_Op_Task *task);
 static int           _e_fm_op_destroy_atom(E_Fm_Op_Task *task);
 static void          _e_fm_op_random_buf(char *buf, ssize_t len);
-static char          _e_fm_op_random_char();
+static void          _e_fm_op_random_char(char *buf, size_t len);
 
 Eina_List *_e_fm_op_work_queue = NULL, *_e_fm_op_scan_queue = NULL;
 Ecore_Idler *_e_fm_op_work_idler_p = NULL, *_e_fm_op_scan_idler_p = NULL;
@@ -311,12 +311,11 @@ main(int argc, char **argv)
                                  if ((stat(argv[i], &st1) == 0) &&
                                      (stat(buf, &st2) == 0))
                                    {
-                                      /* if files are on the same device */
-                                      if (st1.st_dev == st2.st_dev)
-                                        type = E_FM_OP_RENAME;
-                                      else
+                                      /* if files are not on the same device */
+                                      if (st1.st_dev != st2.st_dev)
                                         type = E_FM_OP_MOVE;
                                    }
+                                 else type = E_FM_OP_MOVE;
                               }
                          }
 
@@ -1661,7 +1660,6 @@ _e_fm_op_rename_atom(E_Fm_Op_Task *task)
    return 0;
 }
 
-/* EXPERIMENTAL */
 static int
 _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
 {
@@ -1691,7 +1689,7 @@ _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
 
        if (st2.st_dev != task->src.st.st_dev ||
            st2.st_ino != task->src.st.st_ino ||
-           !S_ISREG(st2.st_mode))
+           st2.st_mode != task->src.st.st_mode)
          goto finish;
 
        if ((buf = malloc(READBUFSIZE)) == NULL)
@@ -1744,32 +1742,28 @@ static void
 _e_fm_op_random_buf(char *buf, ssize_t len)
 {
    int f = -1;
-   ssize_t i;
 
    if ((f = open("/dev/urandom", O_RDONLY)) == -1)
      {
-       for (i = 0; i < len; i++)
-         {
-            buf[i] = _e_fm_op_random_char();
-         }
-       return;
+        _e_fm_op_random_char(buf, len);
+        return;
      }
 
    if (read(f, buf, len) != len)
-     {
-       for (i = 0; i < len; i++)
-         {
-            buf[i] = _e_fm_op_random_char();
-         }
-     }
+     _e_fm_op_random_char(buf, len);
 
    close(f);
    return;
 }
 
-static char
-_e_fm_op_random_char()
+static void
+_e_fm_op_random_char(char *buf, size_t len)
 {
+   size_t i;
    srand((unsigned int)time(NULL));
-   return (rand() % 256) + 'a';
+
+   for (i = 0; i < len; i++)
+     {
+        buf[i] = (rand() % 256) + 'a';
+     }
 }