Mercurial > geeqie.yaz
annotate src/filedata.c @ 1753:c4d37e0fc841 default tip
installation fix
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 29 Jan 2010 19:22:50 +0900 |
parents | 219a5dd783ed |
children |
rev | line source |
---|---|
586 | 1 /* |
2 * Geeqie | |
3 * (C) 2006 John Ellis | |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
586 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
14 #include "main.h" | |
15 #include "filedata.h" | |
16 | |
17 #include "filefilter.h" | |
18 #include "cache.h" | |
19 #include "thumb_standard.h" | |
20 #include "ui_fileops.h" | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
21 #include "metadata.h" |
1212 | 22 #include "trash.h" |
1439 | 23 #include "histogram.h" |
586 | 24 |
1746
219a5dd783ed
Log a message when EOVERFLOW error is set by stat() when building files lists. See bug 2876142.
zas_
parents:
1742
diff
changeset
|
25 #include <errno.h> |
586 | 26 |
785 | 27 static GHashTable *file_data_pool = NULL; |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
28 static GHashTable *file_data_planned_change_hash = NULL; |
785 | 29 |
586 | 30 static gint sidecar_file_priority(const gchar *path); |
1708 | 31 static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean check_sidecars, GHashTable *basename_hash); |
586 | 32 |
33 | |
34 /* | |
35 *----------------------------------------------------------------------------- | |
36 * text conversion utils | |
37 *----------------------------------------------------------------------------- | |
38 */ | |
39 | |
40 gchar *text_from_size(gint64 size) | |
41 { | |
42 gchar *a, *b; | |
43 gchar *s, *d; | |
44 gint l, n, i; | |
45 | |
46 /* what I would like to use is printf("%'d", size) | |
47 * BUT: not supported on every libc :( | |
48 */ | |
49 if (size > G_MAXUINT) | |
50 { | |
51 /* the %lld conversion is not valid in all libcs, so use a simple work-around */ | |
52 a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000)); | |
53 } | |
54 else | |
55 { | |
56 a = g_strdup_printf("%d", (guint)size); | |
57 } | |
58 l = strlen(a); | |
59 n = (l - 1)/ 3; | |
60 if (n < 1) return a; | |
61 | |
62 b = g_new(gchar, l + n + 1); | |
63 | |
64 s = a; | |
65 d = b; | |
66 i = l - n * 3; | |
67 while (*s != '\0') | |
68 { | |
69 if (i < 1) | |
70 { | |
71 i = 3; | |
72 *d = ','; | |
73 d++; | |
74 } | |
75 | |
76 *d = *s; | |
77 s++; | |
78 d++; | |
79 i--; | |
80 } | |
81 *d = '\0'; | |
82 | |
83 g_free(a); | |
84 return b; | |
85 } | |
86 | |
87 gchar *text_from_size_abrev(gint64 size) | |
88 { | |
89 if (size < (gint64)1024) | |
90 { | |
91 return g_strdup_printf(_("%d bytes"), (gint)size); | |
92 } | |
93 if (size < (gint64)1048576) | |
94 { | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
95 return g_strdup_printf(_("%.1f K"), (gdouble)size / 1024.0); |
586 | 96 } |
97 if (size < (gint64)1073741824) | |
98 { | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
99 return g_strdup_printf(_("%.1f MB"), (gdouble)size / 1048576.0); |
586 | 100 } |
101 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
102 /* to avoid overflowing the gdouble, do division in two steps */ |
586 | 103 size /= 1048576; |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
104 return g_strdup_printf(_("%.1f GB"), (gdouble)size / 1024.0); |
586 | 105 } |
106 | |
107 /* note: returned string is valid until next call to text_from_time() */ | |
108 const gchar *text_from_time(time_t t) | |
109 { | |
110 static gchar *ret = NULL; | |
111 gchar buf[128]; | |
112 gint buflen; | |
113 struct tm *btime; | |
114 GError *error = NULL; | |
115 | |
116 btime = localtime(&t); | |
117 | |
118 /* the %x warning about 2 digit years is not an error */ | |
119 buflen = strftime(buf, sizeof(buf), "%x %H:%M", btime); | |
120 if (buflen < 1) return ""; | |
121 | |
122 g_free(ret); | |
123 ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error); | |
124 if (error) | |
125 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
126 log_printf("Error converting locale strftime to UTF-8: %s\n", error->message); |
586 | 127 g_error_free(error); |
128 return ""; | |
129 } | |
130 | |
131 return ret; | |
132 } | |
133 | |
134 /* | |
135 *----------------------------------------------------------------------------- | |
136 * file info struct | |
137 *----------------------------------------------------------------------------- | |
138 */ | |
139 | |
140 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source); | |
1708 | 141 static void file_data_check_sidecars(FileData *fd, GHashTable *basename_hash); |
586 | 142 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd); |
143 | |
144 | |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
145 void file_data_increment_version(FileData *fd) |
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
146 { |
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
147 fd->version++; |
1227 | 148 fd->valid_marks = 0; |
149 if (fd->parent) | |
150 { | |
151 fd->parent->version++; | |
152 fd->parent->valid_marks = 0; | |
153 } | |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
154 } |
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
155 |
1701 | 156 static gint file_data_sort_by_ext(gconstpointer a, gconstpointer b) |
157 { | |
158 const FileData *fda = a; | |
159 const FileData *fdb = b; | |
160 | |
161 return strcmp(fdb->extension, fda->extension); | |
162 } | |
163 | |
1708 | 164 static GHashTable *file_data_basename_hash_new(void) |
165 { | |
166 return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
167 } | |
168 | |
169 static void file_data_basename_hash_insert(GHashTable *basename_hash, FileData *fd) | |
1518 | 170 { |
171 GList *list; | |
172 const gchar *ext = extension_from_path(fd->path); | |
173 gchar *basename = ext ? g_strndup(fd->path, ext - fd->path) : g_strdup(fd->path); | |
1708 | 174 |
175 list = g_hash_table_lookup(basename_hash, basename); | |
1518 | 176 |
177 if (!g_list_find(list, fd)) | |
178 { | |
1708 | 179 list = g_list_insert_sorted(list, file_data_ref(fd), file_data_sort_by_ext); |
180 g_hash_table_insert(basename_hash, basename, list); | |
1518 | 181 } |
182 else | |
183 { | |
184 g_free(basename); | |
185 } | |
186 } | |
187 | |
1722 | 188 #if 0 |
1708 | 189 static void file_data_basename_hash_remove(GHashTable *basename_hash, FileData *fd) |
1518 | 190 { |
191 GList *list; | |
192 const gchar *ext = extension_from_path(fd->path); | |
193 gchar *basename = ext ? g_strndup(fd->path, ext - fd->path) : g_strdup(fd->path); | |
194 | |
1708 | 195 list = g_hash_table_lookup(basename_hash, basename); |
196 | |
197 if (!g_list_find(list, fd)) return; | |
1518 | 198 |
199 list = g_list_remove(list, fd); | |
1708 | 200 file_data_unref(fd); |
1518 | 201 |
202 if (list) | |
203 { | |
1708 | 204 g_hash_table_insert(basename_hash, basename, list); |
1518 | 205 } |
206 else | |
207 { | |
1708 | 208 g_hash_table_remove(basename_hash, basename); |
1518 | 209 g_free(basename); |
210 } | |
211 } | |
1722 | 212 #endif |
1518 | 213 |
1708 | 214 static void file_data_basename_hash_remove_list(gpointer key, gpointer value, gpointer data) |
215 { | |
216 filelist_free((GList *)value); | |
217 } | |
218 | |
219 static void file_data_basename_hash_free(GHashTable *basename_hash) | |
220 { | |
221 g_hash_table_foreach(basename_hash, file_data_basename_hash_remove_list, NULL); | |
222 g_hash_table_destroy(basename_hash); | |
223 } | |
224 | |
785 | 225 static void file_data_set_collate_keys(FileData *fd) |
226 { | |
227 gchar *caseless_name; | |
1007
4303ee1e88ec
Removed converting fd->name to utf8 from file_data_set_collate_keys(), because fd->name is utf8.
bruclik
parents:
1002
diff
changeset
|
228 |
4303ee1e88ec
Removed converting fd->name to utf8 from file_data_set_collate_keys(), because fd->name is utf8.
bruclik
parents:
1002
diff
changeset
|
229 caseless_name = g_utf8_casefold(fd->name, -1); |
785 | 230 |
231 g_free(fd->collate_key_name); | |
232 g_free(fd->collate_key_name_nocase); | |
233 | |
1742 | 234 #if 0 && GLIB_CHECK_VERSION(2, 8, 0) |
1007
4303ee1e88ec
Removed converting fd->name to utf8 from file_data_set_collate_keys(), because fd->name is utf8.
bruclik
parents:
1002
diff
changeset
|
235 fd->collate_key_name = g_utf8_collate_key_for_filename(fd->name, -1); |
785 | 236 fd->collate_key_name_nocase = g_utf8_collate_key_for_filename(caseless_name, -1); |
237 #else | |
1007
4303ee1e88ec
Removed converting fd->name to utf8 from file_data_set_collate_keys(), because fd->name is utf8.
bruclik
parents:
1002
diff
changeset
|
238 fd->collate_key_name = g_utf8_collate_key(fd->name, -1); |
785 | 239 fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1); |
240 #endif | |
241 g_free(caseless_name); | |
242 } | |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
243 |
1722 | 244 static void file_data_set_path(FileData *fd, const gchar *path) |
586 | 245 { |
790 | 246 g_assert(path /* && *path*/); /* view_dir_tree uses FileData with zero length path */ |
785 | 247 g_assert(file_data_pool); |
248 | |
249 g_free(fd->path); | |
250 | |
251 if (fd->original_path) | |
252 { | |
253 g_hash_table_remove(file_data_pool, fd->original_path); | |
254 g_free(fd->original_path); | |
255 } | |
915 | 256 |
257 g_assert(!g_hash_table_lookup(file_data_pool, path)); | |
258 | |
785 | 259 fd->original_path = g_strdup(path); |
260 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
586 | 261 |
725 | 262 if (strcmp(path, G_DIR_SEPARATOR_S) == 0) |
586 | 263 { |
264 fd->path = g_strdup(path); | |
265 fd->name = fd->path; | |
266 fd->extension = fd->name + 1; | |
785 | 267 file_data_set_collate_keys(fd); |
586 | 268 return; |
269 } | |
270 | |
271 fd->path = g_strdup(path); | |
272 fd->name = filename_from_path(fd->path); | |
273 | |
274 if (strcmp(fd->name, "..") == 0) | |
275 { | |
276 gchar *dir = remove_level_from_path(path); | |
277 g_free(fd->path); | |
278 fd->path = remove_level_from_path(dir); | |
279 g_free(dir); | |
280 fd->name = ".."; | |
281 fd->extension = fd->name + 2; | |
785 | 282 file_data_set_collate_keys(fd); |
586 | 283 return; |
284 } | |
285 else if (strcmp(fd->name, ".") == 0) | |
286 { | |
287 g_free(fd->path); | |
288 fd->path = remove_level_from_path(path); | |
289 fd->name = "."; | |
290 fd->extension = fd->name + 1; | |
785 | 291 file_data_set_collate_keys(fd); |
586 | 292 return; |
293 } | |
294 | |
295 fd->extension = extension_from_path(fd->path); | |
296 if (fd->extension == NULL) | |
1422 | 297 { |
586 | 298 fd->extension = fd->name + strlen(fd->name); |
1422 | 299 } |
785 | 300 |
301 file_data_set_collate_keys(fd); | |
586 | 302 } |
303 | |
801 | 304 static gboolean file_data_check_changed_files_recursive(FileData *fd, struct stat *st) |
586 | 305 { |
801 | 306 gboolean ret = FALSE; |
586 | 307 GList *work; |
806 | 308 |
586 | 309 if (fd->size != st->st_size || |
310 fd->date != st->st_mtime) | |
311 { | |
312 fd->size = st->st_size; | |
313 fd->date = st->st_mtime; | |
945
fd84847c8231
speed-up of directory notification on deleting large number of files
nadvornik
parents:
942
diff
changeset
|
314 fd->mode = st->st_mode; |
845 | 315 if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf); |
316 fd->thumb_pixbuf = NULL; | |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
317 file_data_increment_version(fd); |
1432 | 318 file_data_send_notification(fd, NOTIFY_REREAD); |
801 | 319 ret = TRUE; |
586 | 320 } |
321 | |
322 work = fd->sidecar_files; | |
323 while (work) | |
324 { | |
325 FileData *sfd = work->data; | |
326 struct stat st; | |
801 | 327 work = work->next; |
586 | 328 |
329 if (!stat_utf8(sfd->path, &st)) | |
330 { | |
801 | 331 fd->size = 0; |
332 fd->date = 0; | |
586 | 333 file_data_disconnect_sidecar_file(fd, sfd); |
801 | 334 ret = TRUE; |
335 continue; | |
586 | 336 } |
337 | |
801 | 338 ret |= file_data_check_changed_files_recursive(sfd, &st); |
586 | 339 } |
801 | 340 return ret; |
341 } | |
342 | |
343 | |
888 | 344 gboolean file_data_check_changed_files(FileData *fd) |
801 | 345 { |
346 gboolean ret = FALSE; | |
347 struct stat st; | |
806 | 348 |
801 | 349 if (fd->parent) fd = fd->parent; |
350 | |
351 if (!stat_utf8(fd->path, &st)) | |
352 { | |
1722 | 353 GList *sidecars; |
806 | 354 GList *work; |
355 FileData *sfd = NULL; | |
356 | |
801 | 357 /* parent is missing, we have to rebuild whole group */ |
358 ret = TRUE; | |
359 fd->size = 0; | |
360 fd->date = 0; | |
806 | 361 |
1722 | 362 /* file_data_disconnect_sidecar_file might delete the file, |
363 we have to keep the reference to prevent this */ | |
364 sidecars = filelist_copy(fd->sidecar_files); | |
365 work = sidecars; | |
801 | 366 while (work) |
367 { | |
368 sfd = work->data; | |
369 work = work->next; | |
370 | |
371 file_data_disconnect_sidecar_file(fd, sfd); | |
372 } | |
1713 | 373 if (sfd) file_data_check_sidecars(sfd, NULL); /* this will group the sidecars back together */ |
1722 | 374 /* now we can release the sidecars */ |
375 filelist_free(sidecars); | |
1432 | 376 file_data_send_notification(fd, NOTIFY_REREAD); |
801 | 377 } |
806 | 378 else |
379 { | |
801 | 380 ret |= file_data_check_changed_files_recursive(fd, &st); |
806 | 381 } |
382 | |
801 | 383 return ret; |
586 | 384 } |
385 | |
1708 | 386 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean check_sidecars, GHashTable *basename_hash) |
586 | 387 { |
388 FileData *fd; | |
389 | |
1708 | 390 DEBUG_2("file_data_new: '%s' %d %d", path_utf8, check_sidecars, !!basename_hash); |
586 | 391 |
392 if (!file_data_pool) | |
393 file_data_pool = g_hash_table_new(g_str_hash, g_str_equal); | |
394 | |
918 | 395 fd = g_hash_table_lookup(file_data_pool, path_utf8); |
396 if (fd) | |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
397 { |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
398 file_data_ref(fd); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
399 } |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
400 |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
401 if (!fd && file_data_planned_change_hash) |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
402 { |
918 | 403 fd = g_hash_table_lookup(file_data_planned_change_hash, path_utf8); |
404 if (fd) | |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
405 { |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
406 DEBUG_1("planned change: using %s -> %s", path_utf8, fd->path); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
407 file_data_ref(fd); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
408 file_data_apply_ci(fd); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
409 } |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
410 } |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
411 |
586 | 412 if (fd) |
413 { | |
801 | 414 gboolean changed; |
1722 | 415 if (basename_hash) |
416 { | |
417 file_data_basename_hash_insert(basename_hash, fd); | |
418 if (check_sidecars) | |
419 file_data_check_sidecars(fd, basename_hash); | |
420 } | |
892
2022112583d0
increase reference count before sending notification in file_data_new
nadvornik
parents:
888
diff
changeset
|
421 |
801 | 422 if (fd->parent) |
423 changed = file_data_check_changed_files(fd); | |
424 else | |
425 changed = file_data_check_changed_files_recursive(fd, st); | |
426 if (changed && check_sidecars && sidecar_file_priority(fd->extension)) | |
1708 | 427 file_data_check_sidecars(fd, basename_hash); |
801 | 428 DEBUG_2("file_data_pool hit: '%s' %s", fd->path, changed ? "(changed)" : ""); |
806 | 429 |
892
2022112583d0
increase reference count before sending notification in file_data_new
nadvornik
parents:
888
diff
changeset
|
430 return fd; |
586 | 431 } |
432 | |
433 fd = g_new0(FileData, 1); | |
785 | 434 |
586 | 435 fd->size = st->st_size; |
436 fd->date = st->st_mtime; | |
945
fd84847c8231
speed-up of directory notification on deleting large number of files
nadvornik
parents:
942
diff
changeset
|
437 fd->mode = st->st_mode; |
586 | 438 fd->ref = 1; |
439 fd->magick = 0x12345678; | |
440 | |
1722 | 441 file_data_set_path(fd, path_utf8); /* set path, name, collate_key_*, original_path */ |
442 if (basename_hash) file_data_basename_hash_insert(basename_hash, fd); | |
586 | 443 |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
444 if (check_sidecars) |
1708 | 445 file_data_check_sidecars(fd, basename_hash); |
785 | 446 |
586 | 447 return fd; |
448 } | |
449 | |
1701 | 450 /* extension must contain only ASCII characters */ |
451 static GList *check_case_insensitive_ext(gchar *path) | |
452 { | |
453 gchar *sl; | |
454 gchar *extl; | |
455 gint ext_len; | |
456 GList *list = NULL; | |
457 | |
458 sl = path_from_utf8(path); | |
1713 | 459 |
1701 | 460 extl = strrchr(sl, '.'); |
461 if (extl) | |
462 { | |
463 gint i, j; | |
464 extl++; /* the first char after . */ | |
465 ext_len = strlen(extl); | |
466 | |
467 for (i = 0; i < (1 << ext_len); i++) | |
468 { | |
469 struct stat st; | |
1713 | 470 gboolean skip = FALSE; |
1701 | 471 for (j = 0; j < ext_len; j++) |
472 { | |
473 if (i & (1 << (ext_len - 1 - j))) | |
1713 | 474 { |
1701 | 475 extl[j] = g_ascii_tolower(extl[j]); |
1713 | 476 /* make sure the result does not contain duplicates */ |
477 if (extl[j] == g_ascii_toupper(extl[j])) | |
478 { | |
479 /* no change, probably a number, we have already tested this combination */ | |
480 skip = TRUE; | |
481 break; | |
482 } | |
483 } | |
1701 | 484 else |
485 extl[j] = g_ascii_toupper(extl[j]); | |
486 } | |
1713 | 487 if (skip) continue; |
488 | |
1701 | 489 if (stat(sl, &st) == 0) |
490 { | |
491 list = g_list_prepend(list, file_data_new_local(sl, &st, FALSE, FALSE)); | |
492 } | |
493 } | |
494 } | |
495 g_free(sl); | |
496 | |
497 return list; | |
498 } | |
499 | |
1708 | 500 static void file_data_check_sidecars(FileData *fd, GHashTable *basename_hash) |
586 | 501 { |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
502 gint base_len; |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
503 GString *fname; |
586 | 504 FileData *parent_fd = NULL; |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
505 GList *work; |
1701 | 506 const GList *basename_list = NULL; |
507 GList *group_list = NULL; | |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
508 if (fd->disable_grouping || !sidecar_file_priority(fd->extension)) |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
509 return; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
510 |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
511 base_len = fd->extension - fd->path; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
512 fname = g_string_new_len(fd->path, base_len); |
1518 | 513 |
1708 | 514 if (basename_hash) |
1518 | 515 { |
1708 | 516 basename_list = g_hash_table_lookup(basename_hash, fname->str); |
1518 | 517 } |
518 | |
1701 | 519 |
520 /* check for possible sidecar files; | |
521 the sidecar files created here are referenced only via fd->sidecar_files or fd->parent, | |
522 they have fd->ref set to 0 and file_data unref must chack and free them all together | |
523 (using fd->ref would cause loops and leaks) | |
524 */ | |
525 | |
526 /* find all possible sidecar files and order them according to sidecar_ext_get_list, | |
527 for case-only differences put lowercase first, | |
528 put the result to group_list | |
529 */ | |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
530 work = sidecar_ext_get_list(); |
586 | 531 while (work) |
532 { | |
806 | 533 gchar *ext = work->data; |
586 | 534 work = work->next; |
535 | |
1708 | 536 if (!basename_hash) |
586 | 537 { |
1701 | 538 GList *new_list; |
539 g_string_truncate(fname, base_len); | |
540 g_string_append(fname, ext); | |
541 new_list = check_case_insensitive_ext(fname->str); | |
542 group_list = g_list_concat(group_list, new_list); | |
586 | 543 } |
544 else | |
545 { | |
1701 | 546 const GList *work2 = basename_list; |
547 | |
548 while (work2) | |
1518 | 549 { |
1701 | 550 FileData *sfd = work2->data; |
1518 | 551 |
1708 | 552 if (g_ascii_strcasecmp(ext, sfd->extension) == 0) |
1518 | 553 { |
1701 | 554 group_list = g_list_append(group_list, file_data_ref(sfd)); |
1518 | 555 } |
1701 | 556 work2 = work2->next; |
1518 | 557 } |
586 | 558 } |
1701 | 559 } |
560 g_string_free(fname, TRUE); | |
561 | |
562 /* process the group list - the first one is the parent file, others are sidecars */ | |
563 work = group_list; | |
564 while (work) | |
565 { | |
566 FileData *new_fd = work->data; | |
567 work = work->next; | |
568 | |
569 if (new_fd->disable_grouping) | |
570 { | |
571 file_data_unref(new_fd); | |
572 continue; | |
573 } | |
574 | |
575 new_fd->ref--; /* do not use ref here */ | |
586 | 576 |
577 if (!parent_fd) | |
578 parent_fd = new_fd; /* parent is the one with the highest prio, found first */ | |
579 else | |
580 file_data_merge_sidecar_files(parent_fd, new_fd); | |
581 } | |
1701 | 582 g_list_free(group_list); |
586 | 583 } |
584 | |
585 | |
1708 | 586 static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean check_sidecars, GHashTable *basename_hash) |
586 | 587 { |
588 gchar *path_utf8 = path_to_utf8(path); | |
1708 | 589 FileData *ret = file_data_new(path_utf8, st, check_sidecars, basename_hash); |
806 | 590 |
586 | 591 g_free(path_utf8); |
592 return ret; | |
593 } | |
594 | |
595 FileData *file_data_new_simple(const gchar *path_utf8) | |
596 { | |
597 struct stat st; | |
598 | |
599 if (!stat_utf8(path_utf8, &st)) | |
600 { | |
601 st.st_size = 0; | |
602 st.st_mtime = 0; | |
603 } | |
604 | |
1708 | 605 return file_data_new(path_utf8, &st, TRUE, NULL); |
586 | 606 } |
607 | |
608 FileData *file_data_add_sidecar_file(FileData *target, FileData *sfd) | |
609 { | |
610 sfd->parent = target; | |
855 | 611 if (!g_list_find(target->sidecar_files, sfd)) |
586 | 612 target->sidecar_files = g_list_prepend(target->sidecar_files, sfd); |
801 | 613 file_data_increment_version(sfd); /* increments both sfd and target */ |
586 | 614 return target; |
615 } | |
616 | |
617 | |
618 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source) | |
619 { | |
620 GList *work; | |
806 | 621 |
586 | 622 file_data_add_sidecar_file(target, source); |
623 | |
624 work = source->sidecar_files; | |
625 while (work) | |
626 { | |
627 FileData *sfd = work->data; | |
628 file_data_add_sidecar_file(target, sfd); | |
629 work = work->next; | |
630 } | |
631 | |
632 g_list_free(source->sidecar_files); | |
633 source->sidecar_files = NULL; | |
634 | |
635 target->sidecar_files = filelist_sort(target->sidecar_files, SORT_NAME, TRUE); | |
806 | 636 |
586 | 637 return target; |
638 } | |
639 | |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
640 #ifdef DEBUG_FILEDATA |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
641 FileData *file_data_ref_debug(const gchar *file, gint line, FileData *fd) |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
642 #else |
586 | 643 FileData *file_data_ref(FileData *fd) |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
644 #endif |
586 | 645 { |
646 if (fd == NULL) return NULL; | |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
647 #ifdef DEBUG_FILEDATA |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
648 if (fd->magick != 0x12345678) |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
649 DEBUG_0("fd magick mismatch at %s:%d", file, line); |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
650 #endif |
586 | 651 g_assert(fd->magick == 0x12345678); |
652 fd->ref++; | |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
653 |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
654 #ifdef DEBUG_FILEDATA |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
655 DEBUG_2("file_data_ref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line); |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
656 #else |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
657 DEBUG_2("file_data_ref (%d): '%s'", fd->ref, fd->path); |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
658 #endif |
586 | 659 return fd; |
660 } | |
661 | |
662 static void file_data_free(FileData *fd) | |
663 { | |
664 g_assert(fd->magick == 0x12345678); | |
665 g_assert(fd->ref == 0); | |
666 | |
667 g_hash_table_remove(file_data_pool, fd->original_path); | |
668 | |
669 g_free(fd->path); | |
670 g_free(fd->original_path); | |
785 | 671 g_free(fd->collate_key_name); |
672 g_free(fd->collate_key_name_nocase); | |
845 | 673 if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf); |
1439 | 674 histmap_free(fd->histmap); |
1294 | 675 |
586 | 676 g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */ |
677 | |
678 file_data_change_info_free(NULL, fd); | |
679 g_free(fd); | |
680 } | |
681 | |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
682 #ifdef DEBUG_FILEDATA |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
683 void file_data_unref_debug(const gchar *file, gint line, FileData *fd) |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
684 #else |
586 | 685 void file_data_unref(FileData *fd) |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
686 #endif |
586 | 687 { |
688 if (fd == NULL) return; | |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
689 #ifdef DEBUG_FILEDATA |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
690 if (fd->magick != 0x12345678) |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
691 DEBUG_0("fd magick mismatch @ %s:%d", file, line); |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
692 #endif |
586 | 693 g_assert(fd->magick == 0x12345678); |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
694 |
586 | 695 fd->ref--; |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
696 #ifdef DEBUG_FILEDATA |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
697 DEBUG_2("file_data_unref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line); |
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
698 #else |
586 | 699 DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path); |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
700 #endif |
586 | 701 if (fd->ref == 0) |
702 { | |
806 | 703 GList *work; |
586 | 704 FileData *parent = fd->parent ? fd->parent : fd; |
806 | 705 |
1422 | 706 if (parent->ref > 0) return; |
586 | 707 |
708 work = parent->sidecar_files; | |
709 while (work) | |
710 { | |
711 FileData *sfd = work->data; | |
1422 | 712 if (sfd->ref > 0) return; |
586 | 713 work = work->next; |
714 } | |
715 | |
716 /* none of parent/children is referenced, we can free everything */ | |
717 | |
874
fa39a4d786ad
Increase debugging info in file_data_ref() and file_data_unref().
zas_
parents:
855
diff
changeset
|
718 DEBUG_2("file_data_unref: deleting '%s', parent '%s'", fd->path, fd->parent ? parent->path : "-"); |
586 | 719 |
720 work = parent->sidecar_files; | |
721 while (work) | |
722 { | |
723 FileData *sfd = work->data; | |
724 file_data_free(sfd); | |
725 work = work->next; | |
726 } | |
727 | |
728 g_list_free(parent->sidecar_files); | |
729 parent->sidecar_files = NULL; | |
730 | |
731 file_data_free(parent); | |
732 } | |
733 } | |
734 | |
735 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd) | |
736 { | |
737 sfd->parent = target; | |
738 g_assert(g_list_find(target->sidecar_files, sfd)); | |
801 | 739 |
740 file_data_increment_version(sfd); /* increments both sfd and target */ | |
586 | 741 |
742 target->sidecar_files = g_list_remove(target->sidecar_files, sfd); | |
743 sfd->parent = NULL; | |
744 | |
806 | 745 if (sfd->ref == 0) |
746 { | |
586 | 747 file_data_free(sfd); |
748 return NULL; | |
806 | 749 } |
586 | 750 |
751 return sfd; | |
752 } | |
753 | |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
754 /* disables / enables grouping for particular file, sends UPDATE notification */ |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
755 void file_data_disable_grouping(FileData *fd, gboolean disable) |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
756 { |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
757 if (!fd->disable_grouping == !disable) return; |
1599 | 758 |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
759 fd->disable_grouping = !!disable; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
760 |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
761 if (disable) |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
762 { |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
763 if (fd->parent) |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
764 { |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
765 FileData *parent = file_data_ref(fd->parent); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
766 file_data_disconnect_sidecar_file(parent, fd); |
1432 | 767 file_data_send_notification(parent, NOTIFY_GROUPING); |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
768 file_data_unref(parent); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
769 } |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
770 else if (fd->sidecar_files) |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
771 { |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
772 GList *sidecar_files = filelist_copy(fd->sidecar_files); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
773 GList *work = sidecar_files; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
774 while (work) |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
775 { |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
776 FileData *sfd = work->data; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
777 work = work->next; |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
778 file_data_disconnect_sidecar_file(fd, sfd); |
1432 | 779 file_data_send_notification(sfd, NOTIFY_GROUPING); |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
780 } |
1518 | 781 file_data_check_sidecars((FileData *)sidecar_files->data, FALSE); /* this will group the sidecars back together */ |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
782 filelist_free(sidecar_files); |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
783 } |
1599 | 784 else |
785 { | |
786 file_data_increment_version(fd); /* the functions called in the cases above increments the version too */ | |
787 } | |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
788 } |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
789 else |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
790 { |
1599 | 791 file_data_increment_version(fd); |
1518 | 792 file_data_check_sidecars(fd, FALSE); |
1599 | 793 } |
794 file_data_send_notification(fd, NOTIFY_GROUPING); | |
795 } | |
796 | |
797 void file_data_disable_grouping_list(GList *fd_list, gboolean disable) | |
798 { | |
799 GList *work; | |
800 | |
801 work = fd_list; | |
802 while (work) | |
803 { | |
804 FileData *fd = work->data; | |
805 | |
806 file_data_disable_grouping(fd, disable); | |
807 work = work->next; | |
849
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
808 } |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
809 } |
db68d673448f
added possibility to disable grouping of selected files
nadvornik
parents:
846
diff
changeset
|
810 |
1599 | 811 |
586 | 812 /* compare name without extension */ |
813 gint file_data_compare_name_without_ext(FileData *fd1, FileData *fd2) | |
814 { | |
815 size_t len1 = fd1->extension - fd1->name; | |
816 size_t len2 = fd2->extension - fd2->name; | |
817 | |
818 if (len1 < len2) return -1; | |
819 if (len1 > len2) return 1; | |
820 | |
785 | 821 return strncmp(fd1->name, fd2->name, len1); /* FIXME: utf8 */ |
586 | 822 } |
823 | |
824 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd) | |
825 { | |
1422 | 826 if (!fdci && fd) fdci = fd->change; |
586 | 827 |
1422 | 828 if (!fdci) return; |
586 | 829 |
830 g_free(fdci->source); | |
831 g_free(fdci->dest); | |
832 | |
833 g_free(fdci); | |
834 | |
1422 | 835 if (fd) fd->change = NULL; |
586 | 836 } |
837 | |
1224 | 838 static gboolean file_data_can_write_directly(FileData *fd) |
839 { | |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1229
diff
changeset
|
840 return filter_name_is_writable(fd->extension); |
1224 | 841 } |
586 | 842 |
1224 | 843 static gboolean file_data_can_write_sidecar(FileData *fd) |
844 { | |
1239
254b09942e68
metadata write mode (direct or sidecar) made configurable for each file
nadvornik
parents:
1229
diff
changeset
|
845 return filter_name_allow_sidecar(fd->extension) && !filter_name_is_writable(fd->extension); |
1224 | 846 } |
847 | |
848 gchar *file_data_get_sidecar_path(FileData *fd, gboolean existing_only) | |
849 { | |
850 gchar *sidecar_path = NULL; | |
851 GList *work; | |
1422 | 852 |
1224 | 853 if (!file_data_can_write_sidecar(fd)) return NULL; |
854 | |
855 work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files; | |
856 while (work) | |
857 { | |
858 FileData *sfd = work->data; | |
859 work = work->next; | |
1307 | 860 if (g_ascii_strcasecmp(sfd->extension, ".xmp") == 0) |
1224 | 861 { |
862 sidecar_path = g_strdup(sfd->path); | |
863 break; | |
864 } | |
865 } | |
866 | |
867 if (!existing_only && !sidecar_path) | |
868 { | |
869 gchar *base = remove_extension_from_path(fd->path); | |
870 sidecar_path = g_strconcat(base, ".xmp", NULL); | |
871 g_free(base); | |
872 } | |
873 | |
874 return sidecar_path; | |
875 } | |
586 | 876 |
877 | |
878 /* | |
879 *----------------------------------------------------------------------------- | |
880 * sidecar file info struct | |
881 *----------------------------------------------------------------------------- | |
882 */ | |
883 | |
884 | |
885 | |
886 static gint sidecar_file_priority(const gchar *path) | |
887 { | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
888 const gchar *extension = extension_from_path(path); |
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
889 gint i = 1; |
586 | 890 GList *work; |
806 | 891 |
586 | 892 if (extension == NULL) |
893 return 0; | |
894 | |
895 work = sidecar_ext_get_list(); | |
896 | |
897 while (work) { | |
898 gchar *ext = work->data; | |
806 | 899 |
586 | 900 work = work->next; |
1307 | 901 if (g_ascii_strcasecmp(extension, ext) == 0) return i; |
586 | 902 i++; |
903 } | |
904 return 0; | |
905 } | |
906 | |
907 | |
908 /* | |
909 *----------------------------------------------------------------------------- | |
910 * load file list | |
911 *----------------------------------------------------------------------------- | |
912 */ | |
913 | |
914 static SortType filelist_sort_method = SORT_NONE; | |
1422 | 915 static gboolean filelist_sort_ascend = TRUE; |
586 | 916 |
917 | |
918 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb) | |
919 { | |
920 if (!filelist_sort_ascend) | |
921 { | |
922 FileData *tmp = fa; | |
923 fa = fb; | |
924 fb = tmp; | |
925 } | |
926 | |
927 switch (filelist_sort_method) | |
928 { | |
785 | 929 case SORT_NAME: |
930 break; | |
586 | 931 case SORT_SIZE: |
932 if (fa->size < fb->size) return -1; | |
933 if (fa->size > fb->size) return 1; | |
785 | 934 /* fall back to name */ |
586 | 935 break; |
936 case SORT_TIME: | |
937 if (fa->date < fb->date) return -1; | |
938 if (fa->date > fb->date) return 1; | |
785 | 939 /* fall back to name */ |
586 | 940 break; |
941 #ifdef HAVE_STRVERSCMP | |
942 case SORT_NUMBER: | |
943 return strverscmp(fa->name, fb->name); | |
944 break; | |
945 #endif | |
946 default: | |
947 break; | |
948 } | |
785 | 949 |
950 if (options->file_sort.case_sensitive) | |
951 return strcmp(fa->collate_key_name, fb->collate_key_name); | |
952 else | |
953 return strcmp(fa->collate_key_name_nocase, fb->collate_key_name_nocase); | |
586 | 954 } |
955 | |
1422 | 956 gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gboolean ascend) |
586 | 957 { |
958 filelist_sort_method = method; | |
959 filelist_sort_ascend = ascend; | |
960 return filelist_sort_compare_filedata(fa, fb); | |
961 } | |
962 | |
1002 | 963 static gint filelist_sort_file_cb(gpointer a, gpointer b) |
586 | 964 { |
965 return filelist_sort_compare_filedata(a, b); | |
966 } | |
967 | |
1422 | 968 GList *filelist_sort_full(GList *list, SortType method, gboolean ascend, GCompareFunc cb) |
586 | 969 { |
970 filelist_sort_method = method; | |
971 filelist_sort_ascend = ascend; | |
972 return g_list_sort(list, cb); | |
973 } | |
974 | |
1422 | 975 GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gboolean ascend, GCompareFunc cb) |
586 | 976 { |
977 filelist_sort_method = method; | |
978 filelist_sort_ascend = ascend; | |
979 return g_list_insert_sorted(list, data, cb); | |
980 } | |
981 | |
1422 | 982 GList *filelist_sort(GList *list, SortType method, gboolean ascend) |
586 | 983 { |
984 return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb); | |
985 } | |
986 | |
1422 | 987 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gboolean ascend) |
586 | 988 { |
989 return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb); | |
990 } | |
991 | |
992 | |
993 static GList *filelist_filter_out_sidecars(GList *flist) | |
994 { | |
995 GList *work = flist; | |
996 GList *flist_filtered = NULL; | |
997 | |
998 while (work) | |
999 { | |
1000 FileData *fd = work->data; | |
806 | 1001 |
586 | 1002 work = work->next; |
1003 if (fd->parent) /* remove fd's that are children */ | |
1004 file_data_unref(fd); | |
1005 else | |
1006 flist_filtered = g_list_prepend(flist_filtered, fd); | |
1007 } | |
1008 g_list_free(flist); | |
806 | 1009 |
586 | 1010 return flist_filtered; |
1011 } | |
1012 | |
1423
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1013 static gboolean is_hidden_file(const gchar *name) |
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1014 { |
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1015 if (name[0] != '.') return FALSE; |
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1016 if (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')) return FALSE; |
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1017 return TRUE; |
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1018 } |
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1019 |
1422 | 1020 static gboolean filelist_read_real(FileData *dir_fd, GList **files, GList **dirs, gboolean follow_symlinks) |
586 | 1021 { |
1022 DIR *dp; | |
1023 struct dirent *dir; | |
1024 gchar *pathl; | |
779 | 1025 GList *dlist = NULL; |
1026 GList *flist = NULL; | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
1027 gint (*stat_func)(const gchar *path, struct stat *buf); |
1708 | 1028 GHashTable *basename_hash = NULL; |
586 | 1029 |
779 | 1030 g_assert(files || dirs); |
1031 | |
1032 if (files) *files = NULL; | |
1033 if (dirs) *dirs = NULL; | |
586 | 1034 |
783 | 1035 pathl = path_from_utf8(dir_fd->path); |
779 | 1036 if (!pathl) return FALSE; |
1037 | |
1038 dp = opendir(pathl); | |
1039 if (dp == NULL) | |
586 | 1040 { |
1041 g_free(pathl); | |
1042 return FALSE; | |
1043 } | |
1044 | |
1708 | 1045 if (files) basename_hash = file_data_basename_hash_new(); |
1046 | |
779 | 1047 if (follow_symlinks) |
1048 stat_func = stat; | |
1049 else | |
1050 stat_func = lstat; | |
1051 | |
586 | 1052 while ((dir = readdir(dp)) != NULL) |
1053 { | |
779 | 1054 struct stat ent_sbuf; |
1055 const gchar *name = dir->d_name; | |
1056 gchar *filepath; | |
1057 | |
1423
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1058 if (!options->file_filter.show_hidden_files && is_hidden_file(name)) |
779 | 1059 continue; |
1060 | |
1061 filepath = g_build_filename(pathl, name, NULL); | |
1062 if (stat_func(filepath, &ent_sbuf) >= 0) | |
586 | 1063 { |
779 | 1064 if (S_ISDIR(ent_sbuf.st_mode)) |
586 | 1065 { |
779 | 1066 /* we ignore the .thumbnails dir for cleanliness */ |
1067 if (dirs && | |
1068 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && | |
1069 strcmp(name, GQ_CACHE_LOCAL_THUMB) != 0 && | |
1070 strcmp(name, GQ_CACHE_LOCAL_METADATA) != 0 && | |
1071 strcmp(name, THUMB_FOLDER_LOCAL) != 0) | |
586 | 1072 { |
1708 | 1073 dlist = g_list_prepend(dlist, file_data_new_local(filepath, &ent_sbuf, FALSE, NULL)); |
586 | 1074 } |
1075 } | |
779 | 1076 else |
1077 { | |
1078 if (files && filter_name_exists(name)) | |
1079 { | |
1708 | 1080 flist = g_list_prepend(flist, file_data_new_local(filepath, &ent_sbuf, TRUE, basename_hash)); |
779 | 1081 } |
1082 } | |
586 | 1083 } |
1746
219a5dd783ed
Log a message when EOVERFLOW error is set by stat() when building files lists. See bug 2876142.
zas_
parents:
1742
diff
changeset
|
1084 else |
219a5dd783ed
Log a message when EOVERFLOW error is set by stat() when building files lists. See bug 2876142.
zas_
parents:
1742
diff
changeset
|
1085 { |
219a5dd783ed
Log a message when EOVERFLOW error is set by stat() when building files lists. See bug 2876142.
zas_
parents:
1742
diff
changeset
|
1086 if (errno == EOVERFLOW) |
219a5dd783ed
Log a message when EOVERFLOW error is set by stat() when building files lists. See bug 2876142.
zas_
parents:
1742
diff
changeset
|
1087 { |
219a5dd783ed
Log a message when EOVERFLOW error is set by stat() when building files lists. See bug 2876142.
zas_
parents:
1742
diff
changeset
|
1088 log_printf("stat(): EOVERFLOW, skip '%s'", filepath); |
219a5dd783ed
Log a message when EOVERFLOW error is set by stat() when building files lists. See bug 2876142.
zas_
parents:
1742
diff
changeset
|
1089 } |
219a5dd783ed
Log a message when EOVERFLOW error is set by stat() when building files lists. See bug 2876142.
zas_
parents:
1742
diff
changeset
|
1090 } |
779 | 1091 g_free(filepath); |
586 | 1092 } |
1093 | |
1094 closedir(dp); | |
779 | 1095 |
586 | 1096 g_free(pathl); |
1708 | 1097 if (basename_hash) file_data_basename_hash_free(basename_hash); |
586 | 1098 |
1099 if (dirs) *dirs = dlist; | |
779 | 1100 if (files) *files = filelist_filter_out_sidecars(flist); |
586 | 1101 |
1102 return TRUE; | |
1103 } | |
1104 | |
1422 | 1105 gboolean filelist_read(FileData *dir_fd, GList **files, GList **dirs) |
586 | 1106 { |
783 | 1107 return filelist_read_real(dir_fd, files, dirs, TRUE); |
586 | 1108 } |
1109 | |
1422 | 1110 gboolean filelist_read_lstat(FileData *dir_fd, GList **files, GList **dirs) |
586 | 1111 { |
783 | 1112 return filelist_read_real(dir_fd, files, dirs, FALSE); |
586 | 1113 } |
1114 | |
1115 void filelist_free(GList *list) | |
1116 { | |
1117 GList *work; | |
1118 | |
1119 work = list; | |
1120 while (work) | |
1121 { | |
1122 file_data_unref((FileData *)work->data); | |
1123 work = work->next; | |
1124 } | |
1125 | |
1126 g_list_free(list); | |
1127 } | |
1128 | |
1129 | |
1130 GList *filelist_copy(GList *list) | |
1131 { | |
1132 GList *new_list = NULL; | |
1133 GList *work; | |
1134 | |
1135 work = list; | |
1136 while (work) | |
1137 { | |
1138 FileData *fd; | |
1139 | |
1140 fd = work->data; | |
1141 work = work->next; | |
1142 | |
1143 new_list = g_list_prepend(new_list, file_data_ref(fd)); | |
1144 } | |
1145 | |
1146 return g_list_reverse(new_list); | |
1147 } | |
1148 | |
1149 GList *filelist_from_path_list(GList *list) | |
1150 { | |
1151 GList *new_list = NULL; | |
1152 GList *work; | |
1153 | |
1154 work = list; | |
1155 while (work) | |
1156 { | |
1157 gchar *path; | |
1158 | |
1159 path = work->data; | |
1160 work = work->next; | |
1161 | |
1162 new_list = g_list_prepend(new_list, file_data_new_simple(path)); | |
1163 } | |
1164 | |
1165 return g_list_reverse(new_list); | |
1166 } | |
1167 | |
1168 GList *filelist_to_path_list(GList *list) | |
1169 { | |
1170 GList *new_list = NULL; | |
1171 GList *work; | |
1172 | |
1173 work = list; | |
1174 while (work) | |
1175 { | |
1176 FileData *fd; | |
1177 | |
1178 fd = work->data; | |
1179 work = work->next; | |
1180 | |
1181 new_list = g_list_prepend(new_list, g_strdup(fd->path)); | |
1182 } | |
1183 | |
1184 return g_list_reverse(new_list); | |
1185 } | |
1186 | |
1422 | 1187 GList *filelist_filter(GList *list, gboolean is_dir_list) |
586 | 1188 { |
1189 GList *work; | |
1190 | |
1191 if (!is_dir_list && options->file_filter.disable && options->file_filter.show_hidden_files) return list; | |
1192 | |
1193 work = list; | |
1194 while (work) | |
1195 { | |
1196 FileData *fd = (FileData *)(work->data); | |
1197 const gchar *name = fd->name; | |
1198 | |
1423
6933974f0885
Make ishidden() static to filedata.c and rename it is_hidden_file().
zas_
parents:
1422
diff
changeset
|
1199 if ((!options->file_filter.show_hidden_files && is_hidden_file(name)) || |
586 | 1200 (!is_dir_list && !filter_name_exists(name)) || |
1201 (is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 || | |
1202 strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) ) | |
1203 { | |
1204 GList *link = work; | |
806 | 1205 |
586 | 1206 list = g_list_remove_link(list, link); |
1207 file_data_unref(fd); | |
1208 g_list_free(link); | |
1209 } | |
806 | 1210 |
1211 work = work->next; | |
586 | 1212 } |
1213 | |
1214 return list; | |
1215 } | |
1216 | |
1217 /* | |
1218 *----------------------------------------------------------------------------- | |
1219 * filelist recursive | |
1220 *----------------------------------------------------------------------------- | |
1221 */ | |
1222 | |
1223 static gint filelist_sort_path_cb(gconstpointer a, gconstpointer b) | |
1224 { | |
1225 return CASE_SORT(((FileData *)a)->path, ((FileData *)b)->path); | |
1226 } | |
1227 | |
1228 GList *filelist_sort_path(GList *list) | |
1229 { | |
1230 return g_list_sort(list, filelist_sort_path_cb); | |
1231 } | |
1232 | |
1233 static void filelist_recursive_append(GList **list, GList *dirs) | |
1234 { | |
1235 GList *work; | |
1236 | |
1237 work = dirs; | |
1238 while (work) | |
1239 { | |
1240 FileData *fd = (FileData *)(work->data); | |
780
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
779
diff
changeset
|
1241 GList *f; |
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
779
diff
changeset
|
1242 GList *d; |
586 | 1243 |
783 | 1244 if (filelist_read(fd, &f, &d)) |
586 | 1245 { |
1246 f = filelist_filter(f, FALSE); | |
1247 f = filelist_sort_path(f); | |
1248 *list = g_list_concat(*list, f); | |
1249 | |
1250 d = filelist_filter(d, TRUE); | |
1251 d = filelist_sort_path(d); | |
1252 filelist_recursive_append(list, d); | |
1253 filelist_free(d); | |
1254 } | |
1255 | |
1256 work = work->next; | |
1257 } | |
1258 } | |
1259 | |
783 | 1260 GList *filelist_recursive(FileData *dir_fd) |
586 | 1261 { |
780
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
779
diff
changeset
|
1262 GList *list; |
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
779
diff
changeset
|
1263 GList *d; |
586 | 1264 |
783 | 1265 if (!filelist_read(dir_fd, &list, &d)) return NULL; |
586 | 1266 list = filelist_filter(list, FALSE); |
1267 list = filelist_sort_path(list); | |
1268 | |
1269 d = filelist_filter(d, TRUE); | |
1270 d = filelist_sort_path(d); | |
1271 filelist_recursive_append(&list, d); | |
1272 filelist_free(d); | |
1273 | |
1274 return list; | |
1275 } | |
590 | 1276 |
1277 | |
800 | 1278 /* |
1279 * marks and orientation | |
1280 */ | |
995 | 1281 |
1222 | 1282 static FileDataGetMarkFunc file_data_get_mark_func[FILEDATA_MARKS_SIZE]; |
1283 static FileDataSetMarkFunc file_data_set_mark_func[FILEDATA_MARKS_SIZE]; | |
1284 static gpointer file_data_mark_func_data[FILEDATA_MARKS_SIZE]; | |
1425 | 1285 static GDestroyNotify file_data_destroy_mark_func[FILEDATA_MARKS_SIZE]; |
995 | 1286 |
800 | 1287 gboolean file_data_get_mark(FileData *fd, gint n) |
1288 { | |
1227 | 1289 gboolean valid = (fd->valid_marks & (1 << n)); |
1422 | 1290 |
1227 | 1291 if (file_data_get_mark_func[n] && !valid) |
1222 | 1292 { |
1227 | 1293 guint old = fd->marks; |
1222 | 1294 gboolean value = (file_data_get_mark_func[n])(fd, n, file_data_mark_func_data[n]); |
1422 | 1295 |
1227 | 1296 if (!value != !(fd->marks & (1 << n))) |
1297 { | |
1298 fd->marks = fd->marks ^ (1 << n); | |
1299 } | |
1422 | 1300 |
1227 | 1301 fd->valid_marks |= (1 << n); |
1302 if (old && !fd->marks) /* keep files with non-zero marks in memory */ | |
1303 { | |
1304 file_data_unref(fd); | |
1305 } | |
1306 else if (!old && fd->marks) | |
1307 { | |
1308 file_data_ref(fd); | |
1309 } | |
1222 | 1310 } |
1311 | |
800 | 1312 return !!(fd->marks & (1 << n)); |
1313 } | |
1314 | |
966 | 1315 guint file_data_get_marks(FileData *fd) |
1316 { | |
1222 | 1317 gint i; |
1318 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) file_data_get_mark(fd, i); | |
966 | 1319 return fd->marks; |
1320 } | |
1321 | |
800 | 1322 void file_data_set_mark(FileData *fd, gint n, gboolean value) |
1323 { | |
1227 | 1324 guint old; |
1325 if (!value == !file_data_get_mark(fd, n)) return; | |
1326 | |
1222 | 1327 if (file_data_set_mark_func[n]) |
1328 { | |
1329 (file_data_set_mark_func[n])(fd, n, value, file_data_mark_func_data[n]); | |
1330 } | |
1227 | 1331 |
1332 old = fd->marks; | |
1222 | 1333 |
800 | 1334 fd->marks = fd->marks ^ (1 << n); |
965 | 1335 |
1336 if (old && !fd->marks) /* keep files with non-zero marks in memory */ | |
1337 { | |
1338 file_data_unref(fd); | |
1339 } | |
1340 else if (!old && fd->marks) | |
1341 { | |
1342 file_data_ref(fd); | |
1343 } | |
1344 | |
800 | 1345 file_data_increment_version(fd); |
1432 | 1346 file_data_send_notification(fd, NOTIFY_MARKS); |
800 | 1347 } |
1348 | |
964 | 1349 gboolean file_data_filter_marks(FileData *fd, guint filter) |
1350 { | |
1222 | 1351 gint i; |
1352 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) if (filter & (1 << i)) file_data_get_mark(fd, i); | |
964 | 1353 return ((fd->marks & filter) == filter); |
1354 } | |
1355 | |
1356 GList *file_data_filter_marks_list(GList *list, guint filter) | |
1357 { | |
1358 GList *work; | |
1359 | |
1360 work = list; | |
1361 while (work) | |
1362 { | |
1363 FileData *fd = work->data; | |
1364 GList *link = work; | |
1365 work = work->next; | |
1366 | |
1367 if (!file_data_filter_marks(fd, filter)) | |
1368 { | |
1369 list = g_list_remove_link(list, link); | |
1370 file_data_unref(fd); | |
1371 g_list_free(link); | |
1372 } | |
1373 } | |
1374 | |
1375 return list; | |
1376 } | |
1377 | |
1222 | 1378 static void file_data_notify_mark_func(gpointer key, gpointer value, gpointer user_data) |
1379 { | |
1380 FileData *fd = value; | |
1381 file_data_increment_version(fd); | |
1432 | 1382 file_data_send_notification(fd, NOTIFY_MARKS); |
1222 | 1383 } |
1384 | |
1425 | 1385 gboolean file_data_register_mark_func(gint n, FileDataGetMarkFunc get_mark_func, FileDataSetMarkFunc set_mark_func, gpointer data, GDestroyNotify notify) |
1222 | 1386 { |
1387 if (n < 0 || n >= FILEDATA_MARKS_SIZE) return FALSE; | |
1425 | 1388 |
1389 if (file_data_destroy_mark_func[n]) (file_data_destroy_mark_func[n])(file_data_mark_func_data[n]); | |
1222 | 1390 |
1391 file_data_get_mark_func[n] = get_mark_func; | |
1392 file_data_set_mark_func[n] = set_mark_func; | |
1393 file_data_mark_func_data[n] = data; | |
1425 | 1394 file_data_destroy_mark_func[n] = notify; |
1395 | |
1222 | 1396 if (get_mark_func) |
1425 | 1397 { |
1398 /* this effectively changes all known files */ | |
1399 g_hash_table_foreach(file_data_pool, file_data_notify_mark_func, NULL); | |
1400 } | |
1401 | |
1222 | 1402 return TRUE; |
1403 } | |
1404 | |
1405 void file_data_get_registered_mark_func(gint n, FileDataGetMarkFunc *get_mark_func, FileDataSetMarkFunc *set_mark_func, gpointer *data) | |
1406 { | |
1407 if (get_mark_func) *get_mark_func = file_data_get_mark_func[n]; | |
1408 if (set_mark_func) *set_mark_func = file_data_set_mark_func[n]; | |
1409 if (data) *data = file_data_mark_func_data[n]; | |
1410 } | |
1411 | |
800 | 1412 gint file_data_get_user_orientation(FileData *fd) |
1413 { | |
1414 return fd->user_orientation; | |
1415 } | |
1416 | |
1417 void file_data_set_user_orientation(FileData *fd, gint value) | |
1418 { | |
1419 if (fd->user_orientation == value) return; | |
1420 | |
1421 fd->user_orientation = value; | |
1422 file_data_increment_version(fd); | |
1432 | 1423 file_data_send_notification(fd, NOTIFY_ORIENTATION); |
800 | 1424 } |
1425 | |
1426 | |
590 | 1427 /* |
1428 * file_data - operates on the given fd | |
1429 * file_data_sc - operates on the given fd + sidecars - all fds linked via fd->sidecar_files or fd->parent | |
1430 */ | |
1431 | |
1432 | |
1433 /* return list of sidecar file extensions in a string */ | |
596 | 1434 gchar *file_data_sc_list_to_string(FileData *fd) |
1435 { | |
1436 GList *work; | |
1437 GString *result = g_string_new(""); | |
1438 | |
1439 work = fd->sidecar_files; | |
1440 while (work) | |
1441 { | |
1442 FileData *sfd = work->data; | |
806 | 1443 |
596 | 1444 result = g_string_append(result, "+ "); |
1445 result = g_string_append(result, sfd->extension); | |
1446 work = work->next; | |
1447 if (work) result = g_string_append_c(result, ' '); | |
1448 } | |
1449 | |
1450 return g_string_free(result, FALSE); | |
1451 } | |
590 | 1452 |
1453 | |
995 | 1454 |
1455 /* | |
1456 * add FileDataChangeInfo (see typedefs.h) for the given operation | |
590 | 1457 * uses file_data_add_change_info |
1458 * | |
1459 * fails if the fd->change already exists - change operations can't run in parallel | |
1460 * fd->change_info works as a lock | |
1461 * | |
1462 * dest can be NULL - in this case the current name is used for now, it will | |
995 | 1463 * be changed later |
590 | 1464 */ |
1465 | |
1466 /* | |
1467 FileDataChangeInfo types: | |
1468 COPY | |
950 | 1469 MOVE - path is changed, name may be changed too |
590 | 1470 RENAME - path remains unchanged, name is changed |
1471 extension should remain (FIXME should we allow editing extension? it will make problems wth grouping) | |
1472 sidecar names are changed too, extensions are not changed | |
1473 DELETE | |
995 | 1474 UPDATE - file size, date or grouping has been changed |
590 | 1475 */ |
1476 | |
1477 gboolean file_data_add_ci(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) | |
1478 { | |
1479 FileDataChangeInfo *fdci; | |
1480 | |
1481 if (fd->change) return FALSE; | |
1482 | |
1483 fdci = g_new0(FileDataChangeInfo, 1); | |
1484 | |
1485 fdci->type = type; | |
1486 | |
1487 if (src) | |
1488 fdci->source = g_strdup(src); | |
1489 else | |
1490 fdci->source = g_strdup(fd->path); | |
1491 | |
1492 if (dest) | |
1493 fdci->dest = g_strdup(dest); | |
1494 | |
1495 fd->change = fdci; | |
1496 | |
1497 return TRUE; | |
1498 } | |
1499 | |
912
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1500 static void file_data_planned_change_remove(FileData *fd) |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1501 { |
995 | 1502 if (file_data_planned_change_hash && |
912
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1503 (fd->change->type == FILEDATA_CHANGE_MOVE || fd->change->type == FILEDATA_CHANGE_RENAME)) |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1504 { |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1505 if (g_hash_table_lookup(file_data_planned_change_hash, fd->change->dest) == fd) |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1506 { |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1507 DEBUG_1("planned change: removing %s -> %s", fd->change->dest, fd->path); |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1508 g_hash_table_remove(file_data_planned_change_hash, fd->change->dest); |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1509 file_data_unref(fd); |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1510 if (g_hash_table_size(file_data_planned_change_hash) == 0) |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1511 { |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1512 g_hash_table_destroy(file_data_planned_change_hash); |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1513 file_data_planned_change_hash = NULL; |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1514 DEBUG_1("planned change: empty"); |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1515 } |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1516 } |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1517 } |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1518 } |
995 | 1519 |
912
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1520 |
590 | 1521 void file_data_free_ci(FileData *fd) |
1522 { | |
1523 FileDataChangeInfo *fdci = fd->change; | |
1524 | |
1422 | 1525 if (!fdci) return; |
590 | 1526 |
912
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1527 file_data_planned_change_remove(fd); |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
1528 |
590 | 1529 g_free(fdci->source); |
1530 g_free(fdci->dest); | |
1531 | |
1532 g_free(fdci); | |
1533 | |
1534 fd->change = NULL; | |
1535 } | |
1536 | |
995 | 1537 |
590 | 1538 static gboolean file_data_sc_add_ci(FileData *fd, FileDataChangeType type) |
1539 { | |
1540 GList *work; | |
806 | 1541 |
590 | 1542 if (fd->parent) fd = fd->parent; |
1543 | |
1544 if (fd->change) return FALSE; | |
806 | 1545 |
590 | 1546 work = fd->sidecar_files; |
1547 while (work) | |
1548 { | |
1549 FileData *sfd = work->data; | |
806 | 1550 |
590 | 1551 if (sfd->change) return FALSE; |
1552 work = work->next; | |
1553 } | |
1554 | |
1555 file_data_add_ci(fd, type, NULL, NULL); | |
1556 | |
1557 work = fd->sidecar_files; | |
1558 while (work) | |
1559 { | |
1560 FileData *sfd = work->data; | |
806 | 1561 |
590 | 1562 file_data_add_ci(sfd, type, NULL, NULL); |
1563 work = work->next; | |
1564 } | |
1565 | |
995 | 1566 return TRUE; |
590 | 1567 } |
1568 | |
1569 static gboolean file_data_sc_check_ci(FileData *fd, FileDataChangeType type) | |
1570 { | |
1571 GList *work; | |
806 | 1572 |
590 | 1573 if (fd->parent) fd = fd->parent; |
1574 | |
806 | 1575 if (!fd->change || fd->change->type != type) return FALSE; |
1576 | |
590 | 1577 work = fd->sidecar_files; |
1578 while (work) | |
1579 { | |
1580 FileData *sfd = work->data; | |
806 | 1581 |
1582 if (!sfd->change || sfd->change->type != type) return FALSE; | |
590 | 1583 work = work->next; |
1584 } | |
806 | 1585 |
590 | 1586 return TRUE; |
1587 } | |
1588 | |
1589 | |
751 | 1590 gboolean file_data_sc_add_ci_copy(FileData *fd, const gchar *dest_path) |
590 | 1591 { |
1592 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_COPY)) return FALSE; | |
1593 file_data_sc_update_ci_copy(fd, dest_path); | |
1594 return TRUE; | |
1595 } | |
1596 | |
751 | 1597 gboolean file_data_sc_add_ci_move(FileData *fd, const gchar *dest_path) |
590 | 1598 { |
1599 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_MOVE)) return FALSE; | |
1600 file_data_sc_update_ci_move(fd, dest_path); | |
1601 return TRUE; | |
1602 } | |
1603 | |
751 | 1604 gboolean file_data_sc_add_ci_rename(FileData *fd, const gchar *dest_path) |
590 | 1605 { |
1606 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_RENAME)) return FALSE; | |
1607 file_data_sc_update_ci_rename(fd, dest_path); | |
1608 return TRUE; | |
1609 } | |
1610 | |
1611 gboolean file_data_sc_add_ci_delete(FileData *fd) | |
1612 { | |
1613 return file_data_sc_add_ci(fd, FILEDATA_CHANGE_DELETE); | |
1614 } | |
1615 | |
753 | 1616 gboolean file_data_sc_add_ci_unspecified(FileData *fd, const gchar *dest_path) |
590 | 1617 { |
753 | 1618 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_UNSPECIFIED)) return FALSE; |
1619 file_data_sc_update_ci_unspecified(fd, dest_path); | |
1620 return TRUE; | |
590 | 1621 } |
1622 | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1623 gboolean file_data_add_ci_write_metadata(FileData *fd) |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1624 { |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1625 return file_data_add_ci(fd, FILEDATA_CHANGE_WRITE_METADATA, NULL, NULL); |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1626 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1627 |
590 | 1628 void file_data_sc_free_ci(FileData *fd) |
1629 { | |
1630 GList *work; | |
806 | 1631 |
590 | 1632 if (fd->parent) fd = fd->parent; |
1633 | |
1634 file_data_free_ci(fd); | |
1635 | |
1636 work = fd->sidecar_files; | |
1637 while (work) | |
1638 { | |
1639 FileData *sfd = work->data; | |
806 | 1640 |
590 | 1641 file_data_free_ci(sfd); |
1642 work = work->next; | |
1643 } | |
1644 } | |
1645 | |
751 | 1646 gboolean file_data_sc_add_ci_delete_list(GList *fd_list) |
1647 { | |
1648 GList *work; | |
1649 gboolean ret = TRUE; | |
806 | 1650 |
751 | 1651 work = fd_list; |
1652 while (work) | |
1653 { | |
1654 FileData *fd = work->data; | |
806 | 1655 |
751 | 1656 if (!file_data_sc_add_ci_delete(fd)) ret = FALSE; |
1657 work = work->next; | |
1658 } | |
806 | 1659 |
751 | 1660 return ret; |
1661 } | |
1662 | |
913 | 1663 static void file_data_sc_revert_ci_list(GList *fd_list) |
751 | 1664 { |
1665 GList *work; | |
806 | 1666 |
751 | 1667 work = fd_list; |
1668 while (work) | |
1669 { | |
1670 FileData *fd = work->data; | |
806 | 1671 |
913 | 1672 file_data_sc_free_ci(fd); |
1673 work = work->prev; | |
1674 } | |
1675 } | |
1676 | |
923 | 1677 static gboolean file_data_sc_add_ci_list_call_func(GList *fd_list, const gchar *dest, gboolean (*func)(FileData *, const gchar *)) |
913 | 1678 { |
1679 GList *work; | |
1680 | |
1681 work = fd_list; | |
1682 while (work) | |
1683 { | |
1684 FileData *fd = work->data; | |
1685 | |
995 | 1686 if (!func(fd, dest)) |
913 | 1687 { |
1688 file_data_sc_revert_ci_list(work->prev); | |
1689 return FALSE; | |
1690 } | |
751 | 1691 work = work->next; |
1692 } | |
806 | 1693 |
913 | 1694 return TRUE; |
751 | 1695 } |
1696 | |
923 | 1697 gboolean file_data_sc_add_ci_copy_list(GList *fd_list, const gchar *dest) |
1698 { | |
1699 return file_data_sc_add_ci_list_call_func(fd_list, dest, file_data_sc_add_ci_copy); | |
1700 } | |
1701 | |
751 | 1702 gboolean file_data_sc_add_ci_move_list(GList *fd_list, const gchar *dest) |
1703 { | |
923 | 1704 return file_data_sc_add_ci_list_call_func(fd_list, dest, file_data_sc_add_ci_move); |
751 | 1705 } |
1706 | |
1707 gboolean file_data_sc_add_ci_rename_list(GList *fd_list, const gchar *dest) | |
1708 { | |
923 | 1709 return file_data_sc_add_ci_list_call_func(fd_list, dest, file_data_sc_add_ci_rename); |
751 | 1710 } |
1711 | |
753 | 1712 gboolean file_data_sc_add_ci_unspecified_list(GList *fd_list, const gchar *dest) |
1713 { | |
923 | 1714 return file_data_sc_add_ci_list_call_func(fd_list, dest, file_data_sc_add_ci_unspecified); |
753 | 1715 } |
1716 | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1717 gboolean file_data_add_ci_write_metadata_list(GList *fd_list) |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1718 { |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1719 GList *work; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1720 gboolean ret = TRUE; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1721 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1722 work = fd_list; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1723 while (work) |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1724 { |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1725 FileData *fd = work->data; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1726 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1727 if (!file_data_add_ci_write_metadata(fd)) ret = FALSE; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1728 work = work->next; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1729 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1730 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1731 return ret; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1732 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1733 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1734 void file_data_free_ci_list(GList *fd_list) |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1735 { |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1736 GList *work; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1737 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1738 work = fd_list; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1739 while (work) |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1740 { |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1741 FileData *fd = work->data; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1742 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1743 file_data_free_ci(fd); |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1744 work = work->next; |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1745 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1746 } |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
1747 |
751 | 1748 void file_data_sc_free_ci_list(GList *fd_list) |
1749 { | |
1750 GList *work; | |
806 | 1751 |
751 | 1752 work = fd_list; |
1753 while (work) | |
1754 { | |
1755 FileData *fd = work->data; | |
806 | 1756 |
751 | 1757 file_data_sc_free_ci(fd); |
1758 work = work->next; | |
1759 } | |
1760 } | |
590 | 1761 |
995 | 1762 /* |
590 | 1763 * update existing fd->change, it will be used from dialog callbacks for interactive editing |
1764 * fails if fd->change does not exist or the change type does not match | |
1765 */ | |
1766 | |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1767 static void file_data_update_planned_change_hash(FileData *fd, const gchar *old_path, gchar *new_path) |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1768 { |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1769 FileDataChangeType type = fd->change->type; |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1770 |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1771 if (type == FILEDATA_CHANGE_MOVE || type == FILEDATA_CHANGE_RENAME) |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1772 { |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1773 FileData *ofd; |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1774 |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1775 if (!file_data_planned_change_hash) |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1776 file_data_planned_change_hash = g_hash_table_new(g_str_hash, g_str_equal); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1777 |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1778 if (old_path && g_hash_table_lookup(file_data_planned_change_hash, old_path) == fd) |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1779 { |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1780 DEBUG_1("planned change: removing %s -> %s", old_path, fd->path); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1781 g_hash_table_remove(file_data_planned_change_hash, old_path); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1782 file_data_unref(fd); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1783 } |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1784 |
918 | 1785 ofd = g_hash_table_lookup(file_data_planned_change_hash, new_path); |
1786 if (ofd != fd) | |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1787 { |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1788 if (ofd) |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1789 { |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1790 DEBUG_1("planned change: replacing %s -> %s", new_path, ofd->path); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1791 g_hash_table_remove(file_data_planned_change_hash, new_path); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1792 file_data_unref(ofd); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1793 } |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1794 |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1795 DEBUG_1("planned change: inserting %s -> %s", new_path, fd->path); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1796 file_data_ref(fd); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1797 g_hash_table_insert(file_data_planned_change_hash, new_path, fd); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1798 } |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1799 } |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1800 } |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1801 |
751 | 1802 static void file_data_update_ci_dest(FileData *fd, const gchar *dest_path) |
590 | 1803 { |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1804 gchar *old_path = fd->change->dest; |
918 | 1805 |
590 | 1806 fd->change->dest = g_strdup(dest_path); |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1807 file_data_update_planned_change_hash(fd, old_path, fd->change->dest); |
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1808 g_free(old_path); |
590 | 1809 } |
1810 | |
751 | 1811 static void file_data_update_ci_dest_preserve_ext(FileData *fd, const gchar *dest_path) |
590 | 1812 { |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
1813 const gchar *extension = extension_from_path(fd->change->source); |
751 | 1814 gchar *base = remove_extension_from_path(dest_path); |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1815 gchar *old_path = fd->change->dest; |
806 | 1816 |
920
408879d2a660
Use g_strconcat() instead of g_strdup_printf("%s%s", ...).
zas_
parents:
918
diff
changeset
|
1817 fd->change->dest = g_strconcat(base, extension, NULL); |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1818 file_data_update_planned_change_hash(fd, old_path, fd->change->dest); |
806 | 1819 |
899
5d9c0b4e6d5f
fixed the case when a renamed file is detected by directory scanning
nadvornik
parents:
896
diff
changeset
|
1820 g_free(old_path); |
751 | 1821 g_free(base); |
590 | 1822 } |
1823 | |
751 | 1824 static void file_data_sc_update_ci(FileData *fd, const gchar *dest_path) |
590 | 1825 { |
1826 GList *work; | |
751 | 1827 gchar *dest_path_full = NULL; |
806 | 1828 |
590 | 1829 if (fd->parent) fd = fd->parent; |
1830 | |
995 | 1831 if (!dest_path) |
934 | 1832 { |
1833 dest_path = fd->path; | |
1834 } | |
1835 else if (!strchr(dest_path, G_DIR_SEPARATOR)) /* we got only filename, not a full path */ | |
751 | 1836 { |
1837 gchar *dir = remove_level_from_path(fd->path); | |
806 | 1838 |
751 | 1839 dest_path_full = g_build_filename(dir, dest_path, NULL); |
1840 g_free(dir); | |
1841 dest_path = dest_path_full; | |
1842 } | |
934 | 1843 else if (fd->change->type != FILEDATA_CHANGE_RENAME && isdir(dest_path)) /* rename should not move files between directories */ |
751 | 1844 { |
1845 dest_path_full = g_build_filename(dest_path, fd->name, NULL); | |
1846 dest_path = dest_path_full; | |
1847 } | |
806 | 1848 |
1849 file_data_update_ci_dest(fd, dest_path); | |
751 | 1850 |
590 | 1851 work = fd->sidecar_files; |
1852 while (work) | |
1853 { | |
1854 FileData *sfd = work->data; | |
806 | 1855 |
590 | 1856 file_data_update_ci_dest_preserve_ext(sfd, dest_path); |
1857 work = work->next; | |
1858 } | |
806 | 1859 |
751 | 1860 g_free(dest_path_full); |
590 | 1861 } |
1862 | |
1422 | 1863 static gboolean file_data_sc_check_update_ci(FileData *fd, const gchar *dest_path, FileDataChangeType type) |
590 | 1864 { |
950 | 1865 if (!file_data_sc_check_ci(fd, type)) return FALSE; |
590 | 1866 file_data_sc_update_ci(fd, dest_path); |
1867 return TRUE; | |
1868 } | |
1869 | |
1422 | 1870 gboolean file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path) |
950 | 1871 { |
1872 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_COPY); | |
1873 } | |
1874 | |
1422 | 1875 gboolean file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path) |
950 | 1876 { |
1877 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_MOVE); | |
1878 } | |
1879 | |
1422 | 1880 gboolean file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path) |
590 | 1881 { |
950 | 1882 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_RENAME); |
590 | 1883 } |
1884 | |
1422 | 1885 gboolean file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path) |
753 | 1886 { |
950 | 1887 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_UNSPECIFIED); |
753 | 1888 } |
1889 | |
950 | 1890 static gboolean file_data_sc_update_ci_list_call_func(GList *fd_list, |
1891 const gchar *dest, | |
1892 gboolean (*func)(FileData *, const gchar *)) | |
751 | 1893 { |
1894 GList *work; | |
1895 gboolean ret = TRUE; | |
806 | 1896 |
751 | 1897 work = fd_list; |
1898 while (work) | |
1899 { | |
1900 FileData *fd = work->data; | |
806 | 1901 |
950 | 1902 if (!func(fd, dest)) ret = FALSE; |
751 | 1903 work = work->next; |
1904 } | |
806 | 1905 |
751 | 1906 return ret; |
1907 } | |
1908 | |
950 | 1909 gboolean file_data_sc_update_ci_move_list(GList *fd_list, const gchar *dest) |
1910 { | |
1911 return file_data_sc_update_ci_list_call_func(fd_list, dest, file_data_sc_update_ci_move); | |
1912 } | |
1913 | |
751 | 1914 gboolean file_data_sc_update_ci_copy_list(GList *fd_list, const gchar *dest) |
1915 { | |
950 | 1916 return file_data_sc_update_ci_list_call_func(fd_list, dest, file_data_sc_update_ci_copy); |
751 | 1917 } |
1918 | |
753 | 1919 gboolean file_data_sc_update_ci_unspecified_list(GList *fd_list, const gchar *dest) |
1920 { | |
950 | 1921 return file_data_sc_update_ci_list_call_func(fd_list, dest, file_data_sc_update_ci_unspecified); |
753 | 1922 } |
1923 | |
590 | 1924 |
1925 /* | |
929 | 1926 * verify source and dest paths - dest image exists, etc. |
590 | 1927 * it should detect all possible problems with the planned operation |
1928 */ | |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
1929 |
928 | 1930 gint file_data_verify_ci(FileData *fd) |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
1931 { |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
1932 gint ret = CHANGE_OK; |
929 | 1933 gchar *dir; |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
1934 |
942 | 1935 if (!fd->change) |
1936 { | |
1937 DEBUG_1("Change checked: no change info: %s", fd->path); | |
995 | 1938 return ret; |
942 | 1939 } |
929 | 1940 |
1224 | 1941 if (!isname(fd->path)) |
929 | 1942 { |
1943 /* this probably should not happen */ | |
1944 ret |= CHANGE_NO_SRC; | |
1945 DEBUG_1("Change checked: file does not exist: %s", fd->path); | |
995 | 1946 return ret; |
929 | 1947 } |
1948 | |
1949 dir = remove_level_from_path(fd->path); | |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
1950 |
995 | 1951 if (fd->change->type != FILEDATA_CHANGE_DELETE && |
1662
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1952 fd->change->type != FILEDATA_CHANGE_MOVE && /* the unsaved metadata should survive move and rename operations */ |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1953 fd->change->type != FILEDATA_CHANGE_RENAME && |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1954 fd->change->type != FILEDATA_CHANGE_WRITE_METADATA && |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1955 fd->modified_xmp) |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1956 { |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1957 ret |= CHANGE_WARN_UNSAVED_META; |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1958 DEBUG_1("Change checked: unsaved metadata: %s", fd->path); |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1959 } |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1960 |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
1961 if (fd->change->type != FILEDATA_CHANGE_DELETE && |
1211 | 1962 fd->change->type != FILEDATA_CHANGE_WRITE_METADATA && |
929 | 1963 !access_file(fd->path, R_OK)) |
1964 { | |
1965 ret |= CHANGE_NO_READ_PERM; | |
1966 DEBUG_1("Change checked: no read permission: %s", fd->path); | |
1967 } | |
1968 else if ((fd->change->type == FILEDATA_CHANGE_DELETE || fd->change->type == FILEDATA_CHANGE_MOVE) && | |
995 | 1969 !access_file(dir, W_OK)) |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
1970 { |
929 | 1971 ret |= CHANGE_NO_WRITE_PERM_DIR; |
1972 DEBUG_1("Change checked: source dir is readonly: %s", fd->path); | |
1973 } | |
995 | 1974 else if (fd->change->type != FILEDATA_CHANGE_COPY && |
1975 fd->change->type != FILEDATA_CHANGE_UNSPECIFIED && | |
1211 | 1976 fd->change->type != FILEDATA_CHANGE_WRITE_METADATA && |
995 | 1977 !access_file(fd->path, W_OK)) |
929 | 1978 { |
1979 ret |= CHANGE_WARN_NO_WRITE_PERM; | |
1980 DEBUG_1("Change checked: no write permission: %s", fd->path); | |
1981 } | |
1211 | 1982 /* WRITE_METADATA is special because it can be configured to silently write to ~/.geeqie/... |
1983 - that means that there are no hard errors and warnings can be disabled | |
1224 | 1984 - the destination is determined during the check |
1211 | 1985 */ |
1224 | 1986 else if (fd->change->type == FILEDATA_CHANGE_WRITE_METADATA) |
1211 | 1987 { |
1224 | 1988 /* determine destination file */ |
1989 gboolean have_dest = FALSE; | |
1990 gchar *dest_dir = NULL; | |
1991 | |
1992 if (options->metadata.save_in_image_file) | |
1211 | 1993 { |
1224 | 1994 if (file_data_can_write_directly(fd)) |
1995 { | |
1996 /* we can write the file directly */ | |
1997 if (access_file(fd->path, W_OK)) | |
1998 { | |
1999 have_dest = TRUE; | |
2000 } | |
2001 else | |
2002 { | |
2003 if (options->metadata.warn_on_write_problems) | |
2004 { | |
2005 ret |= CHANGE_WARN_NO_WRITE_PERM; | |
2006 DEBUG_1("Change checked: file is not writable: %s", fd->path); | |
2007 } | |
2008 } | |
2009 } | |
2010 else if (file_data_can_write_sidecar(fd)) | |
2011 { | |
2012 /* we can write sidecar */ | |
2013 gchar *sidecar = file_data_get_sidecar_path(fd, FALSE); | |
2014 if (access_file(sidecar, W_OK) || (!isname(sidecar) && access_file(dir, W_OK))) | |
2015 { | |
2016 file_data_update_ci_dest(fd, sidecar); | |
2017 have_dest = TRUE; | |
2018 } | |
2019 else | |
2020 { | |
2021 if (options->metadata.warn_on_write_problems) | |
2022 { | |
2023 ret |= CHANGE_WARN_NO_WRITE_PERM; | |
2024 DEBUG_1("Change checked: file is not writable: %s", sidecar); | |
2025 } | |
2026 } | |
2027 g_free(sidecar); | |
2028 } | |
1211 | 2029 } |
2030 | |
1224 | 2031 if (!have_dest) |
1211 | 2032 { |
1224 | 2033 /* write private metadata file under ~/.geeqie */ |
2034 | |
2035 /* If an existing metadata file exists, we will try writing to | |
2036 * it's location regardless of the user's preference. | |
2037 */ | |
1667 | 2038 gchar *metadata_path = NULL; |
2039 #ifdef HAVE_EXIV2 | |
2040 /* but ignore XMP if we are not able to write it */ | |
2041 metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path); | |
2042 #endif | |
1224 | 2043 if (!metadata_path) metadata_path = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
2044 | |
2045 if (metadata_path && !access_file(metadata_path, W_OK)) | |
2046 { | |
2047 g_free(metadata_path); | |
2048 metadata_path = NULL; | |
2049 } | |
2050 | |
2051 if (!metadata_path) | |
2052 { | |
2053 mode_t mode = 0755; | |
2054 | |
2055 dest_dir = cache_get_location(CACHE_TYPE_METADATA, fd->path, FALSE, &mode); | |
2056 if (recursive_mkdir_if_not_exists(dest_dir, mode)) | |
2057 { | |
2058 gchar *filename = g_strconcat(fd->name, options->metadata.save_legacy_format ? GQ_CACHE_EXT_METADATA : GQ_CACHE_EXT_XMP_METADATA, NULL); | |
2059 | |
2060 metadata_path = g_build_filename(dest_dir, filename, NULL); | |
2061 g_free(filename); | |
2062 } | |
2063 } | |
2064 if (access_file(metadata_path, W_OK) || (!isname(metadata_path) && access_file(dest_dir, W_OK))) | |
2065 { | |
2066 file_data_update_ci_dest(fd, metadata_path); | |
2067 have_dest = TRUE; | |
2068 } | |
2069 else | |
2070 { | |
2071 ret |= CHANGE_NO_WRITE_PERM_DEST; | |
2072 DEBUG_1("Change checked: file is not writable: %s", metadata_path); | |
2073 } | |
2074 g_free(metadata_path); | |
1211 | 2075 } |
1224 | 2076 g_free(dest_dir); |
1211 | 2077 } |
2078 | |
1224 | 2079 if (fd->change->dest && fd->change->type != FILEDATA_CHANGE_WRITE_METADATA) |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2080 { |
953 | 2081 gboolean same; |
951 | 2082 gchar *dest_dir; |
955 | 2083 |
953 | 2084 same = (strcmp(fd->path, fd->change->dest) == 0); |
2085 | |
955 | 2086 if (!same) |
933 | 2087 { |
955 | 2088 const gchar *dest_ext = extension_from_path(fd->change->dest); |
2089 if (!dest_ext) dest_ext = ""; | |
933 | 2090 |
1307 | 2091 if (g_ascii_strcasecmp(fd->extension, dest_ext) != 0) |
955 | 2092 { |
2093 ret |= CHANGE_WARN_CHANGED_EXT; | |
2094 DEBUG_1("Change checked: source and destination have different extensions: %s -> %s", fd->path, fd->change->dest); | |
2095 } | |
2096 } | |
2097 else | |
933 | 2098 { |
955 | 2099 if (fd->change->type != FILEDATA_CHANGE_UNSPECIFIED) /* FIXME this is now needed for running editors */ |
2100 { | |
2101 ret |= CHANGE_WARN_SAME; | |
2102 DEBUG_1("Change checked: source and destination are the same: %s -> %s", fd->path, fd->change->dest); | |
2103 } | |
2104 } | |
933 | 2105 |
951 | 2106 dest_dir = remove_level_from_path(fd->change->dest); |
2107 | |
995 | 2108 if (!isdir(dest_dir)) |
929 | 2109 { |
2110 ret |= CHANGE_NO_DEST_DIR; | |
2111 DEBUG_1("Change checked: destination dir does not exist: %s -> %s", fd->path, fd->change->dest); | |
2112 } | |
2113 else if (!access_file(dest_dir, W_OK)) | |
2114 { | |
2115 ret |= CHANGE_NO_WRITE_PERM_DEST_DIR; | |
2116 DEBUG_1("Change checked: destination dir is readonly: %s -> %s", fd->path, fd->change->dest); | |
2117 } | |
955 | 2118 else if (!same) |
929 | 2119 { |
955 | 2120 if (isfile(fd->change->dest)) |
952 | 2121 { |
955 | 2122 if (!access_file(fd->change->dest, W_OK)) |
2123 { | |
2124 ret |= CHANGE_NO_WRITE_PERM_DEST; | |
2125 DEBUG_1("Change checked: destination file exists and is readonly: %s -> %s", fd->path, fd->change->dest); | |
2126 } | |
2127 else | |
2128 { | |
2129 ret |= CHANGE_WARN_DEST_EXISTS; | |
2130 DEBUG_1("Change checked: destination exists: %s -> %s", fd->path, fd->change->dest); | |
2131 } | |
952 | 2132 } |
955 | 2133 else if (isdir(fd->change->dest)) |
952 | 2134 { |
955 | 2135 ret |= CHANGE_DEST_EXISTS; |
952 | 2136 DEBUG_1("Change checked: destination exists: %s -> %s", fd->path, fd->change->dest); |
2137 } | |
929 | 2138 } |
951 | 2139 |
2140 g_free(dest_dir); | |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2141 } |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2142 |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2143 fd->change->error = ret; |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2144 if (ret == 0) DEBUG_1("Change checked: OK: %s", fd->path); |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2145 |
929 | 2146 g_free(dir); |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2147 return ret; |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2148 } |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2149 |
995 | 2150 |
928 | 2151 gint file_data_sc_verify_ci(FileData *fd) |
590 | 2152 { |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2153 GList *work; |
928 | 2154 gint ret; |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2155 |
928 | 2156 ret = file_data_verify_ci(fd); |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2157 |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2158 work = fd->sidecar_files; |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2159 while (work) |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2160 { |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2161 FileData *sfd = work->data; |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2162 |
928 | 2163 ret |= file_data_verify_ci(sfd); |
914
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2164 work = work->next; |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2165 } |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2166 |
9427c91951e8
basic infrastructure for early error and dangerous operations checking
nadvornik
parents:
913
diff
changeset
|
2167 return ret; |
590 | 2168 } |
2169 | |
928 | 2170 gchar *file_data_get_error_string(gint error) |
2171 { | |
2172 GString *result = g_string_new(""); | |
590 | 2173 |
929 | 2174 if (error & CHANGE_NO_SRC) |
2175 { | |
2176 if (result->len > 0) g_string_append(result, ", "); | |
2177 g_string_append(result, _("file or directory does not exist")); | |
2178 } | |
2179 | |
2180 if (error & CHANGE_DEST_EXISTS) | |
2181 { | |
2182 if (result->len > 0) g_string_append(result, ", "); | |
2183 g_string_append(result, _("destination already exists")); | |
2184 } | |
2185 | |
2186 if (error & CHANGE_NO_WRITE_PERM_DEST) | |
2187 { | |
2188 if (result->len > 0) g_string_append(result, ", "); | |
2189 g_string_append(result, _("destination can't be overwritten")); | |
2190 } | |
2191 | |
2192 if (error & CHANGE_NO_WRITE_PERM_DEST_DIR) | |
2193 { | |
2194 if (result->len > 0) g_string_append(result, ", "); | |
2195 g_string_append(result, _("destination directory is not writable")); | |
2196 } | |
2197 | |
2198 if (error & CHANGE_NO_DEST_DIR) | |
2199 { | |
2200 if (result->len > 0) g_string_append(result, ", "); | |
2201 g_string_append(result, _("destination directory does not exist")); | |
2202 } | |
2203 | |
2204 if (error & CHANGE_NO_WRITE_PERM_DIR) | |
2205 { | |
2206 if (result->len > 0) g_string_append(result, ", "); | |
2207 g_string_append(result, _("source directory is not writable")); | |
2208 } | |
2209 | |
2210 if (error & CHANGE_NO_READ_PERM) | |
928 | 2211 { |
2212 if (result->len > 0) g_string_append(result, ", "); | |
2213 g_string_append(result, _("no read permission")); | |
2214 } | |
2215 | |
929 | 2216 if (error & CHANGE_WARN_NO_WRITE_PERM) |
928 | 2217 { |
2218 if (result->len > 0) g_string_append(result, ", "); | |
929 | 2219 g_string_append(result, _("file is readonly")); |
2220 } | |
2221 | |
2222 if (error & CHANGE_WARN_DEST_EXISTS) | |
2223 { | |
2224 if (result->len > 0) g_string_append(result, ", "); | |
2225 g_string_append(result, _("destination already exists and will be overwritten")); | |
2226 } | |
933 | 2227 |
929 | 2228 if (error & CHANGE_WARN_SAME) |
2229 { | |
2230 if (result->len > 0) g_string_append(result, ", "); | |
948 | 2231 g_string_append(result, _("source and destination are the same")); |
928 | 2232 } |
2233 | |
933 | 2234 if (error & CHANGE_WARN_CHANGED_EXT) |
2235 { | |
2236 if (result->len > 0) g_string_append(result, ", "); | |
2237 g_string_append(result, _("source and destination have different extension")); | |
2238 } | |
2239 | |
1662
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
2240 if (error & CHANGE_WARN_UNSAVED_META) |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
2241 { |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
2242 if (result->len > 0) g_string_append(result, ", "); |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
2243 g_string_append(result, _("there are unsaved metadata changes for the file")); |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
2244 } |
7a4034d32503
warn if another operation is performed on a file with unsaved metadata
nadvornik
parents:
1649
diff
changeset
|
2245 |
928 | 2246 return g_string_free(result, FALSE); |
2247 } | |
2248 | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
2249 gint file_data_verify_ci_list(GList *list, gchar **desc, gboolean with_sidecars) |
928 | 2250 { |
956 | 2251 GList *work; |
928 | 2252 gint all_errors = 0; |
995 | 2253 gint common_errors = ~0; |
928 | 2254 gint num; |
2255 gint *errors; | |
2256 gint i; | |
2257 | |
2258 if (!list) return 0; | |
2259 | |
2260 num = g_list_length(list); | |
2261 errors = g_new(int, num); | |
956 | 2262 work = list; |
928 | 2263 i = 0; |
2264 while (work) | |
2265 { | |
2266 FileData *fd; | |
2267 gint error; | |
2268 | |
2269 fd = work->data; | |
2270 work = work->next; | |
2271 | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
2272 error = with_sidecars ? file_data_sc_verify_ci(fd) : file_data_verify_ci(fd); |
928 | 2273 all_errors |= error; |
2274 common_errors &= error; | |
2275 | |
2276 errors[i] = error; | |
2277 | |
2278 i++; | |
2279 } | |
2280 | |
2281 if (desc && all_errors) | |
2282 { | |
956 | 2283 GList *work; |
928 | 2284 GString *result = g_string_new(""); |
2285 | |
2286 if (common_errors) | |
2287 { | |
2288 gchar *str = file_data_get_error_string(common_errors); | |
2289 g_string_append(result, str); | |
2290 g_string_append(result, "\n"); | |
2291 g_free(str); | |
2292 } | |
2293 | |
956 | 2294 work = list; |
928 | 2295 i = 0; |
2296 while (work) | |
2297 { | |
2298 FileData *fd; | |
2299 gint error; | |
2300 | |
2301 fd = work->data; | |
2302 work = work->next; | |
2303 | |
2304 error = errors[i] & ~common_errors; | |
2305 | |
2306 if (error) | |
2307 { | |
2308 gchar *str = file_data_get_error_string(error); | |
2309 g_string_append_printf(result, "%s: %s\n", fd->name, str); | |
2310 g_free(str); | |
2311 } | |
2312 i++; | |
2313 } | |
2314 *desc = g_string_free(result, FALSE); | |
2315 } | |
2316 | |
2317 g_free(errors); | |
2318 return all_errors; | |
2319 } | |
590 | 2320 |
2321 | |
2322 /* | |
2323 * perform the change described by FileFataChangeInfo | |
995 | 2324 * it is used for internal operations, |
590 | 2325 * this function actually operates with files on the filesystem |
2326 * it should implement safe delete | |
2327 */ | |
995 | 2328 |
590 | 2329 static gboolean file_data_perform_move(FileData *fd) |
2330 { | |
2331 g_assert(!strcmp(fd->change->source, fd->path)); | |
2332 return move_file(fd->change->source, fd->change->dest); | |
2333 } | |
2334 | |
2335 static gboolean file_data_perform_copy(FileData *fd) | |
2336 { | |
2337 g_assert(!strcmp(fd->change->source, fd->path)); | |
2338 return copy_file(fd->change->source, fd->change->dest); | |
2339 } | |
2340 | |
2341 static gboolean file_data_perform_delete(FileData *fd) | |
2342 { | |
896
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
892
diff
changeset
|
2343 if (isdir(fd->path) && !islink(fd->path)) |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
892
diff
changeset
|
2344 return rmdir_utf8(fd->path); |
cf21dc928122
implemented directory rename and delete operations
nadvornik
parents:
892
diff
changeset
|
2345 else |
1212 | 2346 if (options->file_ops.safe_delete_enable) |
2347 return file_util_safe_unlink(fd->path); | |
2348 else | |
2349 return unlink_file(fd->path); | |
590 | 2350 } |
2351 | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
2352 gboolean file_data_perform_ci(FileData *fd) |
590 | 2353 { |
2354 FileDataChangeType type = fd->change->type; | |
1422 | 2355 |
590 | 2356 switch (type) |
2357 { | |
2358 case FILEDATA_CHANGE_MOVE: | |
2359 return file_data_perform_move(fd); | |
2360 case FILEDATA_CHANGE_COPY: | |
2361 return file_data_perform_copy(fd); | |
2362 case FILEDATA_CHANGE_RENAME: | |
2363 return file_data_perform_move(fd); /* the same as move */ | |
2364 case FILEDATA_CHANGE_DELETE: | |
2365 return file_data_perform_delete(fd); | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
2366 case FILEDATA_CHANGE_WRITE_METADATA: |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
2367 return metadata_write_perform(fd); |
753 | 2368 case FILEDATA_CHANGE_UNSPECIFIED: |
596 | 2369 /* nothing to do here */ |
590 | 2370 break; |
2371 } | |
2372 return TRUE; | |
2373 } | |
2374 | |
2375 | |
2376 | |
2377 gboolean file_data_sc_perform_ci(FileData *fd) | |
2378 { | |
2379 GList *work; | |
2380 gboolean ret = TRUE; | |
2381 FileDataChangeType type = fd->change->type; | |
806 | 2382 |
590 | 2383 if (!file_data_sc_check_ci(fd, type)) return FALSE; |
2384 | |
2385 work = fd->sidecar_files; | |
2386 while (work) | |
2387 { | |
2388 FileData *sfd = work->data; | |
806 | 2389 |
590 | 2390 if (!file_data_perform_ci(sfd)) ret = FALSE; |
2391 work = work->next; | |
2392 } | |
806 | 2393 |
590 | 2394 if (!file_data_perform_ci(fd)) ret = FALSE; |
806 | 2395 |
590 | 2396 return ret; |
2397 } | |
2398 | |
2399 /* | |
2400 * updates FileData structure according to FileDataChangeInfo | |
2401 */ | |
912
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
2402 |
1422 | 2403 gboolean file_data_apply_ci(FileData *fd) |
590 | 2404 { |
2405 FileDataChangeType type = fd->change->type; | |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
2406 |
590 | 2407 /* FIXME delete ?*/ |
773 | 2408 if (type == FILEDATA_CHANGE_MOVE || type == FILEDATA_CHANGE_RENAME) |
590 | 2409 { |
912
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
2410 DEBUG_1("planned change: applying %s -> %s", fd->change->dest, fd->path); |
9108a7158c02
remove items from file_data_planned_change_hash when the operation is
nadvornik
parents:
910
diff
changeset
|
2411 file_data_planned_change_remove(fd); |
915 | 2412 |
2413 if (g_hash_table_lookup(file_data_pool, fd->change->dest)) | |
2414 { | |
2415 /* this change overwrites another file which is already known to other modules | |
2416 renaming fd would create duplicate FileData structure | |
2417 the best thing we can do is nothing | |
2418 FIXME: maybe we could copy stuff like marks | |
2419 */ | |
2420 DEBUG_1("can't rename fd, target exists %s -> %s", fd->change->dest, fd->path); | |
2421 } | |
2422 else | |
2423 { | |
1722 | 2424 file_data_set_path(fd, fd->change->dest); |
915 | 2425 } |
590 | 2426 } |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
2427 file_data_increment_version(fd); |
1432 | 2428 file_data_send_notification(fd, NOTIFY_CHANGE); |
1205
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
2429 |
3ff2aa99108b
use the workflow in utilops.c for metadata approving and writting
nadvornik
parents:
1055
diff
changeset
|
2430 return TRUE; |
590 | 2431 } |
2432 | |
1422 | 2433 gboolean file_data_sc_apply_ci(FileData *fd) |
590 | 2434 { |
2435 GList *work; | |
2436 FileDataChangeType type = fd->change->type; | |
806 | 2437 |
590 | 2438 if (!file_data_sc_check_ci(fd, type)) return FALSE; |
2439 | |
2440 work = fd->sidecar_files; | |
2441 while (work) | |
2442 { | |
2443 FileData *sfd = work->data; | |
806 | 2444 |
590 | 2445 file_data_apply_ci(sfd); |
2446 work = work->next; | |
2447 } | |
806 | 2448 |
590 | 2449 file_data_apply_ci(fd); |
806 | 2450 |
590 | 2451 return TRUE; |
2452 } | |
2453 | |
1619 | 2454 static gboolean file_data_list_contains_whole_group(GList *list, FileData *fd) |
2455 { | |
2456 GList *work; | |
2457 if (fd->parent) fd = fd->parent; | |
2458 if (!g_list_find(list, fd)) return FALSE; | |
2459 | |
2460 work = fd->sidecar_files; | |
2461 while (work) | |
2462 { | |
2463 if (!g_list_find(list, work->data)) return FALSE; | |
2464 work = work->next; | |
2465 } | |
2466 return TRUE; | |
2467 } | |
2468 | |
2469 #if 0 | |
2470 static gboolean file_data_list_dump(GList *list) | |
2471 { | |
2472 GList *work, *work2; | |
2473 | |
2474 work = list; | |
2475 while (work) | |
2476 { | |
2477 FileData *fd = work->data; | |
2478 printf("%s\n", fd->name); | |
2479 work2 = fd->sidecar_files; | |
2480 while (work2) | |
2481 { | |
2482 FileData *fd = work2->data; | |
2483 printf(" %s\n", fd->name); | |
2484 work2 = work2->next; | |
2485 } | |
2486 work = work->next; | |
2487 } | |
2488 return TRUE; | |
2489 } | |
2490 #endif | |
2491 | |
2492 GList *file_data_process_groups(GList *list) | |
2493 { | |
2494 GList *out = NULL; | |
2495 GList *work = list; | |
2496 | |
2497 /* change partial groups to independent files */ | |
2498 while (work) | |
2499 { | |
2500 FileData *fd = work->data; | |
2501 work = work->next; | |
2502 | |
2503 if (!file_data_list_contains_whole_group(list, fd)) | |
2504 file_data_disable_grouping(fd, TRUE); | |
2505 } | |
2506 | |
2507 /* remove sidecars from the list, | |
2508 they can be still acessed via main_fd->sidecar_files */ | |
2509 work = list; | |
2510 while (work) | |
2511 { | |
2512 FileData *fd = work->data; | |
2513 work = work->next; | |
2514 | |
2515 if (!fd->parent) | |
2516 { | |
2517 out = g_list_prepend(out, fd); | |
2518 } | |
2519 else | |
2520 { | |
2521 file_data_unref(fd); | |
2522 } | |
2523 } | |
2524 | |
2525 g_list_free(list); | |
2526 out = g_list_reverse(out); | |
2527 | |
2528 return out; | |
2529 } | |
2530 | |
2531 | |
2532 | |
2533 | |
2534 | |
590 | 2535 /* |
1619 | 2536 * notify other modules about the change described by FileDataChangeInfo |
590 | 2537 */ |
995 | 2538 |
590 | 2539 /* might use file_maint_ functions for now, later it should be changed to a system of callbacks |
2540 FIXME do we need the ignore_list? It looks like a workaround for ineffective | |
2541 implementation in view_file_list.c */ | |
2542 | |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2543 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2544 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2545 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2546 typedef struct _NotifyData NotifyData; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2547 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2548 struct _NotifyData { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2549 FileDataNotifyFunc func; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2550 gpointer data; |
791 | 2551 NotifyPriority priority; |
1422 | 2552 }; |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2553 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2554 static GList *notify_func_list = NULL; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2555 |
791 | 2556 static gint file_data_notify_sort(gconstpointer a, gconstpointer b) |
2557 { | |
2558 NotifyData *nda = (NotifyData *)a; | |
2559 NotifyData *ndb = (NotifyData *)b; | |
806 | 2560 |
791 | 2561 if (nda->priority < ndb->priority) return -1; |
2562 if (nda->priority > ndb->priority) return 1; | |
2563 return 0; | |
2564 } | |
2565 | |
1422 | 2566 gboolean file_data_register_notify_func(FileDataNotifyFunc func, gpointer data, NotifyPriority priority) |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2567 { |
806 | 2568 NotifyData *nd; |
1709 | 2569 GList *work = notify_func_list; |
2570 | |
2571 while (work) | |
2572 { | |
2573 NotifyData *nd = (NotifyData *)work->data; | |
2574 | |
2575 if (nd->func == func && nd->data == data) | |
2576 { | |
2577 g_warning("Notify func already registered"); | |
2578 return FALSE; | |
2579 } | |
2580 work = work->next; | |
2581 } | |
806 | 2582 |
2583 nd = g_new(NotifyData, 1); | |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2584 nd->func = func; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2585 nd->data = data; |
791 | 2586 nd->priority = priority; |
806 | 2587 |
791 | 2588 notify_func_list = g_list_insert_sorted(notify_func_list, nd, file_data_notify_sort); |
1498 | 2589 DEBUG_2("Notify func registered: %p", nd); |
806 | 2590 |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2591 return TRUE; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2592 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2593 |
1422 | 2594 gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data) |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2595 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2596 GList *work = notify_func_list; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2597 |
806 | 2598 while (work) |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2599 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2600 NotifyData *nd = (NotifyData *)work->data; |
806 | 2601 |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2602 if (nd->func == func && nd->data == data) |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2603 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2604 notify_func_list = g_list_delete_link(notify_func_list, work); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2605 g_free(nd); |
1498 | 2606 DEBUG_2("Notify func unregistered: %p", nd); |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2607 return TRUE; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2608 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2609 work = work->next; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2610 } |
806 | 2611 |
1709 | 2612 g_warning("Notify func not found"); |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2613 return FALSE; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2614 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2615 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2616 |
792 | 2617 void file_data_send_notification(FileData *fd, NotifyType type) |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2618 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2619 GList *work = notify_func_list; |
806 | 2620 |
2621 while (work) | |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2622 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2623 NotifyData *nd = (NotifyData *)work->data; |
806 | 2624 |
792 | 2625 nd->func(fd, type, nd->data); |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2626 work = work->next; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2627 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2628 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
2629 |
791 | 2630 static GHashTable *file_data_monitor_pool = NULL; |
1523 | 2631 static guint realtime_monitor_id = 0; /* event source id */ |
791 | 2632 |
2633 static void realtime_monitor_check_cb(gpointer key, gpointer value, gpointer data) | |
2634 { | |
2635 FileData *fd = key; | |
2636 | |
801 | 2637 file_data_check_changed_files(fd); |
791 | 2638 |
2639 DEBUG_1("monitor %s", fd->path); | |
2640 } | |
2641 | |
2642 static gboolean realtime_monitor_cb(gpointer data) | |
2643 { | |
903
c93823609f15
periodic testing of changed files can be now disabled
nadvornik
parents:
899
diff
changeset
|
2644 if (!options->update_on_time_change) return TRUE; |
791 | 2645 g_hash_table_foreach(file_data_monitor_pool, realtime_monitor_check_cb, NULL); |
2646 return TRUE; | |
2647 } | |
2648 | |
1422 | 2649 gboolean file_data_register_real_time_monitor(FileData *fd) |
791 | 2650 { |
950 | 2651 gint count; |
791 | 2652 |
2653 file_data_ref(fd); | |
2654 | |
2655 if (!file_data_monitor_pool) | |
2656 file_data_monitor_pool = g_hash_table_new(g_direct_hash, g_direct_equal); | |
2657 | |
2658 count = GPOINTER_TO_INT(g_hash_table_lookup(file_data_monitor_pool, fd)); | |
2659 | |
2660 DEBUG_1("Register realtime %d %s", count, fd->path); | |
2661 | |
2662 count++; | |
2663 g_hash_table_insert(file_data_monitor_pool, fd, GINT_TO_POINTER(count)); | |
2664 | |
1523 | 2665 if (!realtime_monitor_id) |
791 | 2666 { |
2667 realtime_monitor_id = g_timeout_add(5000, realtime_monitor_cb, NULL); | |
2668 } | |
806 | 2669 |
791 | 2670 return TRUE; |
2671 } | |
2672 | |
1422 | 2673 gboolean file_data_unregister_real_time_monitor(FileData *fd) |
791 | 2674 { |
2675 gint count; | |
806 | 2676 |
791 | 2677 g_assert(file_data_monitor_pool); |
2678 | |
2679 count = GPOINTER_TO_INT(g_hash_table_lookup(file_data_monitor_pool, fd)); | |
2680 | |
2681 DEBUG_1("Unregister realtime %d %s", count, fd->path); | |
2682 | |
2683 g_assert(count > 0); | |
2684 | |
2685 count--; | |
2686 | |
2687 if (count == 0) | |
2688 g_hash_table_remove(file_data_monitor_pool, fd); | |
2689 else | |
2690 g_hash_table_insert(file_data_monitor_pool, fd, GINT_TO_POINTER(count)); | |
2691 | |
2692 file_data_unref(fd); | |
2693 | |
2694 if (g_hash_table_size(file_data_monitor_pool) == 0) | |
2695 { | |
2696 g_source_remove(realtime_monitor_id); | |
1523 | 2697 realtime_monitor_id = 0; |
791 | 2698 return FALSE; |
2699 } | |
806 | 2700 |
791 | 2701 return TRUE; |
2702 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1023
diff
changeset
|
2703 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |