Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
authorLaurent Monin <geeqie@norz.org>
Sat, 15 Nov 2008 20:01:25 +0000 (20:01 +0000)
committerLaurent Monin <geeqie@norz.org>
Sat, 15 Nov 2008 20:01:25 +0000 (20:01 +0000)
13 files changed:
src/bar_info.c
src/cache-loader.c
src/cache.c
src/cache.h
src/cache_maint.c
src/dupe.c
src/main.c
src/pan-view.c
src/search.c
src/thumb.c
src/thumb_standard.c
src/ui_fileops.c
src/ui_fileops.h

index 4ac1846..fff5815 100644 (file)
@@ -98,7 +98,7 @@ static gint comment_legacy_write(FileData *fd, GList *keywords, const gchar *com
                mode_t mode = 0755;
 
                comment_dir = cache_get_location(CACHE_TYPE_METADATA, fd->path, FALSE, &mode);
-               if (cache_ensure_dir_exists(comment_dir, mode))
+               if (recursive_mkdir_if_not_exists(comment_dir, mode))
                        {
                        gchar *filename = g_strconcat(fd->name, GQ_CACHE_EXT_METADATA, NULL);
                        
index d4a29cc..1e0231e 100644 (file)
@@ -168,7 +168,7 @@ static gboolean cache_loader_process(CacheLoader *cl)
                        mode_t mode = 0755;
 
                        base = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, FALSE, &mode);
-                       if (cache_ensure_dir_exists(base, mode))
+                       if (recursive_mkdir_if_not_exists(base, mode))
                                {
                                g_free(cl->cd->path);
                                cl->cd->path = cache_get_location(CACHE_TYPE_SIM, cl->fd->path, TRUE, NULL);
index 48a04ab..7395ab7 100644 (file)
@@ -582,40 +582,6 @@ gint cache_sim_data_filled(ImageSimilarityData *sd)
  *-------------------------------------------------------------------
  */
 
-/* warning: this func modifies path string contents!, on fail it is set to fail point */
-gint cache_ensure_dir_exists(gchar *path, mode_t mode)
-{
-       if (!path) return FALSE;
-
-       if (!isdir(path))
-               {
-               gchar *p = path;
-               while (p[0] != '\0')
-                       {
-                       p++;
-                       if (p[0] == G_DIR_SEPARATOR || p[0] == '\0')
-                               {
-                               gint end = TRUE;
-                               if (p[0] != '\0')
-                                       {
-                                       p[0] = '\0';
-                                       end = FALSE;
-                                       }
-                               if (!isdir(path))
-                                       {
-                                       DEBUG_1("creating sub dir:%s", path);
-                                       if (!mkdir_utf8(path, mode))
-                                               {
-                                               log_printf("create dir failed: %s\n", path);
-                                               return FALSE;
-                                               }
-                                       }
-                               if (!end) p[0] = G_DIR_SEPARATOR;
-                               }
-                       }
-               }
-       return TRUE;
-}
 
 static void cache_path_parts(CacheType type,
                             const gchar **cache_rc, const gchar **cache_local, const gchar **cache_ext)
index a16db5b..d52d74d 100644 (file)
@@ -69,8 +69,6 @@ void cache_sim_data_set_md5sum(CacheData *cd, guchar digest[16]);
 void cache_sim_data_set_similarity(CacheData *cd, ImageSimilarityData *sd);
 gint cache_sim_data_filled(ImageSimilarityData *sd);
 
-
-gint cache_ensure_dir_exists(gchar *path, mode_t mode);
 gchar *cache_get_location(CacheType type, const gchar *source, gint include_name, mode_t *mode);
 gchar *cache_find_location(CacheType type, const gchar *source);
 
index 46c9475..1349598 100644 (file)
@@ -524,7 +524,7 @@ static void cache_maint_moved(FileData *fd)
        if (!src || !dest) return;
 
        base = cache_get_location(CACHE_TYPE_THUMB, dest, FALSE, &mode);
-       if (cache_ensure_dir_exists(base, mode))
+       if (recursive_mkdir_if_not_exists(base, mode))
                {
                gchar *buf;
                gchar *d;
@@ -548,7 +548,7 @@ static void cache_maint_moved(FileData *fd)
        g_free(base);
 
        base = cache_get_location(CACHE_TYPE_METADATA, dest, FALSE, &mode);
-       if (cache_ensure_dir_exists(base, mode))
+       if (recursive_mkdir_if_not_exists(base, mode))
                {
                gchar *buf;
                gchar *d;
@@ -603,7 +603,7 @@ static void cache_maint_copied(FileData *fd)
        if (!src_cache) return;
 
        dest_base = cache_get_location(CACHE_TYPE_METADATA, fd->change->dest, FALSE, &mode);
-       if (cache_ensure_dir_exists(dest_base, mode))
+       if (recursive_mkdir_if_not_exists(dest_base, mode))
                {
                gchar *path;
 
index 1fba04e..df0366c 100644 (file)
@@ -435,7 +435,7 @@ static void dupe_item_write_cache(DupeItem *di)
        if (!di) return;
 
        base = cache_get_location(CACHE_TYPE_SIM, di->fd->path, FALSE, &mode);
-       if (cache_ensure_dir_exists(base, mode))
+       if (recursive_mkdir_if_not_exists(base, mode))
                {
                CacheData *cd;
 
index 5bb2590..de76aba 100644 (file)
@@ -450,7 +450,7 @@ static void mkdir_if_not_exists(const gchar *path)
 
        log_printf(_("Creating %s dir:%s\n"), GQ_APPNAME, path);
 
-       if (!mkdir_utf8(path, 0755))
+       if (!recursive_mkdir_if_not_exists(path, 0755))
                {
                log_printf(_("Could not create dir:%s\n"), path);
                }
index b4454d1..8c6e176 100644 (file)
@@ -638,7 +638,7 @@ static gint pan_cache_step(PanWindow *pw)
                        mode_t mode = 0755;
 
                        base = cache_get_location(CACHE_TYPE_SIM, fd->path, FALSE, &mode);
-                       if (cache_ensure_dir_exists(base, mode))
+                       if (recursive_mkdir_if_not_exists(base, mode))
                                {
                                g_free(cd->path);
                                cd->path = cache_get_location(CACHE_TYPE_SIM, fd->path, TRUE, NULL);
index 9e94aba..2dc4d2f 100644 (file)
@@ -1540,7 +1540,7 @@ static void search_file_load_process(SearchData *sd, CacheData *cd)
 
                        path = image_loader_get_fd(sd->img_loader)->path;
                        base = cache_get_location(CACHE_TYPE_SIM, path, FALSE, &mode);
-                       if (cache_ensure_dir_exists(base, mode))
+                       if (recursive_mkdir_if_not_exists(base, mode))
                                {
                                g_free(cd->path);
                                cd->path = cache_get_location(CACHE_TYPE_SIM, path, TRUE, NULL);
index 5a2f33f..cae4beb 100644 (file)
@@ -50,7 +50,7 @@ static gboolean thumb_loader_save_thumbnail(ThumbLoader *tl, gboolean mark_failu
 
        cache_dir = cache_get_location(CACHE_TYPE_THUMB, tl->fd->path, FALSE, &mode);
 
-       if (cache_ensure_dir_exists(cache_dir, mode))
+       if (recursive_mkdir_if_not_exists(cache_dir, mode))
                {
                gchar *cache_path;
                gchar *pathl;
index 64938c9..d685fa1 100644 (file)
@@ -14,7 +14,6 @@
 #include "main.h"
 #include "thumb_standard.h"
 
-#include "cache.h"     /* for cache_ensure_dir_exists */
 #include "image-load.h"
 #include "md5-util.h"
 #include "pixbuf_util.h"
@@ -319,14 +318,14 @@ static void thumb_loader_std_save(ThumbLoaderStd *tl, GdkPixbuf *pixbuf)
                        source_base = remove_level_from_path(tl->fd->path);
                        if (stat_utf8(source_base, &st))
                                {
-                               cache_ensure_dir_exists(base_path, st.st_mode);
+                               recursive_mkdir_if_not_exists(base_path, st.st_mode);
                                }
                        g_free(source_base);
                        }
                }
        else
                {
-               cache_ensure_dir_exists(base_path, THUMB_PERMS_FOLDER);
+               recursive_mkdir_if_not_exists(base_path, THUMB_PERMS_FOLDER);
                }
        g_free(base_path);
 
index a864334..db16b1c 100644 (file)
@@ -762,4 +762,49 @@ gint file_in_path(const gchar *name)
 
        return ret;
 }
+
+gboolean recursive_mkdir_if_not_exists(gchar *path, mode_t mode)
+{
+       if (!path) return FALSE;
+
+       if (!isdir(path))
+               {
+               gchar *npath = g_strdup(path);
+               gchar *p = npath;
+
+               while (p[0] != '\0')
+                       {
+                       p++;
+                       if (p[0] == G_DIR_SEPARATOR || p[0] == '\0')
+                               {
+                               gint end = TRUE;
+
+                               if (p[0] != '\0')
+                                       {
+                                       p[0] = '\0';
+                                       end = FALSE;
+                                       }
+                               
+                               if (!isdir(npath))
+                                       {
+                                       DEBUG_1("creating sub dir:%s", npath);
+                                       if (!mkdir_utf8(npath, mode))
+                                               {
+                                               log_printf("create dir failed: %s\n", npath);
+                                               g_free(npath);
+                                               return FALSE;
+                                               }
+                                       }
+                               
+                               if (!end) p[0] = G_DIR_SEPARATOR;
+                               }
+                       }
+               g_free(npath);
+               }
+
+       return TRUE;
+}
+
+
+
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 2ba463c..ce01722 100644 (file)
@@ -81,5 +81,7 @@ void parse_out_relatives(gchar *path);
 
 gint file_in_path(const gchar *name);
 
+gboolean recursive_mkdir_if_not_exists(gchar *path, mode_t mode);
+
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */