summaryrefslogtreecommitdiff
path: root/tumbler/tumbler-file-info.c
diff options
context:
space:
mode:
authorGaël Bonithon <gael@xfce.org>2021-12-18 16:06:04 +0100
committerGaël Bonithon <gael@xfce.org>2021-12-21 12:01:32 +0100
commita242e1324c7a3d1428e2a8ce58ee77c71967d8b7 (patch)
tree4b2dc8863594a79bdd06dbabe0d55ee2d4a1d6c7 /tumbler/tumbler-file-info.c
parentad432ab47e1ede51bee08af11daca69a9ca6a216 (diff)
downloadtumbler-a242e1324c7a3d1428e2a8ce58ee77c71967d8b7.tar.gz
Use microsecond precision for last modification time
When the file system allows it, this prevents Tumbler from believing that the original file has not been modified since the last time the thumbnail was created, when in fact modifications have taken place in the second that the thumbnail was created. The time of last modification is stored internally in a `gdouble`, and written to the PNG thumbnail in `%.6f` format. This complies well with the Freedesktop specification [1], as the stat command returns this format when invoked as `stat -c%.6Y file`, although it is likely that the specification was written with the idea that this value be an integer. The extraction of the thumbnail information is done via `g_ascii_strtod()`, so an integer or less precision is not a problem. As for a code expecting to find an integer, it is likely to simply ignore the decimal part, as Tumbler used to do by extracting the information via `atol()`. It is possible, however, that an error will be found if a more complete extractor is used, such as `strtol()`. The changes this causes to the exposed Tumbler APIs should also be inconsequential, as it is a conversion to a higher type. This should therefore result in implicit conversions, except perhaps for `tumbler_file_info_get_mtime()`, if its return value is explicitly stored in a `gint64`. [1] https://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#CREATION Fixes #15, see !20 for more details.
Diffstat (limited to 'tumbler/tumbler-file-info.c')
-rw-r--r--tumbler/tumbler-file-info.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/tumbler/tumbler-file-info.c b/tumbler/tumbler-file-info.c
index 7116658..9a32983 100644
--- a/tumbler/tumbler-file-info.c
+++ b/tumbler/tumbler-file-info.c
@@ -70,7 +70,7 @@ struct _TumblerFileInfo
TumblerThumbnailFlavor *flavor;
TumblerThumbnail *thumbnail;
- guint64 mtime;
+ gdouble mtime;
gchar *uri;
gchar *mime_type;
};
@@ -93,10 +93,10 @@ tumbler_file_info_class_init (TumblerFileInfoClass *klass)
gobject_class->set_property = tumbler_file_info_set_property;
g_object_class_install_property (gobject_class, PROP_MTIME,
- g_param_spec_uint64 ("mtime",
+ g_param_spec_double ("mtime",
"mtime",
"mtime",
- 0, G_MAXUINT64, 0,
+ 0, G_MAXDOUBLE, 0,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class, PROP_URI,
@@ -167,7 +167,7 @@ tumbler_file_info_get_property (GObject *object,
switch (prop_id)
{
case PROP_MTIME:
- g_value_set_uint64 (value, info->mtime);
+ g_value_set_double (value, info->mtime);
break;
case PROP_URI:
g_value_set_string (value, info->uri);
@@ -197,7 +197,7 @@ tumbler_file_info_set_property (GObject *object,
switch (prop_id)
{
case PROP_MTIME:
- info->mtime = g_value_get_uint64 (value);
+ info->mtime = g_value_get_double (value);
break;
case PROP_URI:
info->uri = g_value_dup_string (value);
@@ -249,7 +249,9 @@ tumbler_file_info_load (TumblerFileInfo *info,
file = g_file_new_for_uri (info->uri);
/* query the modified time from the file */
- file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED
+ "," G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
G_FILE_QUERY_INFO_NONE, cancellable, &err);
/* destroy the GFile */
@@ -263,8 +265,9 @@ tumbler_file_info_load (TumblerFileInfo *info,
}
/* read and remember the modified time */
- info->mtime = g_file_info_get_attribute_uint64 (file_info,
- G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ info->mtime = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED)
+ + 1e-6 * g_file_info_get_attribute_uint32 (file_info,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
/* we no longer need the file information */
g_object_unref (file_info);
@@ -341,7 +344,7 @@ tumbler_file_info_get_mime_type (TumblerFileInfo *info)
-guint64
+gdouble
tumbler_file_info_get_mtime (TumblerFileInfo *info)
{
g_return_val_if_fail (TUMBLER_IS_FILE_INFO (info), 0);