Mercurial > hg > forks > geeqie
annotate src/ui_fileops.c @ 2916:ae6cdcd69d9f default tip
Merge with upstream/master.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 14 May 2019 11:46:50 +0300 |
parents | 667eb6d5a0b1 |
children |
rev | line source |
---|---|
9 | 1 /* |
2350
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
2 * Copyright (C) 2006 John Ellis |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
3 * Copyright (C) 2008 - 2016 The Geeqie Team |
9 | 4 * |
5 * Author: John Ellis | |
6 * | |
2350
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
10 * (at your option) any later version. |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
11 * |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
15 * GNU General Public License for more details. |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
16 * |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
18 * with this program; if not, write to the Free Software Foundation, Inc., |
95507e596256
Update copyright in all files
Klaus Ethgen <Klaus@Ethgen.de>
parents:
2185
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
9 | 20 */ |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 #include <pwd.h> | |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 #include <unistd.h> | |
31 #include <sys/param.h> | |
32 #include <dirent.h> | |
33 #include <utime.h> | |
34 | |
35 #include <glib.h> | |
36 #include <gtk/gtk.h> /* for locale warning dialog */ | |
37 | |
281 | 38 #include "main.h" |
9 | 39 #include "ui_fileops.h" |
40 | |
41 #include "ui_utildlg.h" /* for locale warning dialog */ | |
1642
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
42 #include "md5-util.h" |
9 | 43 |
2454
93d1c77a312b
Fix #147: Alternative format for sidecar extension
Tomasz Golinski <tomaszg@math.uwb.edu.pl>
parents:
2350
diff
changeset
|
44 #include "filefilter.h" |
2508
a39331032807
Additional debug features
Colin Clark <colin.clark@cclark.uk>
parents:
2459
diff
changeset
|
45 #include "secure_save.h" |
a39331032807
Additional debug features
Colin Clark <colin.clark@cclark.uk>
parents:
2459
diff
changeset
|
46 |
9 | 47 /* |
48 *----------------------------------------------------------------------------- | |
49 * generic file information and manipulation routines (public) | |
50 *----------------------------------------------------------------------------- | |
442 | 51 */ |
9 | 52 |
53 | |
54 | |
2678
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
55 void print_term(gboolean err, const gchar *text_utf8) |
9 | 56 { |
57 gchar *text_l; | |
58 | |
59 text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL); | |
2678
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
60 if (err) |
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
61 { |
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
62 fputs((text_l) ? text_l : text_utf8, stderr); |
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
63 } |
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
64 else |
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
65 { |
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
66 fputs((text_l) ? text_l : text_utf8, stdout); |
195267d1c78f
Fix #548: Send text output to stdout
cclark <colin.clark@cclark.uk>
parents:
2674
diff
changeset
|
67 } |
2508
a39331032807
Additional debug features
Colin Clark <colin.clark@cclark.uk>
parents:
2459
diff
changeset
|
68 if(command_line && command_line->ssi) |
a39331032807
Additional debug features
Colin Clark <colin.clark@cclark.uk>
parents:
2459
diff
changeset
|
69 secure_fputs(command_line->ssi, (text_l) ? text_l : text_utf8); |
9 | 70 g_free(text_l); |
71 } | |
72 | |
73 static void encoding_dialog(const gchar *path) | |
74 { | |
1437 | 75 static gboolean warned_user = FALSE; |
9 | 76 GenericDialog *gd; |
77 GString *string; | |
78 const gchar *lc; | |
79 const gchar *bf; | |
80 | |
81 if (warned_user) return; | |
82 warned_user = TRUE; | |
83 | |
84 lc = getenv("LANG"); | |
85 bf = getenv("G_BROKEN_FILENAMES"); | |
86 | |
87 string = g_string_new(""); | |
989
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
88 g_string_append(string, _("One or more filenames are not encoded with the preferred locale character set.\n")); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
89 g_string_append_printf(string, _("Operations on, and display of these files with %s may not succeed.\n"), PACKAGE); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
90 g_string_append(string, "\n"); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
91 g_string_append(string, _("If your filenames are not encoded in utf-8, try setting the environment variable G_BROKEN_FILENAMES=1\n")); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
92 if (bf) |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
93 g_string_append_printf(string, _("It appears G_BROKEN_FILENAMES is set to %s\n"), bf); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
94 else |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
95 g_string_append(string, _("It appears G_BROKEN_FILENAMES is not set\n")); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
96 g_string_append(string, "\n"); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
97 g_string_append_printf(string, _("The locale appears to be set to \"%s\"\n(set by the LANG environment variable)\n"), (lc) ? lc : "undefined"); |
9 | 98 if (lc && (strstr(lc, "UTF-8") || strstr(lc, "utf-8"))) |
99 { | |
100 gchar *name; | |
101 name = g_convert(path, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); | |
989
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
102 string = g_string_append(string, _("\nPreferred encoding appears to be UTF-8, however the file:\n")); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
103 g_string_append_printf(string, "\"%s\"\n", (name) ? name : _("[name not displayable]")); |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
104 |
989
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
105 if (g_utf8_validate(path, -1, NULL)) |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
106 g_string_append_printf(string, _("\"%s\" is encoded in valid UTF-8."), (name) ? name : _("[name not displayable]")); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
107 else |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
108 g_string_append_printf(string, _("\"%s\" is not encoded in valid UTF-8."), (name) ? name : _("[name not displayable]")); |
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
109 g_string_append(string, "\n"); |
9 | 110 g_free(name); |
111 } | |
112 | |
989
9c9909249006
Fix untranslated messages. French translation and POTFILES.in were updated.
Laurent Monin <geeqie@norz.org>
parents:
983
diff
changeset
|
113 gd = generic_dialog_new(_("Filename encoding locale mismatch"), |
1174
f809d57aed0c
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
Laurent Monin <geeqie@norz.org>
parents:
1164
diff
changeset
|
114 "locale warning", NULL, TRUE, NULL, NULL); |
9 | 115 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE); |
116 | |
117 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING, | |
2587
c6f9494f6be1
Fix #508: Copy and Move windows scale incorrectly
cclark <colin.clark@cclark.uk>
parents:
2585
diff
changeset
|
118 _("Filename encoding locale mismatch"), string->str, TRUE); |
9 | 119 |
120 gtk_widget_show(gd->dialog); | |
121 | |
122 g_string_free(string, TRUE); | |
123 } | |
124 | |
1386
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
125 #if GQ_DEBUG_PATH_UTF8 |
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
126 gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line) |
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
127 #else |
9 | 128 gchar *path_to_utf8(const gchar *path) |
1386
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
129 #endif |
9 | 130 { |
131 gchar *utf8; | |
132 GError *error = NULL; | |
133 | |
134 if (!path) return NULL; | |
135 | |
136 utf8 = g_filename_to_utf8(path, -1, NULL, NULL, &error); | |
137 if (error) | |
138 { | |
1386
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
139 #if GQ_DEBUG_PATH_UTF8 |
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
140 log_printf("%s:%d: Unable to convert filename to UTF-8:\n%s\n%s\n", file, line, path, error->message); |
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
141 #else |
673
c9c2bc042e10
Do not use printf() directly but use new wrapper function log_printf() instead.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
142 log_printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message); |
1386
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
143 #endif |
9 | 144 g_error_free(error); |
145 encoding_dialog(path); | |
146 } | |
147 if (!utf8) | |
148 { | |
149 /* just let it through, but bad things may happen */ | |
150 utf8 = g_strdup(path); | |
151 } | |
152 | |
153 return utf8; | |
154 } | |
155 | |
1386
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
156 #if GQ_DEBUG_PATH_UTF8 |
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
157 gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line) |
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
158 #else |
9 | 159 gchar *path_from_utf8(const gchar *utf8) |
1386
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
160 #endif |
9 | 161 { |
162 gchar *path; | |
163 GError *error = NULL; | |
164 | |
165 if (!utf8) return NULL; | |
166 | |
167 path = g_filename_from_utf8(utf8, -1, NULL, NULL, &error); | |
168 if (error) | |
169 { | |
1386
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
170 #if GQ_DEBUG_PATH_UTF8 |
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
171 log_printf("%s:%d: Unable to convert filename to locale from UTF-8:\n%s\n%s\n", file, line, utf8, error->message); |
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
172 #else |
673
c9c2bc042e10
Do not use printf() directly but use new wrapper function log_printf() instead.
Laurent Monin <geeqie@norz.org>
parents:
671
diff
changeset
|
173 log_printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message); |
1386
e9c4c6247ae3
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
Laurent Monin <geeqie@norz.org>
parents:
1360
diff
changeset
|
174 #endif |
9 | 175 g_error_free(error); |
176 } | |
177 if (!path) | |
178 { | |
179 /* if invalid UTF-8, text probaby still in original form, so just copy it */ | |
180 path = g_strdup(utf8); | |
181 } | |
182 | |
183 return path; | |
184 } | |
185 | |
998
788d59ed765b
Fixed segfault when is run inside directory with non valid uft-8 image
Petr Ostadal <postadal@suse.cz>
parents:
990
diff
changeset
|
186 /* first we try the HOME environment var, if that doesn't work, we try g_get_homedir(). */ |
9 | 187 const gchar *homedir(void) |
188 { | |
189 static gchar *home = NULL; | |
190 | |
191 if (!home) | |
192 home = path_to_utf8(getenv("HOME")); | |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
193 |
9 | 194 if (!home) |
998
788d59ed765b
Fixed segfault when is run inside directory with non valid uft-8 image
Petr Ostadal <postadal@suse.cz>
parents:
990
diff
changeset
|
195 home = path_to_utf8(g_get_home_dir()); |
9 | 196 |
2681 | 197 DEBUG_1("Home directory: %s", home); |
198 | |
9 | 199 return home; |
200 } | |
201 | |
1149
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
202 static gchar *xdg_dir_get(const gchar *key, const gchar *fallback) |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
203 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
204 gchar *dir = getenv(key); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
205 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
206 if (!dir || dir[0] == '\0') |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
207 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
208 return g_build_filename(homedir(), fallback, NULL); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
209 } |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
210 |
2681 | 211 DEBUG_1("Got xdg %s: %s", key, dir); |
212 | |
1149
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
213 return path_to_utf8(dir); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
214 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
215 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
216 const gchar *xdg_data_home_get(void) |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
217 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
218 static const gchar *xdg_data_home = NULL; |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
219 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
220 if (xdg_data_home) return xdg_data_home; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
221 |
1149
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
222 xdg_data_home = xdg_dir_get("XDG_DATA_HOME", ".local/share"); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
223 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
224 return xdg_data_home; |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
225 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
226 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
227 const gchar *xdg_config_home_get(void) |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
228 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
229 static const gchar *xdg_config_home = NULL; |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
230 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
231 if (xdg_config_home) return xdg_config_home; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
232 |
1149
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
233 xdg_config_home = xdg_dir_get("XDG_CONFIG_HOME", ".config"); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
234 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
235 return xdg_config_home; |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
236 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
237 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
238 const gchar *xdg_cache_home_get(void) |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
239 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
240 static const gchar *xdg_cache_home = NULL; |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
241 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
242 if (xdg_cache_home) return xdg_cache_home; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
243 |
1149
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
244 xdg_cache_home = xdg_dir_get("XDG_CACHE_HOME", ".cache"); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
245 |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
246 return xdg_cache_home; |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
247 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
248 |
1145
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
249 const gchar *get_rc_dir(void) |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
250 { |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
251 static gchar *rc_dir = NULL; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
252 |
1145
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
253 if (rc_dir) return rc_dir; |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
254 |
1149
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
255 if (USE_XDG) |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
256 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
257 rc_dir = g_build_filename(xdg_config_home_get(), GQ_APPNAME_LC, NULL); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
258 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
259 else |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
260 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
261 rc_dir = g_build_filename(homedir(), GQ_RC_DIR, NULL); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
262 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
263 |
1145
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
264 return rc_dir; |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
265 } |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
266 |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
267 const gchar *get_collections_dir(void) |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
268 { |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
269 static gchar *collections_dir = NULL; |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
270 |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
271 if (collections_dir) return collections_dir; |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
272 |
1149
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
273 if (USE_XDG) |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
274 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
275 collections_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_COLLECTIONS_DIR, NULL); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
276 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
277 else |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
278 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
279 collections_dir = g_build_filename(get_rc_dir(), GQ_COLLECTIONS_DIR, NULL); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
280 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
281 |
1145
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
282 return collections_dir; |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
283 } |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
284 |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
285 const gchar *get_trash_dir(void) |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
286 { |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
287 static gchar *trash_dir = NULL; |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
288 |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
289 if (trash_dir) return trash_dir; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
290 |
1149
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
291 if (USE_XDG) |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
292 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
293 trash_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_TRASH_DIR, NULL); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
294 } |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
295 else |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
296 { |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
297 trash_dir = g_build_filename(get_rc_dir(), GQ_TRASH_DIR, NULL); |
fc690206842a
Implement preliminary support for XDG Base Directory Specification.
Laurent Monin <geeqie@norz.org>
parents:
1148
diff
changeset
|
298 } |
1145
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
299 |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
300 return trash_dir; |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
301 } |
94adf34fe826
Use functions to return directories instead of constants.
Laurent Monin <geeqie@norz.org>
parents:
1055
diff
changeset
|
302 |
1448 | 303 gboolean stat_utf8(const gchar *s, struct stat *st) |
9 | 304 { |
305 gchar *sl; | |
1448 | 306 gboolean ret; |
9 | 307 |
308 if (!s) return FALSE; | |
309 sl = path_from_utf8(s); | |
310 ret = (stat(sl, st) == 0); | |
311 g_free(sl); | |
312 | |
313 return ret; | |
314 } | |
315 | |
1448 | 316 gboolean lstat_utf8(const gchar *s, struct stat *st) |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
317 { |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
318 gchar *sl; |
1448 | 319 gboolean ret; |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
320 |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
321 if (!s) return FALSE; |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
322 sl = path_from_utf8(s); |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
323 ret = (lstat(sl, st) == 0); |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
324 g_free(sl); |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
325 |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
326 return ret; |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
327 } |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
328 |
1448 | 329 gboolean isname(const gchar *s) |
9 | 330 { |
331 struct stat st; | |
332 | |
333 return stat_utf8(s, &st); | |
334 } | |
335 | |
1448 | 336 gboolean isfile(const gchar *s) |
9 | 337 { |
338 struct stat st; | |
339 | |
340 return (stat_utf8(s, &st) && S_ISREG(st.st_mode)); | |
341 } | |
342 | |
1448 | 343 gboolean isdir(const gchar *s) |
9 | 344 { |
345 struct stat st; | |
442 | 346 |
1198 | 347 return (stat_utf8(s, &st) && S_ISDIR(st.st_mode)); |
9 | 348 } |
349 | |
1448 | 350 gboolean islink(const gchar *s) |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
351 { |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
352 struct stat st; |
442 | 353 |
1198 | 354 return (lstat_utf8(s, &st) && S_ISLNK(st.st_mode)); |
40
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
355 } |
d561a5869d5f
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
John Ellis <johne@verizon.net>
parents:
9
diff
changeset
|
356 |
9 | 357 gint64 filesize(const gchar *s) |
358 { | |
359 struct stat st; | |
442 | 360 |
9 | 361 if (!stat_utf8(s, &st)) return 0; |
983
b3611ad72b1b
Remove unneeded type casting.
Laurent Monin <geeqie@norz.org>
parents:
919
diff
changeset
|
362 return st.st_size; |
9 | 363 } |
364 | |
365 time_t filetime(const gchar *s) | |
366 { | |
442 | 367 struct stat st; |
9 | 368 |
369 if (!stat_utf8(s, &st)) return 0; | |
370 return st.st_mtime; | |
371 } | |
372 | |
1448 | 373 gboolean filetime_set(const gchar *s, time_t tval) |
9 | 374 { |
1437 | 375 gboolean ret = FALSE; |
9 | 376 |
377 if (tval > 0) | |
378 { | |
379 struct utimbuf ut; | |
380 gchar *sl; | |
381 | |
382 ut.actime = ut.modtime = tval; | |
383 | |
384 sl = path_from_utf8(s); | |
385 ret = (utime(sl, &ut) == 0); | |
386 g_free(sl); | |
387 } | |
388 | |
389 return ret; | |
390 } | |
391 | |
1360
e6b453609ace
Introduce is_readable_file() which test if file exists, is regular and readable.
Laurent Monin <geeqie@norz.org>
parents:
1356
diff
changeset
|
392 gboolean is_readable_file(const gchar *s) |
e6b453609ace
Introduce is_readable_file() which test if file exists, is regular and readable.
Laurent Monin <geeqie@norz.org>
parents:
1356
diff
changeset
|
393 { |
e6b453609ace
Introduce is_readable_file() which test if file exists, is regular and readable.
Laurent Monin <geeqie@norz.org>
parents:
1356
diff
changeset
|
394 if (!s || !s[0] || !isfile(s)) return FALSE; |
e6b453609ace
Introduce is_readable_file() which test if file exists, is regular and readable.
Laurent Monin <geeqie@norz.org>
parents:
1356
diff
changeset
|
395 return access_file(s, R_OK); |
e6b453609ace
Introduce is_readable_file() which test if file exists, is regular and readable.
Laurent Monin <geeqie@norz.org>
parents:
1356
diff
changeset
|
396 } |
e6b453609ace
Introduce is_readable_file() which test if file exists, is regular and readable.
Laurent Monin <geeqie@norz.org>
parents:
1356
diff
changeset
|
397 |
1448 | 398 gboolean access_file(const gchar *s, gint mode) |
9 | 399 { |
400 gchar *sl; | |
401 gint ret; | |
402 | |
1356
56881d66e7c8
Slightly modify access_file() and use it to test profile files existence and read access.
Laurent Monin <geeqie@norz.org>
parents:
1307
diff
changeset
|
403 if (!s || !s[0]) return FALSE; |
9 | 404 |
405 sl = path_from_utf8(s); | |
406 ret = (access(sl, mode) == 0); | |
407 g_free(sl); | |
408 | |
409 return ret; | |
410 } | |
411 | |
1448 | 412 gboolean unlink_file(const gchar *s) |
9 | 413 { |
414 gchar *sl; | |
1448 | 415 gboolean ret; |
9 | 416 |
417 if (!s) return FALSE; | |
418 | |
419 sl = path_from_utf8(s); | |
420 ret = (unlink(sl) == 0); | |
421 g_free(sl); | |
422 | |
423 return ret; | |
424 } | |
425 | |
1448 | 426 gboolean symlink_utf8(const gchar *source, const gchar *target) |
9 | 427 { |
428 gchar *sl; | |
429 gchar *tl; | |
1448 | 430 gboolean ret; |
9 | 431 |
432 if (!source || !target) return FALSE; | |
433 | |
434 sl = path_from_utf8(source); | |
435 tl = path_from_utf8(target); | |
436 | |
437 ret = (symlink(sl, tl) == 0); | |
438 | |
439 g_free(sl); | |
440 g_free(tl); | |
441 | |
442 return ret; | |
443 } | |
444 | |
1448 | 445 gboolean mkdir_utf8(const gchar *s, gint mode) |
9 | 446 { |
447 gchar *sl; | |
1448 | 448 gboolean ret; |
9 | 449 |
450 if (!s) return FALSE; | |
451 | |
452 sl = path_from_utf8(s); | |
453 ret = (mkdir(sl, mode) == 0); | |
454 g_free(sl); | |
455 return ret; | |
456 } | |
457 | |
1448 | 458 gboolean rmdir_utf8(const gchar *s) |
9 | 459 { |
460 gchar *sl; | |
1448 | 461 gboolean ret; |
9 | 462 |
463 if (!s) return FALSE; | |
464 | |
465 sl = path_from_utf8(s); | |
466 ret = (rmdir(sl) == 0); | |
467 g_free(sl); | |
468 | |
469 return ret; | |
470 } | |
471 | |
1448 | 472 gboolean copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime) |
9 | 473 { |
474 struct stat st; | |
475 gchar *sl, *tl; | |
1437 | 476 gboolean ret = FALSE; |
9 | 477 |
478 if (!s || !t) return FALSE; | |
479 | |
480 sl = path_from_utf8(s); | |
481 tl = path_from_utf8(t); | |
482 | |
483 if (stat(sl, &st) == 0) | |
484 { | |
485 struct utimbuf tb; | |
486 | |
487 ret = TRUE; | |
488 | |
489 /* set the dest file attributes to that of source (ignoring errors) */ | |
490 | |
1870
0edb60ebe74b
Fix bug 2999830: do not report failed chown() on copy.
Vladislav Naumov <vnaum@vnaum.com>
parents:
1802
diff
changeset
|
491 if (perms) |
0edb60ebe74b
Fix bug 2999830: do not report failed chown() on copy.
Vladislav Naumov <vnaum@vnaum.com>
parents:
1802
diff
changeset
|
492 { |
0edb60ebe74b
Fix bug 2999830: do not report failed chown() on copy.
Vladislav Naumov <vnaum@vnaum.com>
parents:
1802
diff
changeset
|
493 ret = chown(tl, st.st_uid, st.st_gid); |
0edb60ebe74b
Fix bug 2999830: do not report failed chown() on copy.
Vladislav Naumov <vnaum@vnaum.com>
parents:
1802
diff
changeset
|
494 /* Ignores chown errors, while still doing chown |
0edb60ebe74b
Fix bug 2999830: do not report failed chown() on copy.
Vladislav Naumov <vnaum@vnaum.com>
parents:
1802
diff
changeset
|
495 (so root still can copy files preserving ownership) */ |
0edb60ebe74b
Fix bug 2999830: do not report failed chown() on copy.
Vladislav Naumov <vnaum@vnaum.com>
parents:
1802
diff
changeset
|
496 ret = TRUE; |
2585
007dc5135fac
Fix #506: ignore chmod errors for filesystems not supporting the operation
Alberto Griggio <>
parents:
2508
diff
changeset
|
497 if (chmod(tl, st.st_mode) < 0) { |
007dc5135fac
Fix #506: ignore chmod errors for filesystems not supporting the operation
Alberto Griggio <>
parents:
2508
diff
changeset
|
498 struct stat st2; |
007dc5135fac
Fix #506: ignore chmod errors for filesystems not supporting the operation
Alberto Griggio <>
parents:
2508
diff
changeset
|
499 if (stat(tl, &st2) != 0 || st2.st_mode != st.st_mode) { |
007dc5135fac
Fix #506: ignore chmod errors for filesystems not supporting the operation
Alberto Griggio <>
parents:
2508
diff
changeset
|
500 ret = FALSE; |
007dc5135fac
Fix #506: ignore chmod errors for filesystems not supporting the operation
Alberto Griggio <>
parents:
2508
diff
changeset
|
501 } |
007dc5135fac
Fix #506: ignore chmod errors for filesystems not supporting the operation
Alberto Griggio <>
parents:
2508
diff
changeset
|
502 } |
1870
0edb60ebe74b
Fix bug 2999830: do not report failed chown() on copy.
Vladislav Naumov <vnaum@vnaum.com>
parents:
1802
diff
changeset
|
503 } |
9 | 504 |
505 tb.actime = st.st_atime; | |
506 tb.modtime = st.st_mtime; | |
507 if (mtime && utime(tl, &tb) < 0) ret = FALSE; | |
508 } | |
509 | |
510 g_free(sl); | |
511 g_free(tl); | |
512 | |
513 return ret; | |
514 } | |
515 | |
516 /* paths are in filesystem encoding */ | |
1448 | 517 static gboolean hard_linked(const gchar *a, const gchar *b) |
9 | 518 { |
519 struct stat sta; | |
520 struct stat stb; | |
521 | |
522 if (stat(a, &sta) != 0 || stat(b, &stb) != 0) return FALSE; | |
523 | |
524 return (sta.st_dev == stb.st_dev && | |
525 sta.st_ino == stb.st_ino); | |
526 } | |
527 | |
1448 | 528 gboolean copy_file(const gchar *s, const gchar *t) |
9 | 529 { |
530 FILE *fi = NULL; | |
531 FILE *fo = NULL; | |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
532 gchar *sl = NULL; |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
533 gchar *tl = NULL; |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
534 gchar *randname = NULL; |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
535 gchar buf[16384]; |
704
5457bcc82950
Use size_t instead of gint, it silents a signed vs unsigned warning.
Laurent Monin <geeqie@norz.org>
parents:
703
diff
changeset
|
536 size_t b; |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
537 gint ret = FALSE; |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
538 gint fd = -1; |
9 | 539 |
540 sl = path_from_utf8(s); | |
541 tl = path_from_utf8(t); | |
542 | |
543 if (hard_linked(sl, tl)) | |
544 { | |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
545 ret = TRUE; |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
546 goto end; |
9 | 547 } |
548 | |
2850
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
549 /* Do not dereference absolute symlinks, but copy them "as is". |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
550 * For a relative symlink, we don't know how to properly change it when |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
551 * copied/moved to another dir to keep pointing it to same target as |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
552 * a relative symlink, so we turn it into absolute symlink using |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
553 * realpath() instead. */ |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
554 struct stat st; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
555 if (lstat_utf8(sl, &st) && S_ISLNK(st.st_mode)) |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
556 { |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
557 gchar *link_target; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
558 ssize_t i; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
559 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
560 link_target = g_malloc(st.st_size + 1); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
561 i = readlink(sl, link_target, st.st_size); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
562 if (i<0) |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
563 { |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
564 g_free(link_target); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
565 goto orig_copy; // try a "normal" copy |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
566 } |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
567 link_target[st.st_size] = '\0'; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
568 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
569 if (link_target[0] != G_DIR_SEPARATOR) // if it is a relative symlink |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
570 { |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
571 gchar *absolute; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
572 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
573 gchar *lastslash = strrchr(sl, G_DIR_SEPARATOR); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
574 gint len = lastslash - sl + 1; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
575 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
576 absolute = g_malloc(len + st.st_size + 1); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
577 strncpy(absolute, sl, len); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
578 strcpy(absolute + len, link_target); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
579 g_free(link_target); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
580 link_target = absolute; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
581 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
582 gchar *realPath; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
583 realPath = realpath(link_target, NULL); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
584 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
585 if (realPath != NULL) // successfully resolved into an absolute path |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
586 { |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
587 g_free(link_target); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
588 link_target = g_strdup(realPath); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
589 g_free(realPath); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
590 } |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
591 else // could not get absolute path, got some error instead |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
592 { |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
593 g_free(link_target); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
594 goto orig_copy; // so try a "normal" copy |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
595 } |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
596 } |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
597 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
598 if (stat_utf8(tl, &st)) unlink(tl); // first try to remove directory entry in destination directory if such entry exists |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
599 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
600 gint success = (symlink(link_target, tl) == 0); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
601 g_free(link_target); |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
602 |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
603 if (success) |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
604 { |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
605 ret = TRUE; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
606 goto end; |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
607 } |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
608 } // if symlink did not succeed, continue on to try a copy procedure |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
609 orig_copy: |
667eb6d5a0b1
Fix #544: copy symlinks as symlinks instead of dereferencing them
Wojciech Muła <>
parents:
2849
diff
changeset
|
610 |
9 | 611 fi = fopen(sl, "rb"); |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
612 if (!fi) goto end; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
613 |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
614 /* First we write to a temporary file, then we rename it on success, |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
615 and attributes from original file are copied */ |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
616 randname = g_strconcat(tl, ".tmp_XXXXXX", NULL); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
617 if (!randname) goto end; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
618 |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
619 fd = g_mkstemp(randname); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
620 if (fd == -1) goto end; |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
621 |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
622 fo = fdopen(fd, "wb"); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
623 if (!fo) { |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
624 close(fd); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
625 goto end; |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
626 } |
9 | 627 |
1000
07f6093c1c1a
For the sake of consistency, use glib basic types everywhere.
Laurent Monin <geeqie@norz.org>
parents:
998
diff
changeset
|
628 while ((b = fread(buf, sizeof(gchar), sizeof(buf), fi)) && b != 0) |
9 | 629 { |
1000
07f6093c1c1a
For the sake of consistency, use glib basic types everywhere.
Laurent Monin <geeqie@norz.org>
parents:
998
diff
changeset
|
630 if (fwrite(buf, sizeof(gchar), b, fo) != b) |
9 | 631 { |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
632 unlink(randname); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
633 goto end; |
9 | 634 } |
635 } | |
636 | |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
637 fclose(fi); fi = NULL; |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
638 fclose(fo); fo = NULL; |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
639 |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
640 if (rename(randname, tl) < 0) { |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
641 unlink(randname); |
2184 | 642 goto end; |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
643 } |
9 | 644 |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
645 ret = copy_file_attributes(s, t, TRUE, TRUE); |
9 | 646 |
1788
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
647 end: |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
648 if (fi) fclose(fi); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
649 if (fo) fclose(fo); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
650 if (sl) g_free(sl); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
651 if (tl) g_free(tl); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
652 if (randname) g_free(randname); |
3de6039e8bb8
copy_file(): remove incomplete file on error (bug 2890715)
Laurent Monin <geeqie@norz.org>
parents:
1719
diff
changeset
|
653 return ret; |
9 | 654 } |
655 | |
1448 | 656 gboolean move_file(const gchar *s, const gchar *t) |
9 | 657 { |
658 gchar *sl, *tl; | |
1437 | 659 gboolean ret = TRUE; |
9 | 660 |
661 if (!s || !t) return FALSE; | |
662 | |
663 sl = path_from_utf8(s); | |
664 tl = path_from_utf8(t); | |
665 if (rename(sl, tl) < 0) | |
666 { | |
667 /* this may have failed because moving a file across filesystems | |
668 was attempted, so try copy and delete instead */ | |
669 if (copy_file(s, t)) | |
670 { | |
671 if (unlink(sl) < 0) | |
672 { | |
673 /* err, now we can't delete the source file so return FALSE */ | |
674 ret = FALSE; | |
675 } | |
676 } | |
677 else | |
678 { | |
679 ret = FALSE; | |
680 } | |
681 } | |
682 g_free(sl); | |
683 g_free(tl); | |
684 | |
685 return ret; | |
686 } | |
687 | |
1448 | 688 gboolean rename_file(const gchar *s, const gchar *t) |
9 | 689 { |
690 gchar *sl, *tl; | |
1448 | 691 gboolean ret; |
9 | 692 |
693 if (!s || !t) return FALSE; | |
694 | |
695 sl = path_from_utf8(s); | |
696 tl = path_from_utf8(t); | |
697 ret = (rename(sl, tl) == 0); | |
698 g_free(sl); | |
699 g_free(tl); | |
700 | |
701 return ret; | |
702 } | |
703 | |
704 gchar *get_current_dir(void) | |
705 { | |
706 gchar *pathl; | |
707 gchar *path8; | |
708 | |
709 pathl = g_get_current_dir(); | |
710 path8 = path_to_utf8(pathl); | |
711 g_free(pathl); | |
712 | |
713 return path8; | |
714 } | |
715 | |
576
47680a5f898a
dropped path_list functions, use filelist functions everywhere
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
545
diff
changeset
|
716 void string_list_free(GList *list) |
9 | 717 { |
718 g_list_foreach(list, (GFunc)g_free, NULL); | |
719 g_list_free(list); | |
720 } | |
721 | |
1238
47e6d7aac05b
simplified metadata interface, dropped metadata_read,
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1229
diff
changeset
|
722 GList *string_list_copy(const GList *list) |
9 | 723 { |
724 GList *new_list = NULL; | |
1249
728030a71f1e
Silent two compilation warnings.
Laurent Monin <geeqie@norz.org>
parents:
1238
diff
changeset
|
725 GList *work = (GList *) list; |
9 | 726 |
727 while (work) | |
728 { | |
729 gchar *path; | |
442 | 730 |
9 | 731 path = work->data; |
732 work = work->next; | |
442 | 733 |
9 | 734 new_list = g_list_prepend(new_list, g_strdup(path)); |
735 } | |
442 | 736 |
9 | 737 return g_list_reverse(new_list); |
738 } | |
739 | |
1448 | 740 gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gboolean pad) |
9 | 741 { |
742 gchar *unique; | |
743 gint n = 1; | |
744 | |
745 if (!ext) ext = ""; | |
746 if (!divider) divider = ""; | |
747 | |
748 unique = g_strconcat(path, ext, NULL); | |
749 while (isname(unique)) | |
750 { | |
751 g_free(unique); | |
752 if (pad) | |
753 { | |
754 unique = g_strdup_printf("%s%s%03d%s", path, divider, n, ext); | |
755 } | |
756 else | |
757 { | |
758 unique = g_strdup_printf("%s%s%d%s", path, divider, n, ext); | |
759 } | |
760 n++; | |
761 if (n > 999) | |
762 { | |
763 /* well, we tried */ | |
764 g_free(unique); | |
765 return NULL; | |
766 } | |
767 } | |
768 | |
769 return unique; | |
770 } | |
771 | |
772 gchar *unique_filename_simple(const gchar *path) | |
773 { | |
774 gchar *unique; | |
775 const gchar *name; | |
776 const gchar *ext; | |
777 | |
778 if (!path) return NULL; | |
779 | |
780 name = filename_from_path(path); | |
781 if (!name) return NULL; | |
782 | |
2454
93d1c77a312b
Fix #147: Alternative format for sidecar extension
Tomasz Golinski <tomaszg@math.uwb.edu.pl>
parents:
2350
diff
changeset
|
783 ext = registered_extension_from_path(name); |
9 | 784 |
785 if (!ext) | |
786 { | |
787 unique = unique_filename(path, NULL, "_", TRUE); | |
788 } | |
789 else | |
790 { | |
791 gchar *base; | |
792 | |
793 base = remove_extension_from_path(path); | |
794 unique = unique_filename(base, ext, "_", TRUE); | |
795 g_free(base); | |
796 } | |
797 | |
798 return unique; | |
799 } | |
800 | |
801 const gchar *filename_from_path(const gchar *path) | |
802 { | |
803 const gchar *base; | |
804 | |
805 if (!path) return NULL; | |
806 | |
701
4dffa2e001a1
Use G_DIR_SEPARATOR instead of '/' where applicable.
Laurent Monin <geeqie@norz.org>
parents:
673
diff
changeset
|
807 base = strrchr(path, G_DIR_SEPARATOR); |
9 | 808 if (base) return base + 1; |
809 | |
810 return path; | |
811 } | |
812 | |
813 gchar *remove_level_from_path(const gchar *path) | |
814 { | |
2454
93d1c77a312b
Fix #147: Alternative format for sidecar extension
Tomasz Golinski <tomaszg@math.uwb.edu.pl>
parents:
2350
diff
changeset
|
815 const gchar *base; |
9 | 816 |
2787
3ff45da4e250
Addl fix #147: Darktable XMP Sidecar Files not grouped
Colin Clark <colin.clark@cclark.uk>
parents:
2783
diff
changeset
|
817 if (!path) return g_strdup(""); |
9 | 818 |
2454
93d1c77a312b
Fix #147: Alternative format for sidecar extension
Tomasz Golinski <tomaszg@math.uwb.edu.pl>
parents:
2350
diff
changeset
|
819 base = strrchr(path, G_DIR_SEPARATOR); |
2634
8cdd84a6a8e9
Fix #527: source directory is not writable
Colin Clark <colin.clark@cclark.uk>
parents:
2621
diff
changeset
|
820 /* Take account of a file being in the root ( / ) folder - ensure the returned value |
8cdd84a6a8e9
Fix #527: source directory is not writable
Colin Clark <colin.clark@cclark.uk>
parents:
2621
diff
changeset
|
821 * is at least one character long */ |
8cdd84a6a8e9
Fix #527: source directory is not writable
Colin Clark <colin.clark@cclark.uk>
parents:
2621
diff
changeset
|
822 if (base) return g_strndup(path, (strlen(path)-strlen(base)) == 0 ? 1 : (strlen(path)-strlen(base))); |
543
ee87db015aa5
remove_level_from_path() was simplified.
Laurent Monin <geeqie@norz.org>
parents:
516
diff
changeset
|
823 |
2787
3ff45da4e250
Addl fix #147: Darktable XMP Sidecar Files not grouped
Colin Clark <colin.clark@cclark.uk>
parents:
2783
diff
changeset
|
824 return g_strdup(""); |
9 | 825 } |
826 | |
1448 | 827 gboolean file_extension_match(const gchar *path, const gchar *ext) |
9 | 828 { |
829 gint p; | |
830 gint e; | |
831 | |
832 if (!path) return FALSE; | |
833 if (!ext) return TRUE; | |
834 | |
835 p = strlen(path); | |
836 e = strlen(ext); | |
837 | |
605
d071d4830586
Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
Laurent Monin <geeqie@norz.org>
parents:
576
diff
changeset
|
838 /* FIXME: utf8 */ |
1307 | 839 return (p > e && g_ascii_strncasecmp(path + p - e, ext, e) == 0); |
9 | 840 } |
841 | |
842 gchar *remove_extension_from_path(const gchar *path) | |
843 { | |
2459
81ba6aa8467c
Bug fix: Seg fault in copy/move dialog
Colin Clark <cclark@mcb.net>
parents:
2454
diff
changeset
|
844 const gchar *reg_ext; |
81ba6aa8467c
Bug fix: Seg fault in copy/move dialog
Colin Clark <cclark@mcb.net>
parents:
2454
diff
changeset
|
845 |
9 | 846 if (!path) return NULL; |
2459
81ba6aa8467c
Bug fix: Seg fault in copy/move dialog
Colin Clark <cclark@mcb.net>
parents:
2454
diff
changeset
|
847 |
81ba6aa8467c
Bug fix: Seg fault in copy/move dialog
Colin Clark <cclark@mcb.net>
parents:
2454
diff
changeset
|
848 reg_ext = registered_extension_from_path(path); |
81ba6aa8467c
Bug fix: Seg fault in copy/move dialog
Colin Clark <cclark@mcb.net>
parents:
2454
diff
changeset
|
849 |
81ba6aa8467c
Bug fix: Seg fault in copy/move dialog
Colin Clark <cclark@mcb.net>
parents:
2454
diff
changeset
|
850 return g_strndup(path, strlen(path) - (reg_ext == NULL ? 0 : strlen(reg_ext))); |
9 | 851 } |
852 | |
853 void parse_out_relatives(gchar *path) | |
854 { | |
855 gint s, t; | |
856 | |
857 if (!path) return; | |
858 | |
859 s = t = 0; | |
860 | |
861 while (path[s] != '\0') | |
862 { | |
919
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
863 if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.') |
9 | 864 { |
919
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
865 /* /. occurence, let's see more */ |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
866 gint p = s + 2; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
867 |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
868 if (path[p] == G_DIR_SEPARATOR || path[p] == '\0') |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
869 { |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
870 /* /./ or /., just skip this part */ |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
871 s = p; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
872 continue; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
873 } |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
874 else if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0')) |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
875 { |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
876 /* /../ or /.., remove previous part, ie. /a/b/../ becomes /a/ */ |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
877 s = p + 1; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
878 if (t > 0) t--; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
879 while (path[t] != G_DIR_SEPARATOR && t > 0) t--; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
880 continue; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
881 } |
9 | 882 } |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
883 |
919
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
884 if (s != t) path[t] = path[s]; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
885 t++; |
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
886 s++; |
9 | 887 } |
919
27043b8dabcc
Simplify parse_out_relatives().
Laurent Monin <geeqie@norz.org>
parents:
759
diff
changeset
|
888 |
701
4dffa2e001a1
Use G_DIR_SEPARATOR instead of '/' where applicable.
Laurent Monin <geeqie@norz.org>
parents:
673
diff
changeset
|
889 if (t == 0 && path[t] == G_DIR_SEPARATOR) t++; |
4dffa2e001a1
Use G_DIR_SEPARATOR instead of '/' where applicable.
Laurent Monin <geeqie@norz.org>
parents:
673
diff
changeset
|
890 if (t > 1 && path[t-1] == G_DIR_SEPARATOR) t--; |
9 | 891 path[t] = '\0'; |
892 } | |
893 | |
1448 | 894 gboolean file_in_path(const gchar *name) |
9 | 895 { |
896 gchar *path; | |
897 gchar *namel; | |
898 gint p, l; | |
1437 | 899 gboolean ret = FALSE; |
9 | 900 |
901 if (!name) return FALSE; | |
902 path = g_strdup(getenv("PATH")); | |
903 if (!path) return FALSE; | |
904 namel = path_from_utf8(name); | |
905 | |
906 p = 0; | |
907 l = strlen(path); | |
908 while (p < l && !ret) | |
909 { | |
910 gchar *f; | |
911 gint e = p; | |
912 while (path[e] != ':' && path[e] != '\0') e++; | |
913 path[e] = '\0'; | |
914 e++; | |
703
993248781d1a
Use g_build_filename() instead of g_strconcat().
Laurent Monin <geeqie@norz.org>
parents:
702
diff
changeset
|
915 f = g_build_filename(path + p, namel, NULL); |
9 | 916 if (isfile(f)) ret = TRUE; |
917 g_free(f); | |
918 p = e; | |
919 } | |
920 g_free(namel); | |
921 g_free(path); | |
922 | |
923 return ret; | |
924 } | |
1148
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
925 |
1164 | 926 gboolean recursive_mkdir_if_not_exists(const gchar *path, mode_t mode) |
1148
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
927 { |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
928 if (!path) return FALSE; |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
929 |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
930 if (!isdir(path)) |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
931 { |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
932 gchar *npath = g_strdup(path); |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
933 gchar *p = npath; |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
934 |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
935 while (p[0] != '\0') |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
936 { |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
937 p++; |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
938 if (p[0] == G_DIR_SEPARATOR || p[0] == '\0') |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
939 { |
1437 | 940 gboolean end = TRUE; |
1148
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
941 |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
942 if (p[0] != '\0') |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
943 { |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
944 p[0] = '\0'; |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
945 end = FALSE; |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
946 } |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
947 |
1148
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
948 if (!isdir(npath)) |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
949 { |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
950 DEBUG_1("creating sub dir:%s", npath); |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
951 if (!mkdir_utf8(npath, mode)) |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
952 { |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
953 log_printf("create dir failed: %s\n", npath); |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
954 g_free(npath); |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
955 return FALSE; |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
956 } |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
957 } |
2185
c14a1d8e6aa4
Trim trailing white spaces on empty lines.
Laurent Monin <zas@norz.org>
parents:
2184
diff
changeset
|
958 |
1148
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
959 if (!end) p[0] = G_DIR_SEPARATOR; |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
960 } |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
961 } |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
962 g_free(npath); |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
963 } |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
964 |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
965 return TRUE; |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
966 } |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
967 |
1642
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
968 /* does filename utf8 to filesystem encoding first */ |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
969 gboolean md5_get_digest_from_file_utf8(const gchar *path, guchar digest[16]) |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
970 { |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
971 gboolean success; |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
972 gchar *pathl; |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
973 |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
974 pathl = path_from_utf8(path); |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
975 success = md5_get_digest_from_file(pathl, digest); |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
976 g_free(pathl); |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
977 |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
978 return success; |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
979 } |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
980 |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
981 |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
982 gchar *md5_text_from_file_utf8(const gchar *path, const gchar *error_text) |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
983 { |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
984 guchar digest[16]; |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
985 |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
986 if (!md5_get_digest_from_file_utf8(path, digest)) return g_strdup(error_text); |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
987 |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
988 return md5_digest_to_text(digest); |
1e6188ed7a68
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
Laurent Monin <geeqie@norz.org>
parents:
1555
diff
changeset
|
989 } |
1148
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
990 |
db3cdb2b9681
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
Laurent Monin <geeqie@norz.org>
parents:
1145
diff
changeset
|
991 |
1055
4bbdfab3c89a
Adding a vim modeline to all files - patch by Klaus Ethgen
Vladimir Nadvornik <nadvornik@suse.cz>
parents:
1000
diff
changeset
|
992 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |