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

lib/commit: (refactor) Clean up delta bare write API #1283

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 3 additions & 16 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,31 +404,18 @@ add_size_index_to_metadata (OstreeRepo *self,
return g_variant_ref_sink (g_variant_builder_end (builder));
}

/* Combines a check for whether or not we already have the object with
* allocating a tempfile if we don't. Used by the static delta code.
/* Create a tmpfile for writing a bare file. Currently just used
* by the static delta code, but will likely later be extended
* to be used also by the dfd_iter commit path.
*/
gboolean
_ostree_repo_open_content_bare (OstreeRepo *self,
const char *checksum,
Copy link
Member

Choose a reason for hiding this comment

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

Can we update the preceding comment block too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep done ⬇️

guint64 content_len,
GLnxTmpfile *out_tmpf,
gboolean *out_have_object,
GCancellable *cancellable,
GError **error)
{
gboolean have_obj;
if (!_ostree_repo_has_loose_object (self, checksum, OSTREE_OBJECT_TYPE_FILE, &have_obj,
cancellable, error))
return FALSE;
/* Do we already have this object? */
*out_have_object = have_obj;
if (have_obj)
{
/* Make sure the tempfile is unset */
out_tmpf->initialized = 0;
return TRUE;
}

return glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY|O_CLOEXEC,
out_tmpf, error);
}
Expand Down
1 change: 0 additions & 1 deletion src/libostree/ostree-repo-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ _ostree_repo_open_content_bare (OstreeRepo *self,
const char *checksum,
guint64 content_len,
GLnxTmpfile *out_tmpf,
gboolean *out_have_object,
GCancellable *cancellable,
GError **error);

Expand Down
30 changes: 19 additions & 11 deletions src/libostree/ostree-repo-static-delta-processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,15 +583,18 @@ dispatch_open_splice_and_close (OstreeRepo *repo,
if (S_ISREG (state->mode) &&
_ostree_repo_mode_is_bare (repo->mode))
{
if (!_ostree_repo_open_content_bare (repo, state->checksum,
state->content_size,
&state->tmpf,
&state->have_obj,
cancellable, error))
if (!ostree_repo_has_object (repo, OSTREE_OBJECT_TYPE_FILE, state->checksum,
&state->have_obj, cancellable, error))
goto out;

if (!state->have_obj)
{
if (!_ostree_repo_open_content_bare (repo, state->checksum,
state->content_size,
&state->tmpf,
cancellable, error))
goto out;

state->content_out = g_unix_output_stream_new (state->tmpf.fd, FALSE);
if (!handle_untrusted_content_checksum (repo, state, cancellable, error))
goto out;
Expand Down Expand Up @@ -682,14 +685,19 @@ dispatch_open (OstreeRepo *repo,
if (state->stats_only)
return TRUE; /* Early return */

if (!_ostree_repo_open_content_bare (repo, state->checksum,
state->content_size,
&state->tmpf,
&state->have_obj,
cancellable, error))
if (!ostree_repo_has_object (repo, OSTREE_OBJECT_TYPE_FILE, state->checksum,
&state->have_obj, cancellable, error))
return FALSE;

if (!state->have_obj)
state->content_out = g_unix_output_stream_new (state->tmpf.fd, FALSE);
{
if (!_ostree_repo_open_content_bare (repo, state->checksum,
state->content_size,
&state->tmpf,
cancellable, error))
return FALSE;
state->content_out = g_unix_output_stream_new (state->tmpf.fd, FALSE);
}

if (!handle_untrusted_content_checksum (repo, state, cancellable, error))
return FALSE;
Expand Down