Mercurial > geeqie.yaz
diff src/ui_fileops.c @ 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 | 3a7af6a8cd5f |
children | c4fcf8001574 |
line wrap: on
line diff
--- 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: */