Do not use chdir() in remove_all_files().
authorAndrej Kacian <ticho@claws-mail.org>
Fri, 6 Nov 2015 19:05:00 +0000 (20:05 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Wed, 11 Nov 2015 15:15:34 +0000 (16:15 +0100)
src/common/utils.c

index b3038ee..f16c00b 100644 (file)
@@ -2195,38 +2195,23 @@ gint make_dir_hier(const gchar *dir)
 gint remove_all_files(const gchar *dir)
 {
        GDir *dp;
-       const gchar *dir_name;
-       gchar *prev_dir;
-
-       prev_dir = g_get_current_dir();
-
-       if (g_chdir(dir) < 0) {
-               FILE_OP_ERROR(dir, "chdir");
-               g_free(prev_dir);
-               return -1;
-       }
+       const gchar *file_name;
+       gchar *tmp;
 
-       if ((dp = g_dir_open(".", 0, NULL)) == NULL) {
+       if ((dp = g_dir_open(dir, 0, NULL)) == NULL) {
                g_warning("failed to open directory: %s", dir);
-               g_free(prev_dir);
                return -1;
        }
 
-       while ((dir_name = g_dir_read_name(dp)) != NULL) {
-               if (claws_unlink(dir_name) < 0)
-                       FILE_OP_ERROR(dir_name, "unlink");
+       while ((file_name = g_dir_read_name(dp)) != NULL) {
+               tmp = g_strconcat(dir, G_DIR_SEPARATOR_S, file_name, NULL);
+               if (claws_unlink(tmp) < 0)
+                       FILE_OP_ERROR(tmp, "unlink");
+               g_free(tmp);
        }
 
        g_dir_close(dp);
 
-       if (g_chdir(prev_dir) < 0) {
-               FILE_OP_ERROR(prev_dir, "chdir");
-               g_free(prev_dir);
-               return -1;
-       }
-
-       g_free(prev_dir);
-
        return 0;
 }