summaryrefslogtreecommitdiff
path: root/plugins
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 /plugins
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 'plugins')
-rw-r--r--plugins/font-thumbnailer/font-thumbnailer.c8
-rw-r--r--plugins/xdg-cache/xdg-cache-cache.c27
-rw-r--r--plugins/xdg-cache/xdg-cache-cache.h4
-rw-r--r--plugins/xdg-cache/xdg-cache-thumbnail.c16
4 files changed, 28 insertions, 27 deletions
diff --git a/plugins/font-thumbnailer/font-thumbnailer.c b/plugins/font-thumbnailer/font-thumbnailer.c
index 4b83046..04b3bcc 100644
--- a/plugins/font-thumbnailer/font-thumbnailer.c
+++ b/plugins/font-thumbnailer/font-thumbnailer.c
@@ -438,7 +438,6 @@ font_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
GdkPixbuf *pixbuf;
FT_Error ft_error;
FT_Face face;
- guint64 mtime;
GError *error = NULL;
GFile *file;
gchar *error_msg;
@@ -558,9 +557,6 @@ font_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
/* release the font face */
FT_Done_Face (face);
- /* determine when the URI was last modified */
- mtime = tumbler_file_info_get_mtime (info);
-
/* compose the image data */
data.data = gdk_pixbuf_get_pixels (pixbuf);
data.has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
@@ -571,7 +567,9 @@ font_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
data.colorspace = (TumblerColorspace) gdk_pixbuf_get_colorspace (pixbuf);
/* save the thumbnail */
- tumbler_thumbnail_save_image_data (thumbnail, &data, mtime, NULL, &error);
+ tumbler_thumbnail_save_image_data (thumbnail, &data,
+ tumbler_file_info_get_mtime (info),
+ NULL, &error);
/* check if there was an error */
if (error != NULL)
diff --git a/plugins/xdg-cache/xdg-cache-cache.c b/plugins/xdg-cache/xdg-cache-cache.c
index e029cd8..69a07e6 100644
--- a/plugins/xdg-cache/xdg-cache-cache.c
+++ b/plugins/xdg-cache/xdg-cache-cache.c
@@ -50,7 +50,7 @@ static TumblerThumbnail *xdg_cache_cache_get_thumbnail (TumblerCache
TumblerThumbnailFlavor *flavor);
static void xdg_cache_cache_cleanup (TumblerCache *cache,
const gchar *const *base_uris,
- guint64 since);
+ gdouble since);
static void xdg_cache_cache_delete (TumblerCache *cache,
const gchar *const *uris);
static void xdg_cache_cache_copy (TumblerCache *cache,
@@ -174,11 +174,11 @@ xdg_cache_cache_get_thumbnail (TumblerCache *cache,
static void
xdg_cache_cache_cleanup (TumblerCache *cache,
const gchar *const *base_uris,
- guint64 since)
+ gdouble since)
{
XDGCacheCache *xdg_cache = XDG_CACHE_CACHE (cache);
const gchar *file_basename;
- guint64 mtime;
+ gdouble mtime;
GFile *base_file;
GFile *dummy_file;
GFile *original_file;
@@ -323,7 +323,7 @@ xdg_cache_cache_copy_or_move_file (TumblerCache *cache,
gboolean do_copy,
const gchar *from_uri,
const gchar *to_uri,
- guint64 mtime)
+ gdouble mtime)
{
GFile *from_file;
GFile *temp_file;
@@ -392,7 +392,7 @@ xdg_cache_cache_copy_or_move (TumblerCache *cache,
{
XDGCacheCache *xdg_cache = XDG_CACHE_CACHE (cache);
GFileInfo *info;
- guint64 mtime;
+ gdouble mtime;
GFile *dest_source_file;
GList *iter;
guint n;
@@ -417,8 +417,9 @@ xdg_cache_cache_copy_or_move (TumblerCache *cache,
{
dest_source_file = g_file_new_for_uri (to_uris[n]);
info = g_file_query_info (dest_source_file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE ","
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE
+ "," G_FILE_ATTRIBUTE_TIME_MODIFIED
+ "," G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
G_FILE_QUERY_INFO_NONE, NULL, NULL);
if (info == NULL)
@@ -492,7 +493,9 @@ xdg_cache_cache_copy_or_move (TumblerCache *cache,
}
else
{
- mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)
+ + 1e-6 * g_file_info_get_attribute_uint32 (info,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
xdg_cache_cache_copy_or_move_file (cache, iter->data, do_copy,
from_uris[n], to_uris[n],
mtime);
@@ -664,7 +667,7 @@ xdg_cache_cache_get_temp_file (const gchar *uri,
gboolean
xdg_cache_cache_read_thumbnail_info (const gchar *filename,
gchar **uri,
- guint64 *mtime,
+ gdouble *mtime,
GCancellable *cancellable,
GError **error)
{
@@ -743,7 +746,7 @@ xdg_cache_cache_read_thumbnail_info (const gchar *filename,
/* remember the Thumb::MTime value */
if (text_ptr[i].text != NULL)
{
- *mtime = atol (text_ptr[i].text);
+ *mtime = g_ascii_strtod (text_ptr[i].text, NULL);
has_mtime = TRUE;
}
}
@@ -767,7 +770,7 @@ xdg_cache_cache_read_thumbnail_info (const gchar *filename,
gboolean
xdg_cache_cache_write_thumbnail_info (const gchar *filename,
const gchar *uri,
- guint64 mtime,
+ gdouble mtime,
GCancellable *cancellable,
GError **error)
{
@@ -788,7 +791,7 @@ xdg_cache_cache_write_thumbnail_info (const gchar *filename,
{
if (!g_cancellable_set_error_if_cancelled (cancellable, &err))
{
- mtime_str = g_strdup_printf ("%" G_GUINT64_FORMAT, mtime);
+ mtime_str = g_strdup_printf ("%.6f", mtime);
gdk_pixbuf_save (pixbuf, filename, "png", &err,
"tEXt::Thumb::URI", uri,
diff --git a/plugins/xdg-cache/xdg-cache-cache.h b/plugins/xdg-cache/xdg-cache-cache.h
index b2037e9..e05a992 100644
--- a/plugins/xdg-cache/xdg-cache-cache.h
+++ b/plugins/xdg-cache/xdg-cache-cache.h
@@ -46,12 +46,12 @@ GFile *xdg_cache_cache_get_temp_file (const gchar *uri,
TumblerThumbnailFlavor *flavor) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
gboolean xdg_cache_cache_read_thumbnail_info (const gchar *filename,
gchar **uri,
- guint64 *mtime,
+ gdouble *mtime,
GCancellable *cancellable,
GError **error);
gboolean xdg_cache_cache_write_thumbnail_info (const gchar *filename,
const gchar *uri,
- guint64 mtime,
+ gdouble mtime,
GCancellable *cancellable,
GError **error);
diff --git a/plugins/xdg-cache/xdg-cache-thumbnail.c b/plugins/xdg-cache/xdg-cache-thumbnail.c
index 19d8083..cf2cf58 100644
--- a/plugins/xdg-cache/xdg-cache-thumbnail.c
+++ b/plugins/xdg-cache/xdg-cache-thumbnail.c
@@ -66,10 +66,10 @@ static gboolean xdg_cache_thumbnail_load (TumblerThumbnail *thu
GError **error);
static gboolean xdg_cache_thumbnail_needs_update (TumblerThumbnail *thumbnail,
const gchar *uri,
- guint64 mtime);
+ gdouble mtime);
static gboolean xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail,
TumblerImageData *data,
- guint64 mtime,
+ gdouble mtime,
GCancellable *cancellable,
GError **error);
@@ -88,7 +88,7 @@ struct _XDGCacheThumbnail
XDGCacheCache *cache;
gchar *uri;
gchar *cached_uri;
- guint64 cached_mtime;
+ gdouble cached_mtime;
};
@@ -269,7 +269,7 @@ xdg_cache_thumbnail_load (TumblerThumbnail *thumbnail,
static gboolean
has_valid_shared_thumbnail (const gchar *uri,
const gchar *size,
- guint64 mtime)
+ gdouble mtime)
{
gchar *thumbnail_path;
gboolean found;
@@ -278,7 +278,7 @@ has_valid_shared_thumbnail (const gchar *uri,
if (g_file_test (thumbnail_path, G_FILE_TEST_EXISTS))
{
- guint64 thumb_mtime;
+ gdouble thumb_mtime;
gchar *thumb_uri;
if (xdg_cache_cache_read_thumbnail_info (thumbnail_path, &thumb_uri, &thumb_mtime, NULL, NULL))
@@ -300,7 +300,7 @@ has_valid_shared_thumbnail (const gchar *uri,
static gboolean
xdg_cache_thumbnail_needs_update (TumblerThumbnail *thumbnail,
const gchar *uri,
- guint64 mtime)
+ gdouble mtime)
{
XDGCacheThumbnail *cache_thumbnail = XDG_CACHE_THUMBNAIL (thumbnail);
gboolean is_valid = TRUE;
@@ -330,7 +330,7 @@ xdg_cache_thumbnail_needs_update (TumblerThumbnail *thumbnail,
static gboolean
xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail,
TumblerImageData *data,
- guint64 mtime,
+ gdouble mtime,
GCancellable *cancellable,
GError **error)
{
@@ -398,7 +398,7 @@ xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail,
if (stream != NULL)
{
/* convert the modified time of the source URI to a string */
- mtime_str = g_strdup_printf ("%" G_GUINT64_FORMAT, mtime);
+ mtime_str = g_strdup_printf ("%.6f", mtime);
/* try to save the pixbuf */
if (gdk_pixbuf_save_to_stream (dest_pixbuf, G_OUTPUT_STREAM (stream), "png",