Skip to content

Commit 9080892

Browse files
committed
manage XMP sidecar files
1 parent 91396c1 commit 9080892

File tree

4 files changed

+785
-183
lines changed

4 files changed

+785
-183
lines changed

src/common/exif.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5860,6 +5860,7 @@ gboolean dt_exif_xmp_write(const dt_imgid_t imgid,
58605860
fprintf(fout, "%s", xml_header);
58615861
fprintf(fout, "%s", xmpPacket.c_str());
58625862
fclose(fout);
5863+
dt_diratime_action(filename, "update");
58635864
}
58645865
else
58655866
{

src/control/control.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,88 @@ void dt_control_set_mouse_over_id(const dt_imgid_t imgid)
937937
dt_pthread_mutex_unlock(&dc->global_mutex);
938938
}
939939

940+
time_t dt_diratime_action(const char *dir_path, const char *action)
941+
{
942+
time_t timestamp = 0;
943+
gchar *_dir = g_strdup(dir_path);
944+
size_t name_len = strlen(dir_path);
945+
const char *ext = dir_path + name_len - 4;
946+
if (!g_strcmp0(action, "update") && (!g_strcmp0(ext, ".xmp") || !g_strcmp0(ext, ".XMP")) && name_len > 4)
947+
{
948+
size_t len = strlen(dir_path);
949+
const char *c = dir_path + len;
950+
while((c > dir_path) && ((*c) != G_DIR_SEPARATOR)) c--;
951+
size_t vers_len = c - dir_path + 1;
952+
g_strlcpy(_dir, dir_path, vers_len + 1);
953+
}
954+
955+
GError *error = NULL;
956+
GFile *_g_dir = g_file_new_for_path(_dir);
957+
GFileInfo *info = g_file_query_info(_g_dir,
958+
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
959+
G_FILE_ATTRIBUTE_STANDARD_TYPE,
960+
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);
961+
const char *dirname = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
962+
963+
const char *dir_mark = g_strconcat(_dir, dirname, ".dt", NULL);
964+
time_t dir_mark_time = 0;
965+
966+
GFile *_g_dir_mark = g_file_new_for_path(dir_mark);
967+
if (!g_strcmp0(action, "create"))
968+
{
969+
if(!g_file_test(dir_mark, G_FILE_TEST_EXISTS))
970+
{
971+
GFileEnumerator *dir_files = g_file_enumerate_children(_g_dir,
972+
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
973+
G_FILE_ATTRIBUTE_TIME_MODIFIED ","
974+
G_FILE_ATTRIBUTE_STANDARD_TYPE,
975+
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
976+
if(dir_files)
977+
{
978+
while((info = g_file_enumerator_next_file(dir_files, NULL, &error)))
979+
{
980+
const char *filename = g_file_info_get_display_name(info);
981+
if(!filename) continue;
982+
const GFileType filetype = g_file_info_get_attribute_uint32(info, G_FILE_ATTRIBUTE_STANDARD_TYPE);
983+
if(filetype == G_FILE_TYPE_REGULAR)
984+
{
985+
name_len = strlen(filename);
986+
ext = filename + name_len - 4;
987+
if ((strcmp(ext, ".xmp") == 0 || strcmp(ext, ".XMP") == 0) && name_len > 4)
988+
{
989+
time_t _timestamp = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
990+
if (_timestamp > dir_mark_time)
991+
dir_mark_time = _timestamp;
992+
}
993+
}
994+
}
995+
}
996+
GFileOutputStream *out = g_file_replace(_g_dir_mark, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error);
997+
g_object_unref(out);
998+
info = g_file_query_info(_g_dir_mark,
999+
G_FILE_ATTRIBUTE_TIME_MODIFIED,
1000+
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
1001+
g_file_set_attribute_uint64(_g_dir_mark, G_FILE_ATTRIBUTE_TIME_MODIFIED, dir_mark_time, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,FALSE,&error);
1002+
g_object_unref(dir_files);
1003+
}
1004+
}
1005+
else if (!g_strcmp0(action, "update"))
1006+
{
1007+
GFileOutputStream *out = g_file_replace(_g_dir_mark, NULL, FALSE,
1008+
G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error);
1009+
g_object_unref(out);
1010+
}
1011+
info = g_file_query_info(_g_dir_mark,
1012+
G_FILE_ATTRIBUTE_TIME_MODIFIED,
1013+
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
1014+
timestamp = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
1015+
g_object_unref(info);
1016+
g_object_unref(_g_dir_mark);
1017+
g_object_unref(_g_dir);
1018+
1019+
return timestamp;
1020+
}
1021+
9401022
// clang-format off
9411023
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
9421024
// vim: shiftwidth=2 expandtab tabstop=2 cindent

src/control/control.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ gboolean dt_control_running(void);
260260
dt_imgid_t dt_control_get_mouse_over_id(void);
261261
void dt_control_set_mouse_over_id(const dt_imgid_t value);
262262

263+
/** actions on directory access mark file.
264+
'action' must be one of "create", "update"*/
265+
time_t dt_diratime_action(const char *dir_path, const char *action);
266+
263267
G_END_DECLS
264268

265269
// clang-format off

0 commit comments

Comments
 (0)