@@ -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
0 commit comments