Skip to content

Commit

Permalink
config: Add a core/change-update-summary option
Browse files Browse the repository at this point in the history
This commits adds and implements a boolean repo config option called
"change-update-summary" which updates the summary file every time a ref
changes (additions, updates, and deletions).

The main impetus for this feature is that the `ostree create-usb` and
`flatpak create-usb` commands depend on the repo summary being up to
date. On the command line you can work around this by asking the user to
run `ostree summary --update` but in the case of GNOME Software calling
out to `flatpak create-usb` this wouldn't work because it's running as a
user and the repo is owned by root. That strategy also means flatpak
can't update the repo metadata refs for fear of invalidating the
summary.

Another use case for this relates to LAN updates. Specifically, the
component of eos-updater that generates DNS-SD records advertising ostree
refs depends on the repo summary being up to date.

Since ostree_repo_regenerate_summary() now takes an exclusive lock, this
should be safe to enable. However it's not enabled by default because of
the performance cost, and because it's more useful on clients than
servers (which likely have another mechanism for updating the summary).

Fixes #1664
  • Loading branch information
mwleeds committed Jul 16, 2018
1 parent 4e2e127 commit 83baafa
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 14 deletions.
8 changes: 8 additions & 0 deletions man/ostree.repo-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ Boston, MA 02111-1307, USA.
to <literal>false</literal>.</para></listitem>
</varlistentry>

<varlistentry>
<term><varname>change-update-summary</varname></term>
<listitem><para>Boolean value controlling whether or not to
automatically update the summary file after any ref is added,
removed, or updated. Defaults to <literal>false</literal>.
</para></listitem>
</varlistentry>

<varlistentry>
<term><varname>fsync</varname></term>
<listitem><para>Boolean value controlling whether or not to
Expand Down
15 changes: 15 additions & 0 deletions src/libostree/ostree-repo-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,21 @@ _ostree_repo_write_ref (OstreeRepo *self,
return FALSE;
}

{
gboolean update_summary;

if (!ot_keyfile_get_boolean_with_default (self->config, "core",
"change-update-summary", FALSE,
&update_summary, error))
return FALSE;

if (update_summary && !ostree_repo_regenerate_summary (self,
NULL,
cancellable,
error))
return FALSE;
}

if (!_ostree_repo_update_mtime (self, error))
return FALSE;

Expand Down
3 changes: 2 additions & 1 deletion src/libostree/ostree-repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -5377,7 +5377,8 @@ summary_add_ref_entry (OstreeRepo *self,
* will aid clients in working out when to check for updates.
*
* It is regenerated automatically after a commit if
* `core/commit-update-summary` is set.
* `core/commit-update-summary` is set, and automatically after any ref is
* added, removed, or updated if `core/change-update-summary` is set.
*
* If the `core/collection-id` key is set in the configuration, it will be
* included as %OSTREE_SUMMARY_COLLECTION_ID in the summary file. Refs that
Expand Down
37 changes: 24 additions & 13 deletions src/ostree/ot-builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio

if (!skip_commit)
{
gboolean update_summary;
guint64 timestamp;
gboolean change_update_summary;

if (!opt_no_bindings)
{
Expand Down Expand Up @@ -824,21 +824,32 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error))
goto out;

/* The default for this option is FALSE, even for archive repos,
* because ostree supports multiple processes committing to the same
* repo (but different refs) concurrently, and in fact gnome-continuous
* actually does this. In that context it's best to update the summary
* explicitly instead of automatically here. */
if (!ot_keyfile_get_boolean_with_default (ostree_repo_get_config (repo), "core",
"commit-update-summary", FALSE,
&update_summary, error))
"change-update-summary", FALSE,
&change_update_summary, error))
goto out;

if (update_summary && !ostree_repo_regenerate_summary (repo,
NULL,
cancellable,
error))
goto out;
/* No need to update it again if we did for each ref change */
if (opt_orphan || !change_update_summary)
{
gboolean commit_update_summary;

/* The default for this option is FALSE, even for archive repos,
* because ostree supports multiple processes committing to the same
* repo (but different refs) concurrently, and in fact gnome-continuous
* actually does this. In that context it's best to update the summary
* explicitly instead of automatically here. */
if (!ot_keyfile_get_boolean_with_default (ostree_repo_get_config (repo), "core",
"commit-update-summary", FALSE,
&commit_update_summary, error))
goto out;

if (commit_update_summary && !ostree_repo_regenerate_summary (repo,
NULL,
cancellable,
error))
goto out;
}
}
else
{
Expand Down
34 changes: 34 additions & 0 deletions tests/test-auto-summary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ echo "1..4"
setup_test_repository "bare"
echo "ok setup"

# Check that without commit-update-summary set, creating a commit doesn't update the summary
mkdir test

echo hello > test/a
Expand All @@ -47,6 +48,7 @@ echo "ok commit 2"

assert_streq "$OLD_MD5" "$(md5sum repo/summary)"

# Check that with commit-update-summary set, creating a commit updates the summary
$OSTREE --repo=repo config set core.commit-update-summary true

echo hello3 > test/a
Expand All @@ -60,3 +62,35 @@ assert_not_streq "$OLD_MD5" "$(md5sum repo/summary)"
touch repo/summary.sig
$OSTREE summary --update
assert_not_has_file repo/summary.sig

# Check that without change-update-summary set, deleting or changing a ref doesn't update the summary
$OSTREE summary --update
OLD_MD5=$(md5sum repo/summary)
$OSTREE reset test test^

assert_streq "$OLD_MD5" "$(md5sum repo/summary)"

$OSTREE summary --update
OLD_MD5=$(md5sum repo/summary)
$OSTREE refs --delete test

assert_streq "$OLD_MD5" "$(md5sum repo/summary)"

# Check that with change-update-summary set, deleting or changing a ref updates the summary
$OSTREE --repo=repo config set core.change-update-summary true

echo hello > test/a
$OSTREE commit -b test -s "A commit" test
echo hello2 > test/a
$OSTREE commit -b test -s "Another commit" test

$OSTREE summary --update
OLD_MD5=$(md5sum repo/summary)
$OSTREE reset test test^

assert_not_streq "$OLD_MD5" "$(md5sum repo/summary)"

OLD_MD5=$(md5sum repo/summary)
$OSTREE refs --delete test

assert_not_streq "$OLD_MD5" "$(md5sum repo/summary)"

0 comments on commit 83baafa

Please sign in to comment.