[Easytag-mailing] Failed directory deletion messages on samba mounts



Hi,

When renaming files out of a directory on a samba mount, each time a
file is moved an error appears complaining that it could not delete
the directory.  This is because trying to delete a non-empty directory
under samba doesn't give a 'directory not empty' error (which easytag
silently ignores), but a 'permission denied' error  (this may also
occur with other kinds of network mount, but I haven't checked).

The following is a patch (for 1.99.12) that manually checks whether
the directory is empty, rather than relying on rmdir & errno.  I
followed the Read_Directory style of putting the necessary #includes
immediately before the function.
This is my first look at easytag, apologies if I've done something stupid.

Cheers,
Michael Macnair


diff -bBdNrw -U5 easytag.c.old easytag.c
--- easytag.c.old       2006-08-10 21:33:55.000000000 +0100
+++ easytag.c   2006-08-10 22:14:25.000000000 +0100
@@ -2594,20 +2594,50 @@

/*
 * Remove old directories after renaming the file
 * Badly coded, but works....
 */
+#include <sys/types.h>
+#include <dirent.h>
gint Remove_Dir (const gchar *dirname_old, const gchar *dirname_new)
{
    gchar *temp_old, *temp_new;
    gchar *temp_end_old, *temp_end_new;
+    DIR *dir;
+    struct dirent *de;
+    int dir_was_empty;

    temp_old = g_strdup(dirname_old);
    temp_new = g_strdup(dirname_new);

    while (temp_old && temp_new && strcmp(temp_old,temp_new)!=0 )
    {
+        /*
+         * Check if directory is empty (code from buildd project)
+         * rmdir does not report this correctly for samba mounts
+         * (you get 'permission denied' rather than 'not empty')
+         */
+        if (!(dir = opendir( temp_old ))) {
+            g_free(temp_old);
+            g_free(temp_new);
+            return(-1);;
+        }
+        dir_was_empty = 1;
+        while( (de = readdir(dir)) ) {
+            if (de->d_name[0] == '.' &&
+                (de->d_name[1] == 0 ||
+                 (de->d_name[1] == '.' && de->d_name[2] == 0)))
+                continue;
+                dir_was_empty = 0;
+                break;
+        }
+        closedir( dir );
+
+        /* do not attempt to delete directory if it is not empty */
+        if (dir_was_empty == 0)
+            break;
+
        if (rmdir(temp_old)==-1)
        {
            if (errno!=ENOTEMPTY)
            {
                g_free(temp_old);




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]