Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow summary file race #490

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apidoc/ostree-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ ostree_repo_verify_commit
ostree_repo_verify_commit_ext
ostree_repo_verify_summary
ostree_repo_regenerate_summary
ostree_repo_regenerate_summary_ext
<SUBSECTION Standard>
OSTREE_REPO
OSTREE_IS_REPO
Expand Down
9 changes: 7 additions & 2 deletions src/libostree/libostree.sym
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,14 @@ global:
* NOTE NOTE NOTE
*/

LIBOSTREE_2016.10 {
global:
ostree_repo_regenerate_summary_ext;
} LIBOSTREE_2016.8;

/* Remove comment when first new symbol is added
LIBOSTREE_2016.10
LIBOSTREE_2016.11 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the patch is just weirdly rendered, but it looks like the new function gets called .10 and the old that .11.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a little weirdness in the ostree symbols file plus weirdness in symbol version files in general. This part is in a comment with a fake symbol waiting for the next release. My addition is above in the .10 section that chains to the .8 section. There's a little extra noise in this patch because the commented out .10 section prior to this patch (there weren't any new symbols yet) was missing the trailing {.

global:
someostree_symbol_deleteme;
} LIBOSTREE_2016.8;
} LIBOSTREE_2016.10;
* Remove comment when first new symbol is added */
94 changes: 94 additions & 0 deletions src/libostree/ostree-repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4784,6 +4784,100 @@ ostree_repo_regenerate_summary (OstreeRepo *self,
return ret;
}


/**
* ostree_repo_regenerate_summary_ext:
* @self: Repo
* @additional_metadata: (allow-none): A GVariant of type a{sv}, or %NULL
* @key_id: (array zero-terminated=1) (element-type utf8): NULL-terminated array of GPG keys.
* @homedir: (allow-none): GPG home directory, or %NULL
* @cancellable: Cancellable
* @error: Error
*
* An OSTree repository can contain a high level "summary" file that
* describes the available branches and other metadata.
*
* It is regenerated automatically after a commit if
* `core/commit-update-summary` is set.
*
* This extended variant allows specifying GPG key IDs to sign the
* summary file before it's committed.
*/
gboolean
ostree_repo_regenerate_summary_ext (OstreeRepo *self,
GVariant *additional_metadata,
const gchar **key_id,
const gchar *homedir,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
g_autofree char *tmpdir_name_template = g_strdup("summary-XXXXXX");
glnx_fd_close int summary_tmpdir_fd = -1;

if (!glnx_mkdtempat (self->tmp_dir_fd, tmpdir_name_template, 0777, error))
goto out;

if (!glnx_opendirat (self->tmp_dir_fd, tmpdir_name_template, FALSE,
&summary_tmpdir_fd, error))
goto out;

/* Generate the summary and optional signature file in the tmpdir */
if (!internal_repo_regenerate_summary (self, summary_tmpdir_fd,
additional_metadata,
cancellable, error))
goto out;

if (key_id &&
!internal_repo_add_gpg_signature_summary (self, summary_tmpdir_fd,
key_id, homedir,
cancellable, error))
goto out;

/* Rename them into place */
if (renameat (summary_tmpdir_fd, "summary",
self->repo_dir_fd, "summary") == -1)
{
glnx_set_prefix_error_from_errno (error, "%s",
"Unable to rename summary file");
goto out;
}
if (key_id)
{
if (renameat (summary_tmpdir_fd, "summary.sig",
self->repo_dir_fd, "summary.sig") == -1)
{
glnx_set_prefix_error_from_errno (error, "%s",
"Unable to rename summary signature file");

/* Delete an existing signature since it no longer corresponds
* to the summary
*/
(void) ot_ensure_unlinked_at (self->repo_dir_fd, "summary.sig", NULL);

goto out;
}
}
else
{
/* Delete an existing signature since it no longer corresponds to
* the summary
*/
if (!ot_ensure_unlinked_at (self->repo_dir_fd, "summary.sig", NULL))
{
g_prefix_error (error, "Unable to delete summary signature file: ");
goto out;
}
}

ret = TRUE;
out:
/* Always cleanup the tmpdir */
(void) glnx_shutil_rm_rf_at (self->tmp_dir_fd, tmpdir_name_template,
NULL, NULL);
return ret;
}

gboolean
_ostree_repo_is_locked_tmpdir (const char *filename)
{
Expand Down
8 changes: 8 additions & 0 deletions src/libostree/ostree-repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,14 @@ gboolean ostree_repo_regenerate_summary (OstreeRepo *self,
GCancellable *cancellable,
GError **error);

_OSTREE_PUBLIC
gboolean ostree_repo_regenerate_summary_ext (OstreeRepo *self,
GVariant *additional_metadata,
const gchar **key_id,
const gchar *homedir,
GCancellable *cancellable,
GError **error);


G_END_DECLS

Expand Down