/*
* (SLIK) SimpLIstic sKin functions
* (C) 2006 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
*
* Author: John Ellis
*
#include "main.h"
#include "ui_fileops.h"
-#include "debug.h"
#include "ui_utildlg.h" /* for locale warning dialog */
+#include "md5-util.h"
/*
*-----------------------------------------------------------------------------
gchar *text_l;
text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL);
- printf((text_l) ? text_l : text_utf8);
+ fputs((text_l) ? text_l : text_utf8, stderr);
g_free(text_l);
}
-static void encoding_dialog(const gchar *path);
-
-static gint encoding_dialog_idle(gpointer data)
-{
- gchar *path = data;
-
- encoding_dialog(path);
- g_free(path);
-
- return FALSE;
-}
-
-static gint encoding_dialog_delay(gpointer data)
-{
- g_idle_add(encoding_dialog_idle, data);
-
- return 0;
-}
-
static void encoding_dialog(const gchar *path)
{
- static gint warned_user = FALSE;
+ static gboolean warned_user = FALSE;
GenericDialog *gd;
GString *string;
const gchar *lc;
const gchar *bf;
- /* check that gtk is initialized (loop is level > 0) */
- if (gtk_main_level() == 0)
- {
- /* gtk not initialized */
- gtk_init_add(encoding_dialog_delay, g_strdup(path));
- return;
- }
-
if (warned_user) return;
warned_user = TRUE;
lc = getenv("LANG");
bf = getenv("G_BROKEN_FILENAMES");
- warned_user = TRUE;
string = g_string_new("");
- g_string_append(string, "One or more filenames are not encoded with the preferred locale character set.\n");
- g_string_append_printf(string, "Operations on, and display of these files with %s may not succeed.\n\n", PACKAGE);
- g_string_append(string, "If your filenames are not encoded in utf-8, try setting\n");
- g_string_append(string, "the environment variable G_BROKEN_FILENAMES=1\n");
- g_string_append_printf(string, "It appears G_BROKEN_FILENAMES is %s%s\n\n",
- (bf) ? "set to " : "not set.", (bf) ? bf : "");
- g_string_append_printf(string, "The locale appears to be set to \"%s\"\n(set by the LANG environment variable)\n", (lc) ? lc : "undefined");
+ g_string_append(string, _("One or more filenames are not encoded with the preferred locale character set.\n"));
+ g_string_append_printf(string, _("Operations on, and display of these files with %s may not succeed.\n"), PACKAGE);
+ g_string_append(string, "\n");
+ g_string_append(string, _("If your filenames are not encoded in utf-8, try setting the environment variable G_BROKEN_FILENAMES=1\n"));
+ if (bf)
+ g_string_append_printf(string, _("It appears G_BROKEN_FILENAMES is set to %s\n"), bf);
+ else
+ g_string_append(string, _("It appears G_BROKEN_FILENAMES is not set\n"));
+ g_string_append(string, "\n");
+ g_string_append_printf(string, _("The locale appears to be set to \"%s\"\n(set by the LANG environment variable)\n"), (lc) ? lc : "undefined");
if (lc && (strstr(lc, "UTF-8") || strstr(lc, "utf-8")))
{
gchar *name;
name = g_convert(path, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
- string = g_string_append(string, "\nPreferred encoding appears to be UTF-8, however the file:\n");
- g_string_append_printf(string, "\"%s\"\n%s encoded in valid UTF-8.\n",
- (name) ? name : "[name not displayable]",
- (g_utf8_validate(path, -1, NULL)) ? "is": "is NOT");
+ string = g_string_append(string, _("\nPreferred encoding appears to be UTF-8, however the file:\n"));
+ g_string_append_printf(string, "\"%s\"\n", (name) ? name : _("[name not displayable]"));
+
+ if (g_utf8_validate(path, -1, NULL))
+ g_string_append_printf(string, _("\"%s\" is encoded in valid UTF-8."), (name) ? name : _("[name not displayable]"));
+ else
+ g_string_append_printf(string, _("\"%s\" is not encoded in valid UTF-8."), (name) ? name : _("[name not displayable]"));
+ g_string_append(string, "\n");
g_free(name);
}
- gd = generic_dialog_new("Filename encoding locale mismatch",
- GQ_WMCLASS, "locale warning", NULL, TRUE, NULL, NULL);
+ gd = generic_dialog_new(_("Filename encoding locale mismatch"),
+ "locale warning", NULL, TRUE, NULL, NULL);
generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE);
generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING,
- "Filename encoding locale mismatch", string->str);
+ _("Filename encoding locale mismatch"), string->str);
gtk_widget_show(gd->dialog);
g_string_free(string, TRUE);
}
+#if GQ_DEBUG_PATH_UTF8
+gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line)
+#else
gchar *path_to_utf8(const gchar *path)
+#endif
{
gchar *utf8;
GError *error = NULL;
utf8 = g_filename_to_utf8(path, -1, NULL, NULL, &error);
if (error)
{
- printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message);
+#if GQ_DEBUG_PATH_UTF8
+ log_printf("%s:%d: Unable to convert filename to UTF-8:\n%s\n%s\n", file, line, path, error->message);
+#else
+ log_printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message);
+#endif
g_error_free(error);
encoding_dialog(path);
}
return utf8;
}
+#if GQ_DEBUG_PATH_UTF8
+gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line)
+#else
gchar *path_from_utf8(const gchar *utf8)
+#endif
{
gchar *path;
GError *error = NULL;
path = g_filename_from_utf8(utf8, -1, NULL, NULL, &error);
if (error)
{
- printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message);
+#if GQ_DEBUG_PATH_UTF8
+ log_printf("%s:%d: Unable to convert filename to locale from UTF-8:\n%s\n%s\n", file, line, utf8, error->message);
+#else
+ log_printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message);
+#endif
g_error_free(error);
}
if (!path)
return path;
}
-/* first we try the HOME environment var, if that doesn't work, we try getpwuid(). */
+/* first we try the HOME environment var, if that doesn't work, we try g_get_homedir(). */
const gchar *homedir(void)
{
static gchar *home = NULL;
if (!home)
- {
home = path_to_utf8(getenv("HOME"));
- }
+
if (!home)
+ home = path_to_utf8(g_get_home_dir());
+
+ return home;
+}
+
+static gchar *xdg_dir_get(const gchar *key, const gchar *fallback)
+{
+ gchar *dir = getenv(key);
+
+ if (!dir || dir[0] == '\0')
{
- struct passwd *pw = getpwuid(getuid());
- if (pw) home = path_to_utf8(pw->pw_dir);
+ return g_build_filename(homedir(), fallback, NULL);
+ }
+
+ return path_to_utf8(dir);
+}
+
+const gchar *xdg_data_home_get(void)
+{
+ static const gchar *xdg_data_home = NULL;
+
+ if (xdg_data_home) return xdg_data_home;
+
+ xdg_data_home = xdg_dir_get("XDG_DATA_HOME", ".local/share");
+
+ return xdg_data_home;
+}
+
+const gchar *xdg_config_home_get(void)
+{
+ static const gchar *xdg_config_home = NULL;
+
+ if (xdg_config_home) return xdg_config_home;
+
+ xdg_config_home = xdg_dir_get("XDG_CONFIG_HOME", ".config");
+
+ return xdg_config_home;
+}
+
+const gchar *xdg_cache_home_get(void)
+{
+ static const gchar *xdg_cache_home = NULL;
+
+ if (xdg_cache_home) return xdg_cache_home;
+
+ xdg_cache_home = xdg_dir_get("XDG_CACHE_HOME", ".cache");
+
+ return xdg_cache_home;
+}
+
+const gchar *get_rc_dir(void)
+{
+ static gchar *rc_dir = NULL;
+
+ if (rc_dir) return rc_dir;
+
+ if (USE_XDG)
+ {
+ rc_dir = g_build_filename(xdg_config_home_get(), GQ_APPNAME_LC, NULL);
+ }
+ else
+ {
+ rc_dir = g_build_filename(homedir(), GQ_RC_DIR, NULL);
}
- return home;
+ return rc_dir;
}
-gint stat_utf8(const gchar *s, struct stat *st)
+const gchar *get_collections_dir(void)
+{
+ static gchar *collections_dir = NULL;
+
+ if (collections_dir) return collections_dir;
+
+ if (USE_XDG)
+ {
+ collections_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_COLLECTIONS_DIR, NULL);
+ }
+ else
+ {
+ collections_dir = g_build_filename(get_rc_dir(), GQ_COLLECTIONS_DIR, NULL);
+ }
+
+ return collections_dir;
+}
+
+const gchar *get_trash_dir(void)
+{
+ static gchar *trash_dir = NULL;
+
+ if (trash_dir) return trash_dir;
+
+ if (USE_XDG)
+ {
+ trash_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_TRASH_DIR, NULL);
+ }
+ else
+ {
+ trash_dir = g_build_filename(get_rc_dir(), GQ_TRASH_DIR, NULL);
+ }
+
+ return trash_dir;
+}
+
+gboolean stat_utf8(const gchar *s, struct stat *st)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
sl = path_from_utf8(s);
return ret;
}
-gint lstat_utf8(const gchar *s, struct stat *st)
+gboolean lstat_utf8(const gchar *s, struct stat *st)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
sl = path_from_utf8(s);
return ret;
}
-gint isname(const gchar *s)
+gboolean isname(const gchar *s)
{
struct stat st;
return stat_utf8(s, &st);
}
-gint isfile(const gchar *s)
+gboolean isfile(const gchar *s)
{
struct stat st;
return (stat_utf8(s, &st) && S_ISREG(st.st_mode));
}
-gint isdir(const gchar *s)
+gboolean isdir(const gchar *s)
{
struct stat st;
- return (stat_utf8(s ,&st) && S_ISDIR(st.st_mode));
+ return (stat_utf8(s, &st) && S_ISDIR(st.st_mode));
}
-gint islink(const gchar *s)
+gboolean islink(const gchar *s)
{
struct stat st;
- return (lstat_utf8(s ,&st) && S_ISLNK(st.st_mode));
+ return (lstat_utf8(s, &st) && S_ISLNK(st.st_mode));
}
gint64 filesize(const gchar *s)
struct stat st;
if (!stat_utf8(s, &st)) return 0;
- return (gint)st.st_size;
+ return st.st_size;
}
time_t filetime(const gchar *s)
return st.st_mtime;
}
-gint filetime_set(const gchar *s, time_t tval)
+gboolean filetime_set(const gchar *s, time_t tval)
{
- gint ret = FALSE;
+ gboolean ret = FALSE;
if (tval > 0)
{
return ret;
}
-gint access_file(const gchar *s, int mode)
+gboolean is_readable_file(const gchar *s)
+{
+ if (!s || !s[0] || !isfile(s)) return FALSE;
+ return access_file(s, R_OK);
+}
+
+gboolean access_file(const gchar *s, gint mode)
{
gchar *sl;
gint ret;
- if (!s) return FALSE;
+ if (!s || !s[0]) return FALSE;
sl = path_from_utf8(s);
ret = (access(sl, mode) == 0);
return ret;
}
-gint unlink_file(const gchar *s)
+gboolean unlink_file(const gchar *s)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
return ret;
}
-gint symlink_utf8(const gchar *source, const gchar *target)
+gboolean symlink_utf8(const gchar *source, const gchar *target)
{
gchar *sl;
gchar *tl;
- gint ret;
+ gboolean ret;
if (!source || !target) return FALSE;
return ret;
}
-gint mkdir_utf8(const gchar *s, int mode)
+gboolean mkdir_utf8(const gchar *s, gint mode)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
return ret;
}
-gint rmdir_utf8(const gchar *s)
+gboolean rmdir_utf8(const gchar *s)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
return ret;
}
-gint copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime)
+gboolean copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime)
{
struct stat st;
gchar *sl, *tl;
- gint ret = FALSE;
+ gboolean ret = FALSE;
if (!s || !t) return FALSE;
/* set the dest file attributes to that of source (ignoring errors) */
- if (perms && chown(tl, st.st_uid, st.st_gid) < 0) ret = FALSE;
- if (perms && chmod(tl, st.st_mode) < 0) ret = FALSE;
+ if (perms)
+ {
+ ret = chown(tl, st.st_uid, st.st_gid);
+ /* Ignores chown errors, while still doing chown
+ (so root still can copy files preserving ownership) */
+ ret = TRUE;
+ if (chmod(tl, st.st_mode) < 0) ret = FALSE;
+ }
tb.actime = st.st_atime;
tb.modtime = st.st_mtime;
}
/* paths are in filesystem encoding */
-static gint hard_linked(const gchar *a, const gchar *b)
+static gboolean hard_linked(const gchar *a, const gchar *b)
{
struct stat sta;
struct stat stb;
sta.st_ino == stb.st_ino);
}
-gint copy_file(const gchar *s, const gchar *t)
+gboolean copy_file(const gchar *s, const gchar *t)
{
FILE *fi = NULL;
FILE *fo = NULL;
- gchar *sl, *tl;
- gchar buf[4096];
- gint b;
+ gchar *sl = NULL;
+ gchar *tl = NULL;
+ gchar *randname = NULL;
+ gchar buf[16384];
+ size_t b;
+ gint ret = FALSE;
+ gint fd = -1;
sl = path_from_utf8(s);
tl = path_from_utf8(t);
if (hard_linked(sl, tl))
{
- g_free(sl);
- g_free(tl);
- return TRUE;
+ ret = TRUE;
+ goto end;
}
fi = fopen(sl, "rb");
- if (fi)
+ if (!fi) goto end;
+
+ /* First we write to a temporary file, then we rename it on success,
+ and attributes from original file are copied */
+ randname = g_strconcat(tl, ".tmp_XXXXXX", NULL);
+ if (!randname) goto end;
+
+ fd = g_mkstemp(randname);
+ if (fd == -1) goto end;
+
+ fo = fdopen(fd, "wb");
+ if (!fo) {
+ close(fd);
+ goto end;
+ }
+
+ while ((b = fread(buf, sizeof(gchar), sizeof(buf), fi)) && b != 0)
{
- fo = fopen(tl, "wb");
- if (!fo)
+ if (fwrite(buf, sizeof(gchar), b, fo) != b)
{
- fclose(fi);
- fi = NULL;
+ unlink(randname);
+ goto end;
}
}
- g_free(sl);
- g_free(tl);
-
- if (!fi || !fo) return FALSE;
+ fclose(fi); fi = NULL;
+ fclose(fo); fo = NULL;
- while ((b = fread(buf, sizeof(char), sizeof(buf), fi)) && b != 0)
- {
- if (fwrite(buf, sizeof(char), b, fo) != b)
- {
- fclose(fi);
- fclose(fo);
- return FALSE;
- }
- }
+ if (rename(randname, tl) < 0) {
+ unlink(randname);
+ goto end;
+ }
- fclose(fi);
- fclose(fo);
+ ret = copy_file_attributes(s, t, TRUE, TRUE);
- copy_file_attributes(s, t, TRUE, TRUE);
-
- return TRUE;
+end:
+ if (fi) fclose(fi);
+ if (fo) fclose(fo);
+ if (sl) g_free(sl);
+ if (tl) g_free(tl);
+ if (randname) g_free(randname);
+ return ret;
}
-gint move_file(const gchar *s, const gchar *t)
+gboolean move_file(const gchar *s, const gchar *t)
{
gchar *sl, *tl;
- gint ret = TRUE;
+ gboolean ret = TRUE;
if (!s || !t) return FALSE;
return ret;
}
-gint rename_file(const gchar *s, const gchar *t)
+gboolean rename_file(const gchar *s, const gchar *t)
{
gchar *sl, *tl;
- gint ret;
+ gboolean ret;
if (!s || !t) return FALSE;
return path8;
}
-static gint path_list_real(const gchar *path, GList **files, GList **dirs,
- gint follow_links)
-{
- DIR *dp;
- struct dirent *dir;
- GList *f_list = NULL;
- GList *d_list = NULL;
- gchar *pathl;
-
- if (!path) return FALSE;
-
- pathl = path_from_utf8(path);
- dp = opendir(pathl);
- if (!dp)
- {
- /* dir not found */
- g_free(pathl);
- return FALSE;
- }
-
- /* root dir fix */
- if (pathl[0] == '/' && pathl[1] == '\0')
- {
- g_free(pathl);
- pathl = g_strdup("");
- }
-
- while ((dir = readdir(dp)) != NULL)
- {
- struct stat st_buf;
- gchar *name;
- gchar *filepath;
- gint result;
-
- name = dir->d_name;
- filepath = g_strconcat(pathl, "/", name, NULL);
-
- if (follow_links)
- {
- result = stat(filepath, &st_buf);
- }
- else
- {
- result = lstat(filepath, &st_buf);
- }
-
- if (result == 0)
- {
- gchar *path8;
- gchar *name8;
-
- name8 = path_to_utf8(name);
- path8 = g_strconcat(path, "/", name8, NULL);
- g_free(name8);
-
- if (dirs && S_ISDIR(st_buf.st_mode) &&
- !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) )
- {
- d_list = g_list_prepend(d_list, path8);
- path8 = NULL;
- }
- else if (files &&
- (S_ISREG(st_buf.st_mode) || (!follow_links && S_ISLNK(st_buf.st_mode))) )
- {
- f_list = g_list_prepend(f_list, path8);
- path8 = NULL;
- }
- g_free(path8);
- }
-
- g_free(filepath);
- }
-
- closedir(dp);
-
- g_free(pathl);
-
- if (dirs) *dirs = g_list_reverse(d_list);
- if (files) *files = g_list_reverse(f_list);
-
- return TRUE;
-}
-
-gint path_list(const gchar *path, GList **files, GList **dirs)
-{
- return path_list_real(path, files, dirs, TRUE);
-}
-
-gint path_list_lstat(const gchar *path, GList **files, GList **dirs)
-{
- return path_list_real(path, files, dirs, FALSE);
-}
-
-void path_list_free(GList *list)
+void string_list_free(GList *list)
{
g_list_foreach(list, (GFunc)g_free, NULL);
g_list_free(list);
}
-GList *path_list_copy(GList *list)
+GList *string_list_copy(const GList *list)
{
GList *new_list = NULL;
- GList *work;
+ GList *work = (GList *) list;
- work = list;
while (work)
{
gchar *path;
return g_list_reverse(new_list);
}
-long checksum_simple(const gchar *path)
-{
- gchar *path8;
- FILE *f;
- long sum = 0;
- gint c;
-
- path8 = path_from_utf8(path);
- f = fopen(path8, "r");
- g_free(path8);
- if (!f) return -1;
-
- while ((c = fgetc(f)) != EOF)
- {
- sum += c;
- }
-
- fclose(f);
-
- return sum;
-}
-
-gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gint pad)
+gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gboolean pad)
{
gchar *unique;
gint n = 1;
if (!path) return NULL;
- base = strrchr(path, '/');
+ base = strrchr(path, G_DIR_SEPARATOR);
if (base) return base + 1;
return path;
while (path[p])
{
- if (path[p] == '/') n = p;
+ if (path[p] == G_DIR_SEPARATOR) n = p;
p++;
}
if (n <= 0) n++;
return g_strndup(path, (gsize) n);
}
-gchar *concat_dir_and_file(const gchar *base, const gchar *name)
-{
- if (!base || !name) return NULL;
-
- if (strcmp(base, "/") == 0) return g_strconcat(base, name, NULL);
-
- return g_strconcat(base, "/", name, NULL);
-}
-
const gchar *extension_from_path(const gchar *path)
{
if (!path) return NULL;
return strrchr(path, '.');
}
-gint file_extension_match(const gchar *path, const gchar *ext)
+gboolean file_extension_match(const gchar *path, const gchar *ext)
{
gint p;
gint e;
p = strlen(path);
e = strlen(ext);
- return (p > e && strncasecmp(path + p - e, ext, e) == 0);
+ /* FIXME: utf8 */
+ return (p > e && g_ascii_strncasecmp(path + p - e, ext, e) == 0);
}
gchar *remove_extension_from_path(const gchar *path)
{
- gchar *new_path;
- const gchar *ptr = path;
- gint p;
+ gint p = 0, n = -1;
if (!path) return NULL;
- if (strlen(path) < 2) return g_strdup(path);
- p = strlen(path) - 1;
- while (ptr[p] != '.' && p > 0) p--;
- if (p == 0) p = strlen(path) - 1;
- new_path = g_strndup(path, (guint)p);
- return new_path;
+ while (path[p])
+ {
+ if (path[p] == '.') n = p;
+ p++;
+ }
+ if (n < 0) n = p;
+
+ return g_strndup(path, (gsize) n);
}
void parse_out_relatives(gchar *path)
while (path[s] != '\0')
{
- if (path[s] == '/' && path[s+1] == '.' && (path[s+2] == '/' || path[s+2] == '\0') )
+ if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.')
{
- s += 2;
- }
- else if (path[s] == '/' && path[s+1] == '.' && path[s+2] == '.' && (path[s+3] == '/' || path[s+3] == '\0') )
- {
- s += 3;
- if (t > 0) t--;
- while (path[t] != '/' && t > 0) t--;
- }
- else
- {
- if (s != t) path[t] = path[s];
- t++;
- s++;
+ /* /. occurence, let's see more */
+ gint p = s + 2;
+
+ if (path[p] == G_DIR_SEPARATOR || path[p] == '\0')
+ {
+ /* /./ or /., just skip this part */
+ s = p;
+ continue;
+ }
+ else if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0'))
+ {
+ /* /../ or /.., remove previous part, ie. /a/b/../ becomes /a/ */
+ s = p + 1;
+ if (t > 0) t--;
+ while (path[t] != G_DIR_SEPARATOR && t > 0) t--;
+ continue;
+ }
}
+
+ if (s != t) path[t] = path[s];
+ t++;
+ s++;
}
- if (t == 0 && path[t] == '/') t++;
- if (t > 1 && path[t-1] == '/') t--;
+
+ if (t == 0 && path[t] == G_DIR_SEPARATOR) t++;
+ if (t > 1 && path[t-1] == G_DIR_SEPARATOR) t--;
path[t] = '\0';
}
-gint file_in_path(const gchar *name)
+gboolean file_in_path(const gchar *name)
{
gchar *path;
gchar *namel;
gint p, l;
- gint ret = FALSE;
+ gboolean ret = FALSE;
if (!name) return FALSE;
path = g_strdup(getenv("PATH"));
while (path[e] != ':' && path[e] != '\0') e++;
path[e] = '\0';
e++;
- f = g_strconcat(path + p, "/", namel, NULL);
+ f = g_build_filename(path + p, namel, NULL);
if (isfile(f)) ret = TRUE;
g_free(f);
p = e;
return ret;
}
+
+gboolean recursive_mkdir_if_not_exists(const 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')
+ {
+ gboolean 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;
+}
+
+/* does filename utf8 to filesystem encoding first */
+gboolean md5_get_digest_from_file_utf8(const gchar *path, guchar digest[16])
+{
+ gboolean success;
+ gchar *pathl;
+
+ pathl = path_from_utf8(path);
+ success = md5_get_digest_from_file(pathl, digest);
+ g_free(pathl);
+
+ return success;
+}
+
+
+gchar *md5_text_from_file_utf8(const gchar *path, const gchar *error_text)
+{
+ guchar digest[16];
+
+ if (!md5_get_digest_from_file_utf8(path, digest)) return g_strdup(error_text);
+
+ return md5_digest_to_text(digest);
+}
+
+
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */