Skip to content
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
2 changes: 1 addition & 1 deletion libglnx
Submodule libglnx updated from 32231f to 9c26c1
31 changes: 12 additions & 19 deletions src/libostree/ostree-fetcher-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ struct FetcherRequest {
OstreeFetcherRequestFlags flags;
gboolean is_membuf;
GError *caught_write_error;
char *out_tmpfile;
int out_tmpfile_fd;
GLnxTmpfile tmpfile;
GString *output_buf;

CURL *easy;
Expand Down Expand Up @@ -269,11 +268,10 @@ request_get_uri (FetcherRequest *req, guint idx)
static gboolean
ensure_tmpfile (FetcherRequest *req, GError **error)
{
if (req->out_tmpfile_fd == -1)
if (req->tmpfile.fd == -1)
{
if (!glnx_open_tmpfile_linkable_at (req->fetcher->tmpdir_dfd, ".",
O_WRONLY, &req->out_tmpfile_fd,
&req->out_tmpfile,
O_WRONLY | O_CLOEXEC, &req->tmpfile,
error))
return FALSE;
}
Expand Down Expand Up @@ -387,18 +385,15 @@ check_multi_info (OstreeFetcher *fetcher)
{
g_task_return_error (task, g_steal_pointer (&local_error));
}
else if (fchmod (req->out_tmpfile_fd, 0644) < 0)
else if (fchmod (req->tmpfile.fd, 0644) < 0)
{
glnx_set_error_from_errno (error);
g_task_return_error (task, g_steal_pointer (&local_error));
}
else if (!glnx_link_tmpfile_at (fetcher->tmpdir_dfd,
GLNX_LINK_TMPFILE_REPLACE,
req->out_tmpfile_fd,
req->out_tmpfile,
fetcher->tmpdir_dfd,
tmpfile_path,
error))
else if (!glnx_link_tmpfile_at (&req->tmpfile,
GLNX_LINK_TMPFILE_REPLACE,
fetcher->tmpdir_dfd, tmpfile_path,
error))
g_task_return_error (task, g_steal_pointer (&local_error));
else
{
Expand Down Expand Up @@ -586,8 +581,8 @@ write_cb (void *ptr, size_t size, size_t nmemb, void *data)
{
if (!ensure_tmpfile (req, &req->caught_write_error))
return -1;
g_assert (req->out_tmpfile_fd >= 0);
if (glnx_loop_write (req->out_tmpfile_fd, ptr, realsize) < 0)
g_assert (req->tmpfile.fd >= 0);
if (glnx_loop_write (req->tmpfile.fd, ptr, realsize) < 0)
{
glnx_set_error_from_errno (&req->caught_write_error);
return -1;
Expand Down Expand Up @@ -622,9 +617,7 @@ request_unref (FetcherRequest *req)
g_ptr_array_unref (req->mirrorlist);
g_free (req->filename);
g_clear_error (&req->caught_write_error);
if (req->out_tmpfile_fd != -1)
(void) close (req->out_tmpfile_fd);
g_free (req->out_tmpfile);
glnx_tmpfile_clear (&req->tmpfile);
if (req->output_buf)
g_string_free (req->output_buf, TRUE);
curl_easy_cleanup (req->easy);
Expand Down Expand Up @@ -847,7 +840,7 @@ _ostree_fetcher_request_async (OstreeFetcher *self,
/* We'll allocate the tmpfile on demand, so we handle
* file I/O errors just in the write func.
*/
req->out_tmpfile_fd = -1;
req->tmpfile.src_dfd = -1;
if (req->is_membuf)
req->output_buf = g_string_new ("");

Expand Down
30 changes: 12 additions & 18 deletions src/libostree/ostree-repo-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ checkout_object_for_uncompressed_cache (OstreeRepo *self,
guint32 file_mode = g_file_info_get_attribute_uint32 (src_info, "unix::mode");
file_mode &= ~(S_ISUID|S_ISGID);

glnx_fd_close int fd = -1;
g_autofree char *temp_filename = NULL;
g_auto(GLnxTmpfile) tmpf = GLNX_TMPFILE_INIT;
if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY | O_CLOEXEC,
&fd, &temp_filename,
error))
&tmpf, error))
return FALSE;
g_autoptr(GOutputStream) temp_out = g_unix_output_stream_new (fd, FALSE);
g_autoptr(GOutputStream) temp_out = g_unix_output_stream_new (tmpf.fd, FALSE);

if (g_output_stream_splice (temp_out, content, 0, cancellable, error) < 0)
return FALSE;
Expand All @@ -76,23 +74,22 @@ checkout_object_for_uncompressed_cache (OstreeRepo *self,

if (!self->disable_fsync)
{
if (TEMP_FAILURE_RETRY (fsync (fd)) < 0)
if (TEMP_FAILURE_RETRY (fsync (tmpf.fd)) < 0)
return glnx_throw_errno (error);
}

if (!g_output_stream_close (temp_out, cancellable, error))
return FALSE;

if (fchmod (fd, file_mode) < 0)
if (fchmod (tmpf.fd, file_mode) < 0)
return glnx_throw_errno (error);

if (!_ostree_repo_ensure_loose_objdir_at (self->uncompressed_objects_dir_fd,
loose_path,
cancellable, error))
return FALSE;

if (!glnx_link_tmpfile_at (self->tmp_dir_fd, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST,
fd, temp_filename,
if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST,
self->uncompressed_objects_dir_fd, loose_path,
error))
return FALSE;
Expand Down Expand Up @@ -185,7 +182,6 @@ create_file_copy_from_input_at (OstreeRepo *repo,
GCancellable *cancellable,
GError **error)
{
g_autofree char *temp_filename = NULL;
const gboolean union_mode = options->overwrite_mode == OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES;
const gboolean add_mode = options->overwrite_mode == OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES;
const gboolean sepolicy_enabled = options->sepolicy && !repo->disable_xattrs;
Expand Down Expand Up @@ -252,7 +248,6 @@ create_file_copy_from_input_at (OstreeRepo *repo,
}
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
{
glnx_fd_close int temp_fd = -1;
guint32 file_mode;
GLnxLinkTmpfileReplaceMode replace_mode;

Expand All @@ -261,9 +256,9 @@ create_file_copy_from_input_at (OstreeRepo *repo,
if (options->mode == OSTREE_REPO_CHECKOUT_MODE_USER)
file_mode &= ~(S_ISUID|S_ISGID);

g_auto(GLnxTmpfile) tmpf = GLNX_TMPFILE_INIT;
if (!glnx_open_tmpfile_linkable_at (destination_dfd, ".", O_WRONLY | O_CLOEXEC,
&temp_fd, &temp_filename,
error))
&tmpf, error))
return FALSE;

if (sepolicy_enabled)
Expand All @@ -274,11 +269,11 @@ create_file_copy_from_input_at (OstreeRepo *repo,
g_file_info_get_attribute_uint32 (file_info, "unix::mode"),
&label, cancellable, error))
return FALSE;
if (fsetxattr (temp_fd, "security.selinux", label, strlen (label), 0) < 0)
if (fsetxattr (tmpf.fd, "security.selinux", label, strlen (label), 0) < 0)
return glnx_throw_errno_prefix (error, "Setting security.selinux");
}

if (!write_regular_file_content (repo, options, temp_fd, file_info, xattrs, input,
if (!write_regular_file_content (repo, options, tmpf.fd, file_info, xattrs, input,
cancellable, error))
return FALSE;

Expand All @@ -290,9 +285,8 @@ create_file_copy_from_input_at (OstreeRepo *repo,
else
replace_mode = GLNX_LINK_TMPFILE_NOREPLACE;

if (!glnx_link_tmpfile_at (destination_dfd, replace_mode,
temp_fd, temp_filename, destination_dfd,
destination_name,
if (!glnx_link_tmpfile_at (&tmpf, replace_mode,
destination_dfd, destination_name,
error))
return FALSE;
}
Expand Down
52 changes: 32 additions & 20 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ _ostree_repo_commit_loose_final (OstreeRepo *self,

if (fd != -1)
{
if (!glnx_link_tmpfile_at (temp_dfd, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST,
fd, temp_filename, dest_dfd, tmpbuf, error))
/* FIXME: We'll unlink the tmpfile here in the non-O_TMPFILE case, and
* then go to unlink it again up the stack. Need to fix this with an
* OstreeTempObject struct or so that handles both regfiles and symlinks.
*/
GLnxTmpfile tmpfile = { temp_dfd, fd, temp_filename ? g_strdup (temp_filename) : NULL };
if (!glnx_link_tmpfile_at (&tmpfile, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST,
dest_dfd, tmpbuf, error))
return FALSE;
}
else
Expand Down Expand Up @@ -494,16 +499,18 @@ _ostree_repo_open_content_bare (OstreeRepo *self,

if (!have_obj)
{
int fd;

/* TODO - raise this struct into OstreeRepoContentBareCommit */
g_auto(GLnxTmpfile) tmpf = GLNX_TMPFILE_INIT;
if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY|O_CLOEXEC,
&fd, &temp_filename, error))
&tmpf, error))
goto out;

if (!ot_fallocate (fd, content_len, error))
if (!ot_fallocate (tmpf.fd, content_len, error))
goto out;

ret_stream = g_unix_output_stream_new (fd, TRUE);
/* Destructure and transfer ownership */
temp_filename = g_steal_pointer (&tmpf.path);
ret_stream = g_unix_output_stream_new (tmpf.fd, TRUE); tmpf.fd = -1;
}

ret = TRUE;
Expand Down Expand Up @@ -558,36 +565,36 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self,
GCancellable *cancellable,
GError **error)
{
glnx_fd_close int temp_fd = -1;
g_autofree char *temp_filename = NULL;

g_auto(GLnxTmpfile) tmpf = GLNX_TMPFILE_INIT;
if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY|O_CLOEXEC,
&temp_fd, &temp_filename,
error))
&tmpf, error))
return FALSE;

if (!ot_fallocate (temp_fd, length, error))
if (!ot_fallocate (tmpf.fd, length, error))
return FALSE;

if (G_IS_FILE_DESCRIPTOR_BASED (input))
{
int infd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*) input);
if (glnx_regfile_copy_bytes (infd, temp_fd, (off_t)length, TRUE) < 0)
if (glnx_regfile_copy_bytes (infd, tmpf.fd, (off_t)length, TRUE) < 0)
return glnx_throw_errno_prefix (error, "regfile copy");
}
else
{
g_autoptr(GOutputStream) temp_out = g_unix_output_stream_new (temp_fd, FALSE);
g_autoptr(GOutputStream) temp_out = g_unix_output_stream_new (tmpf.fd, FALSE);
if (g_output_stream_splice (temp_out, input, 0,
cancellable, error) < 0)
return FALSE;
}

if (fchmod (temp_fd, 0644) < 0)
if (fchmod (tmpf.fd, 0644) < 0)
return glnx_throw_errno_prefix (error, "fchmod");

*out_fd = temp_fd; temp_fd = -1;
*out_path = g_steal_pointer (&temp_filename);
/* Deconstruct and return. It's hard to return the tmpf directly since some
* bits of the commit path also use the temp path for symlinks.
*/
*out_fd = tmpf.fd; tmpf.fd = -1;
*out_path = g_steal_pointer (&tmpf.path);
return TRUE;
}

Expand Down Expand Up @@ -716,10 +723,15 @@ write_object (OstreeRepo *self,
if (self->generate_sizes)
indexable = TRUE;

GLnxTmpfile tmpf; /* Not auto, see below */
if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY|O_CLOEXEC,
&temp_fd, &temp_filename,
error))
&tmpf, error))
goto out;
/* We destructure it here to avoid having to churn too much code;
* perhaps down the line we could pass the tmpfile struct down.
*/
temp_fd = tmpf.fd; tmpf.fd = -1;
temp_filename = g_steal_pointer (&tmpf.path);
temp_file_is_regular = TRUE;
temp_out = g_unix_output_stream_new (temp_fd, FALSE);

Expand Down
Loading