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
This commit is contained in:
1 parent
7f6af94c5a
commit
2e3889a4eb
5 files changed
+86
-107
No files matched your search
@@ -269,13 +269,13 @@ ensure_tmpfile (FetcherRequest *req, GError **error)
|
||||
{
|
||||
if (!req->tmpf.initialized)
|
||||
{
|
||||
if (!glnx_open_tmpfile_linkable_at (req->fetcher->tmpdir_dfd, ".",
|
||||
O_WRONLY | O_CLOEXEC, &req->tmpf,
|
||||
error))
|
||||
if (!_ostree_fetcher_tmpf_from_flags (req->flags, req->fetcher->tmpdir_dfd,
|
||||
&req->tmpf, error))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Check for completed transfers, and remove their easy handles */
|
||||
static void
|
||||
check_multi_info (OstreeFetcher *fetcher)
|
||||
@@ -378,25 +378,19 @@ check_multi_info (OstreeFetcher *fetcher)
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
GError **error = &local_error;
|
||||
|
||||
g_autofree char *tmpfile_path =
|
||||
ostree_fetcher_generate_url_tmpname (eff_url);
|
||||
if (!ensure_tmpfile (req, error))
|
||||
{
|
||||
g_task_return_error (task, g_steal_pointer (&local_error));
|
||||
}
|
||||
/* This should match the libsoup chmod */
|
||||
else if (fchmod (req->tmpf.fd, 0644) < 0)
|
||||
else if (lseek (req->tmpf.fd, 0, SEEK_SET) < 0)
|
||||
{
|
||||
glnx_set_error_from_errno (error);
|
||||
g_task_return_error (task, g_steal_pointer (&local_error));
|
||||
}
|
||||
else if (!glnx_link_tmpfile_at (&req->tmpf, GLNX_LINK_TMPFILE_REPLACE,
|
||||
fetcher->tmpdir_dfd, tmpfile_path,
|
||||
error))
|
||||
g_task_return_error (task, g_steal_pointer (&local_error));
|
||||
else
|
||||
{
|
||||
g_task_return_pointer (task, g_steal_pointer (&tmpfile_path), g_free);
|
||||
/* We return the tmpfile in the _finish wrapper */
|
||||
g_task_return_boolean (task, TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -887,26 +881,21 @@ _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;
|
||||
FetcherRequest *req;
|
||||
gpointer ret;
|
||||
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
|
||||
g_return_val_if_fail (g_async_result_is_tagged (result, _ostree_fetcher_request_async), FALSE);
|
||||
|
||||
task = (GTask*)result;
|
||||
req = g_task_get_task_data (task);
|
||||
GTask *task = (GTask*)result;
|
||||
FetcherRequest *req = g_task_get_task_data (task);
|
||||
|
||||
ret = g_task_propagate_pointer (task, error);
|
||||
if (!ret)
|
||||
if (!g_task_propagate_boolean (task, error))
|
||||
return FALSE;
|
||||
|
||||
g_assert (!req->is_membuf);
|
||||
g_assert (out_filename);
|
||||
*out_filename = ret;
|
||||
*out_tmpf = req->tmpf;
|
||||
req->tmpf.initialized = FALSE; /* Transfer ownership */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user