From c0a18e38c8e97fe79907e98d2dfb94760293e71c Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 12 Feb 2016 13:03:24 +0100 Subject: [PATCH] Work around race when doing first initial appstream checkout. Whenever we finish the first update of appstream for a remote we touch the toplevel appstream directory. This avoids an race-like issue where you can't put a watch on the non-existant timestamp file for a remote before it is created. --- common/xdg-app-dir.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/xdg-app-dir.c b/common/xdg-app-dir.c index d7a4d913b..6f5c83295 100644 --- a/common/xdg-app-dir.c +++ b/common/xdg-app-dir.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include "libgsystem.h" @@ -617,6 +619,7 @@ xdg_app_dir_update_appstream (XdgAppDir *self, g_autoptr(GFile) active_link = NULL; g_autoptr(GFile) timestamp_file = NULL; g_autoptr(GError) tmp_error = NULL; + gboolean checkout_exists; if (!xdg_app_dir_ensure_repo (self, cancellable, error)) return FALSE; @@ -656,9 +659,11 @@ xdg_app_dir_update_appstream (XdgAppDir *self, return FALSE; } + checkout_exists = g_file_query_exists (checkout_dir, NULL); + if (old_checksum != NULL && new_checksum != NULL && strcmp (old_checksum, new_checksum) == 0 && - g_file_query_exists (checkout_dir, NULL)) + checkout_exists) { if (!g_file_replace_contents (timestamp_file, "", 0, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, NULL, error)) @@ -710,6 +715,14 @@ xdg_app_dir_update_appstream (XdgAppDir *self, G_FILE_CREATE_REPLACE_DESTINATION, NULL, NULL, error)) return FALSE; + /* If we added a new checkout, touch the toplevel dir to tell people that they need + to re-scan */ + if (!checkout_exists) + { + g_autofree char *appstream_dir_path = g_file_get_path (appstream_dir); + utime (appstream_dir_path, NULL); + } + if (out_changed) *out_changed = TRUE; return TRUE;