From cd490d12a7e5fe5e936fa7a4da4bfb7ff9eadfc9 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 21 Dec 2015 11:12:25 +0100 Subject: [PATCH] XdgAppDir: Touch .changes file each time something changes --- app/xdg-app-builtins-add-remote.c | 6 ++++++ app/xdg-app-builtins-delete-remote.c | 3 +++ app/xdg-app-builtins-install.c | 9 +++++++++ app/xdg-app-builtins-make-current.c | 3 +++ app/xdg-app-builtins-uninstall.c | 6 ++++++ app/xdg-app-builtins-update.c | 6 ++++++ common/xdg-app-dir.c | 25 +++++++++++++++++++++++++ common/xdg-app-dir.h | 3 +++ lib/xdg-app-installation.c | 9 +++++++++ 9 files changed, 70 insertions(+) diff --git a/app/xdg-app-builtins-add-remote.c b/app/xdg-app-builtins-add-remote.c index 01091a78..fa460999 100644 --- a/app/xdg-app-builtins-add-remote.c +++ b/app/xdg-app-builtins-add-remote.c @@ -237,6 +237,9 @@ xdg_app_builtin_add_remote (int argc, char **argv, if (!import_keys (dir, remote_name, cancellable, error)) return FALSE; + if (!xdg_app_dir_mark_changed (dir, error)) + return FALSE; + return TRUE; } @@ -301,5 +304,8 @@ xdg_app_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable, if (!import_keys (dir, remote_name, cancellable, error)) return FALSE; + if (!xdg_app_dir_mark_changed (dir, error)) + return FALSE; + return TRUE; } diff --git a/app/xdg-app-builtins-delete-remote.c b/app/xdg-app-builtins-delete-remote.c index 6da68ef3..e4057c88 100644 --- a/app/xdg-app-builtins-delete-remote.c +++ b/app/xdg-app-builtins-delete-remote.c @@ -54,5 +54,8 @@ xdg_app_builtin_delete_remote (int argc, char **argv, GCancellable *cancellable, cancellable, error)) return FALSE; + if (!xdg_app_dir_mark_changed (dir, error)) + return FALSE; + return TRUE; } diff --git a/app/xdg-app-builtins-install.c b/app/xdg-app-builtins-install.c index e7c5bc75..2d777d98 100644 --- a/app/xdg-app-builtins-install.c +++ b/app/xdg-app-builtins-install.c @@ -167,6 +167,9 @@ xdg_app_builtin_install_runtime (int argc, char **argv, GCancellable *cancellabl xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir, error)) + goto out; + ret = TRUE; out: @@ -251,6 +254,9 @@ xdg_app_builtin_install_app (int argc, char **argv, GCancellable *cancellable, G xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir, error)) + goto out; + ret = TRUE; out: @@ -504,6 +510,9 @@ xdg_app_builtin_install_bundle (int argc, char **argv, GCancellable *cancellable xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir, error)) + goto out; + ret = TRUE; out: diff --git a/app/xdg-app-builtins-make-current.c b/app/xdg-app-builtins-make-current.c index 40732023..e434812f 100644 --- a/app/xdg-app-builtins-make-current.c +++ b/app/xdg-app-builtins-make-current.c @@ -80,5 +80,8 @@ xdg_app_builtin_make_current_app (int argc, char **argv, GCancellable *cancellab glnx_release_lock_file (&lock); + if (!xdg_app_dir_mark_changed (dir, error)) + return FALSE; + return TRUE; } diff --git a/app/xdg-app-builtins-uninstall.c b/app/xdg-app-builtins-uninstall.c index 605e6cc6..1d8cbb44 100644 --- a/app/xdg-app-builtins-uninstall.c +++ b/app/xdg-app-builtins-uninstall.c @@ -101,6 +101,9 @@ xdg_app_builtin_uninstall_runtime (int argc, char **argv, GCancellable *cancella xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir, error)) + return FALSE; + if (!was_deployed) return xdg_app_fail (error, "Nothing to uninstall"); @@ -173,6 +176,9 @@ xdg_app_builtin_uninstall_app (int argc, char **argv, GCancellable *cancellable, xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir, error)) + return FALSE; + if (!was_deployed) return xdg_app_fail (error, "Nothing to uninstall"); diff --git a/app/xdg-app-builtins-update.c b/app/xdg-app-builtins-update.c index 37831e2a..bf1e8615 100644 --- a/app/xdg-app-builtins-update.c +++ b/app/xdg-app-builtins-update.c @@ -105,6 +105,9 @@ xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir, error)) + return FALSE; + return TRUE; } @@ -173,5 +176,8 @@ xdg_app_builtin_update_app (int argc, char **argv, GCancellable *cancellable, GE xdg_app_dir_cleanup_removed (dir, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir, error)) + return FALSE; + return TRUE; } diff --git a/common/xdg-app-dir.c b/common/xdg-app-dir.c index b3ff8ba2..a2b4e21a 100644 --- a/common/xdg-app-dir.c +++ b/common/xdg-app-dir.c @@ -263,6 +263,12 @@ xdg_app_dir_get_path (XdgAppDir *self) return self->basedir; } +GFile * +xdg_app_dir_get_changed_path (XdgAppDir *self) +{ + return g_file_get_child (self->basedir, ".changed"); +} + char * xdg_app_dir_load_override (XdgAppDir *self, const char *app_id, @@ -549,6 +555,9 @@ xdg_app_dir_ensure_repo (XdgAppDir *self, gs_shutil_rm_rf (repodir, cancellable, NULL); goto out; } + + /* Create .changes file early to avoid polling non-existing file in monitor */ + xdg_app_dir_mark_changed (self, NULL); } else { @@ -570,6 +579,22 @@ xdg_app_dir_ensure_repo (XdgAppDir *self, return ret; } +gboolean +xdg_app_dir_mark_changed (XdgAppDir *self, + GError **error) +{ + g_autoptr(GFile) changed_file = NULL; + + g_print ("mark changed\n"); + changed_file = xdg_app_dir_get_changed_path (self); + if (!g_file_replace_contents (changed_file, "", 0, NULL, FALSE, + G_FILE_CREATE_REPLACE_DESTINATION, NULL, NULL, error)) + return FALSE; + g_print ("OK\n"); + + return TRUE; +} + gboolean xdg_app_dir_pull (XdgAppDir *self, const char *repository, diff --git a/common/xdg-app-dir.h b/common/xdg-app-dir.h index 0447f274..76847daf 100644 --- a/common/xdg-app-dir.h +++ b/common/xdg-app-dir.h @@ -76,6 +76,7 @@ XdgAppDir *xdg_app_dir_get_system (void); XdgAppDir *xdg_app_dir_get_user (void); gboolean xdg_app_dir_is_user (XdgAppDir *self); GFile * xdg_app_dir_get_path (XdgAppDir *self); +GFile * xdg_app_dir_get_changed_path (XdgAppDir *self); GFile * xdg_app_dir_get_deploy_dir (XdgAppDir *self, const char *ref); char * xdg_app_dir_get_origin (XdgAppDir *self, @@ -109,6 +110,8 @@ gboolean xdg_app_dir_ensure_path (XdgAppDir *self, gboolean xdg_app_dir_ensure_repo (XdgAppDir *self, GCancellable *cancellable, GError **error); +gboolean xdg_app_dir_mark_changed (XdgAppDir *self, + GError **error); gboolean xdg_app_dir_pull (XdgAppDir *self, const char *repository, const char *ref, diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c index a4d89d19..c92856be 100644 --- a/lib/xdg-app-installation.c +++ b/lib/xdg-app-installation.c @@ -753,6 +753,9 @@ xdg_app_installation_install (XdgAppInstallation *self, xdg_app_dir_cleanup_removed (dir_clone, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir_clone, error)) + goto out; + out: if (main_context) g_main_context_pop_thread_default (main_context); @@ -867,6 +870,9 @@ xdg_app_installation_update (XdgAppInstallation *self, { if (!xdg_app_dir_prune (dir_clone, cancellable, error)) goto out; + + if (!xdg_app_dir_mark_changed (dir_clone, error)) + goto out; } xdg_app_dir_cleanup_removed (dir_clone, cancellable, NULL); @@ -961,6 +967,9 @@ xdg_app_installation_uninstall (XdgAppInstallation *self, xdg_app_dir_cleanup_removed (dir_clone, cancellable, NULL); + if (!xdg_app_dir_mark_changed (dir_clone, error)) + return FALSE; + if (!was_deployed) { g_set_error (error,