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);
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);
*-------------------------------------------------------------------
*/
-/* 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)
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);
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;
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;
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;
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;
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);
}
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);
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);
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;
#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"
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);
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: */
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: */