xdg-app-dir: Move exports to update_exports

During installation of an app we rewrite and clean up the
deployed export directory, but don't actually export it.

Instead we export only the "current" version of the application
when we run update_exports (passing in which app changed). This way
we ensure that any newly exported files in the current app are exported
before we remove all dangling symlinks.

To make the symlinks properly dangle we also make the export symlinks
point use the "current" and "active" symlinks so non-current deployed
dirs don't keep an old symlink from being removed.
This commit is contained in:
Alexander Larsson 2015-03-11 09:53:47 +01:00
parent c71c8d0b5b
commit db191015d4
6 changed files with 40 additions and 20 deletions

View File

@ -167,7 +167,7 @@ xdg_app_builtin_install_app (int argc, char **argv, GCancellable *cancellable, G
if (!xdg_app_dir_make_current_ref (dir, ref, cancellable, error))
goto out;
if (!xdg_app_dir_update_exports (dir, cancellable, error))
if (!xdg_app_dir_update_exports (dir, app, cancellable, error))
goto out;
xdg_app_dir_cleanup_removed (dir, cancellable, NULL);

View File

@ -67,6 +67,9 @@ xdg_app_builtin_make_current_app (int argc, char **argv, GCancellable *cancellab
if (!xdg_app_dir_make_current_ref (dir, ref, cancellable, error))
goto out;
if (!xdg_app_dir_update_exports (dir, app, cancellable, error))
goto out;
ret = TRUE;
out:

View File

@ -244,7 +244,7 @@ xdg_app_builtin_uninstall_app (int argc, char **argv, GCancellable *cancellable,
if (!gs_shutil_rm_rf (deploy_base, cancellable, error))
goto out;
if (!xdg_app_dir_update_exports (dir, cancellable, error))
if (!xdg_app_dir_update_exports (dir, name, cancellable, error))
goto out;
g_debug ("cleaning up empty directories");

View File

@ -196,7 +196,7 @@ xdg_app_builtin_update_app (int argc, char **argv, GCancellable *cancellable, GE
goto out;
}
if (!xdg_app_dir_update_exports (dir, cancellable, error))
if (!xdg_app_dir_update_exports (dir, app, cancellable, error))
goto out;
ret = TRUE;

View File

@ -1095,23 +1095,50 @@ xdg_app_export_dir (GFile *source,
gboolean
xdg_app_dir_update_exports (XdgAppDir *self,
const char *changed_app,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
gs_unref_object GFile *exports = NULL;
gs_free char *current_ref = NULL;
gs_free char *active_id = NULL;
gs_free char *symlink_prefix = NULL;
exports = xdg_app_dir_get_exports_dir (self);
if (g_file_query_exists (exports, cancellable))
{
if (!xdg_app_remove_dangling_symlinks (exports, cancellable, error))
goto out;
if (!gs_file_ensure_directory (exports, TRUE, cancellable, error))
goto out;
if (!xdg_app_dir_run_triggers (self, cancellable, error))
goto out;
if (changed_app &&
(current_ref = xdg_app_dir_current_ref (self, changed_app, cancellable)) &&
(active_id = xdg_app_dir_read_active (self, current_ref, cancellable)))
{
gs_unref_object GFile *deploy_base = NULL;
gs_unref_object GFile *active = NULL;
gs_unref_object GFile *export = NULL;
deploy_base = xdg_app_dir_get_deploy_dir (self, current_ref);
active = g_file_get_child (deploy_base, active_id);
export = g_file_get_child (active, "export");
if (g_file_query_exists (export, cancellable))
{
symlink_prefix = g_build_filename ("..", "app", changed_app, "current", "active", "export", NULL);
if (!xdg_app_export_dir (export, exports,
symlink_prefix,
cancellable,
error))
goto out;
}
}
if (!xdg_app_remove_dangling_symlinks (exports, cancellable, error))
goto out;
if (!xdg_app_dir_run_triggers (self, cancellable, error))
goto out;
ret = TRUE;
out:
@ -1238,8 +1265,6 @@ xdg_app_dir_deploy (XdgAppDir *self,
export = g_file_get_child (checkoutdir, "export");
if (g_file_query_exists (export, cancellable))
{
gs_free char *relative_path = NULL;
gs_free char *symlink_prefix = NULL;
gs_strfreev char **ref_parts = NULL;
ref_parts = g_strsplit (ref, "/", -1);
@ -1248,15 +1273,6 @@ xdg_app_dir_deploy (XdgAppDir *self,
cancellable,
error))
goto out;
relative_path = g_file_get_relative_path (self->basedir, export);
symlink_prefix = g_build_filename ("..", relative_path, NULL);
if (!xdg_app_export_dir (export, exports,
symlink_prefix,
cancellable,
error))
goto out;
}
if (!xdg_app_dir_set_active (self, ref, checksum, cancellable, error))

View File

@ -97,6 +97,7 @@ gboolean xdg_app_dir_undeploy (XdgAppDir *self,
GCancellable *cancellable,
GError **error);
gboolean xdg_app_dir_update_exports (XdgAppDir *self,
const char *app,
GCancellable *cancellable,
GError **error);
gboolean xdg_app_dir_prune (XdgAppDir *self,