Mercurial > geeqie.yaz
changeset 1148:95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
author | zas_ |
---|---|
date | Sat, 15 Nov 2008 20:01:25 +0000 |
parents | 4220d5536ad9 |
children | c4fcf8001574 |
files | 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 |
diffstat | 13 files changed, 59 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bar_info.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/bar_info.c Sat Nov 15 20:01:25 2008 +0000 @@ -98,7 +98,7 @@ 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);
--- a/src/cache-loader.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/cache-loader.c Sat Nov 15 20:01:25 2008 +0000 @@ -168,7 +168,7 @@ 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);
--- a/src/cache.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/cache.c Sat Nov 15 20:01:25 2008 +0000 @@ -582,40 +582,6 @@ *------------------------------------------------------------------- */ -/* 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)
--- a/src/cache.h Sat Nov 15 19:13:43 2008 +0000 +++ b/src/cache.h Sat Nov 15 20:01:25 2008 +0000 @@ -69,8 +69,6 @@ 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);
--- a/src/cache_maint.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/cache_maint.c Sat Nov 15 20:01:25 2008 +0000 @@ -524,7 +524,7 @@ 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 @@ 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 @@ 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;
--- a/src/dupe.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/dupe.c Sat Nov 15 20:01:25 2008 +0000 @@ -435,7 +435,7 @@ 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;
--- a/src/main.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/main.c Sat Nov 15 20:01:25 2008 +0000 @@ -450,7 +450,7 @@ 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); }
--- a/src/pan-view.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/pan-view.c Sat Nov 15 20:01:25 2008 +0000 @@ -638,7 +638,7 @@ 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);
--- a/src/search.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/search.c Sat Nov 15 20:01:25 2008 +0000 @@ -1540,7 +1540,7 @@ 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);
--- a/src/thumb.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/thumb.c Sat Nov 15 20:01:25 2008 +0000 @@ -50,7 +50,7 @@ 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;
--- a/src/thumb_standard.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/thumb_standard.c Sat Nov 15 20:01:25 2008 +0000 @@ -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 @@ 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);
--- a/src/ui_fileops.c Sat Nov 15 19:13:43 2008 +0000 +++ b/src/ui_fileops.c Sat Nov 15 20:01:25 2008 +0000 @@ -762,4 +762,49 @@ 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: */
--- a/src/ui_fileops.h Sat Nov 15 19:13:43 2008 +0000 +++ b/src/ui_fileops.h Sat Nov 15 20:01:25 2008 +0000 @@ -81,5 +81,7 @@ 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: */