summaryrefslogtreecommitdiff
path: root/src/libostree/ostree-fetcher-soup.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-10-02 21:36:10 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2017-10-05 14:58:20 +0000
commit2e3889a4eb2e33b6cd0e0cc683ee9f047a756b6e (patch)
tree704d914b05ee74aa2d233fef424c663e2ac81905 /src/libostree/ostree-fetcher-soup.c
parent7f6af94c5a9a1ffa411636225baf5cb51de08144 (diff)
downloadostree-2e3889a4eb2e33b6cd0e0cc683ee9f047a756b6e.tar.gz
lib/pull: Change fetcher to return O_TMPFILE
A lot of the libostree code is honestly too complex for its own good (this is mostly my fault). The way we do HTTP writes is still one of those. The way the fetcher writes tempfiles, then reads them back in is definitely one of those. Now that we've dropped the "partial object" bits in: https://github.com/ostreedev/ostree/pull/1176 i.e. commit https://github.com/ostreedev/ostree/commit/0488b4870e80ef575d8b0edf6f2a9e5ad54bf4df we can simplify things a lot more by having the fetcher return an `O_TMPFILE` rather than a filename. For trusted archive mirroring, we need to enable linking in the tmpfiles directly. Otherwise for at least content objects they're compressed, so we couldn't link them in. For metadata, we need to do similar logic to what we have around `mmap()` to only grab a tmpfile if the size is large enough. Closes: #1252 Approved by: jlebon
Diffstat (limited to 'src/libostree/ostree-fetcher-soup.c')
-rw-r--r--src/libostree/ostree-fetcher-soup.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/libostree/ostree-fetcher-soup.c b/src/libostree/ostree-fetcher-soup.c
index 90986c66..e023d34e 100644
--- a/src/libostree/ostree-fetcher-soup.c
+++ b/src/libostree/ostree-fetcher-soup.c
@@ -905,11 +905,8 @@ on_stream_read (GObject *object,
{
if (!pending->is_membuf)
{
- if (!glnx_open_tmpfile_linkable_at (pending->thread_closure->base_tmpdir_dfd, ".",
- O_WRONLY | O_CLOEXEC, &pending->tmpf, &local_error))
- goto out;
- /* This should match the libcurl chmod */
- if (!glnx_fchmod (pending->tmpf.fd, 0644, &local_error))
+ if (!_ostree_fetcher_tmpf_from_flags (pending->flags, pending->thread_closure->base_tmpdir_dfd,
+ &pending->tmpf, &local_error))
goto out;
pending->out_stream = g_unix_output_stream_new (pending->tmpf.fd, FALSE);
}
@@ -943,18 +940,13 @@ on_stream_read (GObject *object,
}
else
{
- g_autofree char *uristring =
- soup_uri_to_string (soup_request_get_uri (pending->request), FALSE);
- g_autofree char *tmpfile_path =
- ostree_fetcher_generate_url_tmpname (uristring);
- if (!glnx_link_tmpfile_at (&pending->tmpf, GLNX_LINK_TMPFILE_REPLACE,
- pending->thread_closure->base_tmpdir_dfd, tmpfile_path,
- &local_error))
- g_task_return_error (task, g_steal_pointer (&local_error));
+ if (lseek (pending->tmpf.fd, 0, SEEK_SET) < 0)
+ {
+ glnx_set_error_from_errno (&local_error);
+ g_task_return_error (task, g_steal_pointer (&local_error));
+ }
else
- g_task_return_pointer (task,
- g_steal_pointer (&tmpfile_path),
- (GDestroyNotify) g_free);
+ g_task_return_boolean (task, TRUE);
}
remove_pending (pending);
}
@@ -1174,7 +1166,7 @@ _ostree_fetcher_request_to_tmpfile (OstreeFetcher *self,
gboolean
_ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self,
GAsyncResult *result,
- char **out_filename,
+ GLnxTmpfile *out_tmpf,
GError **error)
{
GTask *task;
@@ -1192,8 +1184,8 @@ _ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self,
return FALSE;
g_assert (!pending->is_membuf);
- g_assert (out_filename);
- *out_filename = ret;
+ *out_tmpf = pending->tmpf;
+ pending->tmpf.initialized = FALSE; /* Transfer ownership */
return TRUE;
}