diff options
author | Gaël Bonithon <gael@xfce.org> | 2021-12-18 16:06:04 +0100 |
---|---|---|
committer | Gaël Bonithon <gael@xfce.org> | 2021-12-21 12:01:32 +0100 |
commit | a242e1324c7a3d1428e2a8ce58ee77c71967d8b7 (patch) | |
tree | 4b2dc8863594a79bdd06dbabe0d55ee2d4a1d6c7 /tumbler | |
parent | ad432ab47e1ede51bee08af11daca69a9ca6a216 (diff) | |
download | tumbler-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')
-rw-r--r-- | tumbler/tumbler-cache.c | 2 | ||||
-rw-r--r-- | tumbler/tumbler-cache.h | 4 | ||||
-rw-r--r-- | tumbler/tumbler-file-info.c | 21 | ||||
-rw-r--r-- | tumbler/tumbler-file-info.h | 2 | ||||
-rw-r--r-- | tumbler/tumbler-thumbnail.c | 6 | ||||
-rw-r--r-- | tumbler/tumbler-thumbnail.h | 12 |
6 files changed, 25 insertions, 22 deletions
diff --git a/tumbler/tumbler-cache.c b/tumbler/tumbler-cache.c index 627100e..ad22e35 100644 --- a/tumbler/tumbler-cache.c +++ b/tumbler/tumbler-cache.c @@ -105,7 +105,7 @@ tumbler_cache_get_thumbnail (TumblerCache *cache, void tumbler_cache_cleanup (TumblerCache *cache, const gchar *const *base_uris, - guint64 since) + gdouble since) { g_return_if_fail (TUMBLER_IS_CACHE (cache)); g_return_if_fail (TUMBLER_CACHE_GET_IFACE (cache)->cleanup != NULL); diff --git a/tumbler/tumbler-cache.h b/tumbler/tumbler-cache.h index f8aaeac..380def8 100644 --- a/tumbler/tumbler-cache.h +++ b/tumbler/tumbler-cache.h @@ -50,7 +50,7 @@ struct _TumblerCacheIface TumblerThumbnailFlavor *flavor); void (*cleanup) (TumblerCache *cache, const gchar *const *base_uris, - guint64 since); + gdouble since); void (*do_delete) (TumblerCache *cache, const gchar *const *uris); void (*copy) (TumblerCache *cache, @@ -73,7 +73,7 @@ TumblerThumbnail *tumbler_cache_get_thumbnail (TumblerCache *ca TumblerThumbnailFlavor *flavor) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; void tumbler_cache_cleanup (TumblerCache *cache, const gchar *const *base_uris, - guint64 since); + gdouble since); void tumbler_cache_delete (TumblerCache *cache, const gchar *const *uris); void tumbler_cache_copy (TumblerCache *cache, 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); diff --git a/tumbler/tumbler-file-info.h b/tumbler/tumbler-file-info.h index a1330c3..372d128 100644 --- a/tumbler/tumbler-file-info.h +++ b/tumbler/tumbler-file-info.h @@ -51,7 +51,7 @@ gboolean tumbler_file_info_load (TumblerFileInfo GError **error); const gchar *tumbler_file_info_get_uri (TumblerFileInfo *info); const gchar *tumbler_file_info_get_mime_type (TumblerFileInfo *info); -guint64 tumbler_file_info_get_mtime (TumblerFileInfo *info); +gdouble tumbler_file_info_get_mtime (TumblerFileInfo *info); gboolean tumbler_file_info_needs_update (TumblerFileInfo *info); TumblerThumbnail *tumbler_file_info_get_thumbnail (TumblerFileInfo *info) G_GNUC_WARN_UNUSED_RESULT; diff --git a/tumbler/tumbler-thumbnail.c b/tumbler/tumbler-thumbnail.c index 50734f6..29a3930 100644 --- a/tumbler/tumbler-thumbnail.c +++ b/tumbler/tumbler-thumbnail.c @@ -79,7 +79,7 @@ tumbler_thumbnail_load (TumblerThumbnail *thumbnail, gboolean tumbler_thumbnail_needs_update (TumblerThumbnail *thumbnail, const gchar *uri, - guint64 mtime) + gdouble mtime) { g_return_val_if_fail (TUMBLER_IS_THUMBNAIL (thumbnail), FALSE); g_return_val_if_fail (uri != NULL, FALSE); @@ -93,7 +93,7 @@ tumbler_thumbnail_needs_update (TumblerThumbnail *thumbnail, gboolean tumbler_thumbnail_save_image_data (TumblerThumbnail *thumbnail, TumblerImageData *data, - guint64 mtime, + gdouble mtime, GCancellable *cancellable, GError **error) { @@ -112,7 +112,7 @@ tumbler_thumbnail_save_image_data (TumblerThumbnail *thumbnail, gboolean tumbler_thumbnail_save_file (TumblerThumbnail *thumbnail, GFile *file, - guint64 mtime, + gdouble mtime, GCancellable *cancellable, GError **error) { diff --git a/tumbler/tumbler-thumbnail.h b/tumbler/tumbler-thumbnail.h index 8279073..b142e48 100644 --- a/tumbler/tumbler-thumbnail.h +++ b/tumbler/tumbler-thumbnail.h @@ -65,15 +65,15 @@ struct _TumblerThumbnailIface GError **error); gboolean (*needs_update) (TumblerThumbnail *thumbnail, const gchar *uri, - guint64 mtime); + gdouble mtime); gboolean (*save_image_data) (TumblerThumbnail *thumbnail, TumblerImageData *data, - guint64 mtime, + gdouble mtime, GCancellable *cancellable, GError **error); gboolean (*save_file) (TumblerThumbnail *thumbnail, GFile *file, - guint64 mtime, + gdouble mtime, GCancellable *cancellable, GError **error); }; @@ -85,15 +85,15 @@ gboolean tumbler_thumbnail_load (TumblerThumbnail GError **error); gboolean tumbler_thumbnail_needs_update (TumblerThumbnail *thumbnail, const gchar *uri, - guint64 mtime); + gdouble mtime); gboolean tumbler_thumbnail_save_image_data (TumblerThumbnail *thumbnail, TumblerImageData *data, - guint64 mtime, + gdouble mtime, GCancellable *cancellable, GError **error); gboolean tumbler_thumbnail_save_file (TumblerThumbnail *thumbnail, GFile *file, - guint64 mtime, + gdouble mtime, GCancellable *cancellable, GError **error); TumblerThumbnailFlavor *tumbler_thumbnail_get_flavor (TumblerThumbnail *thumbnail); |