diff options
author | Colin Walters <walters@verbum.org> | 2017-06-24 14:06:53 +0000 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-06-27 22:02:14 +0000 |
commit | 5776d5dcc09e5aabae1b5c1b8854c0b66522accd (patch) | |
tree | 466c0a17f2c0378d4ff938078718dc17c0d50396 /src/libostree/ostree-repo-static-delta-compilation.c | |
parent | 79f285d188eef288cecb35ed7977bf6e219cc396 (diff) | |
download | ostree-5776d5dcc09e5aabae1b5c1b8854c0b66522accd.tar.gz |
Port to GLnxTmpfile
There's lots of mechanically replacing `OtTmpFile` with `GLnxTmpfile`;
the biggest changes are in the commit path. Symlink commits are now
very clearly separated from regular files. Symlinks are `OtCleanupUnlinkat`,
and regular files are `GLnxTmpfile`.
The commit codepath separates those as `_ostree_repo_commit_path_final()` and
`_ostree_repo_commit_tmpf_final()`. A nice aspect of all of this is that they
both *consume* the temporary on success. This avoids an extra spurious
`unlink()` call.
One of the biggest bits of code motion is in `commit_loose_regfile_object()`,
which no longer needs to care about symlinks. For the most parth though it's
just removing conditionals.
Update submodule: libglnx
Closes: #958
Approved by: jlebon
Diffstat (limited to 'src/libostree/ostree-repo-static-delta-compilation.c')
-rw-r--r-- | src/libostree/ostree-repo-static-delta-compilation.c | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/src/libostree/ostree-repo-static-delta-compilation.c b/src/libostree/ostree-repo-static-delta-compilation.c index 7bcf5a92..6d26a1e5 100644 --- a/src/libostree/ostree-repo-static-delta-compilation.c +++ b/src/libostree/ostree-repo-static-delta-compilation.c @@ -437,29 +437,25 @@ get_unpacked_unlinked_content (OstreeRepo *repo, GCancellable *cancellable, GError **error) { - g_autofree char *tmpname = NULL; - glnx_fd_close int fd = -1; + g_auto(GLnxTmpfile) tmpf = { 0, }; g_autoptr(GBytes) ret_content = NULL; g_autoptr(GInputStream) istream = NULL; g_autoptr(GOutputStream) out = NULL; if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, "/tmp", O_RDWR | O_CLOEXEC, - &fd, &tmpname, error)) + &tmpf, error)) return FALSE; - /* We don't need the file name */ - if (tmpname) - (void) unlinkat (AT_FDCWD, tmpname, 0); if (!ostree_repo_load_file (repo, checksum, &istream, NULL, NULL, cancellable, error)) return FALSE; - out = g_unix_output_stream_new (fd, FALSE); + out = g_unix_output_stream_new (tmpf.fd, FALSE); if (g_output_stream_splice (out, istream, G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, cancellable, error) < 0) return FALSE; - { g_autoptr(GMappedFile) mfile = g_mapped_file_new_from_fd (fd, FALSE, error); + { g_autoptr(GMappedFile) mfile = g_mapped_file_new_from_fd (tmpf.fd, FALSE, error); if (!mfile) return FALSE; ret_content = g_mapped_file_get_bytes (mfile); @@ -1163,6 +1159,15 @@ get_fallback_headers (OstreeRepo *self, return TRUE; } +static inline void +glnx_tmpfile_clear_p (void *ptr) +{ + GLnxTmpfile *tmpf = ptr; + if (!tmpf) + return; + glnx_tmpfile_clear (tmpf); +} + /** * ostree_repo_static_delta_generate: * @self: Repo @@ -1213,7 +1218,6 @@ ostree_repo_static_delta_generate (OstreeRepo *self, guint64 total_compressed_size = 0; guint64 total_uncompressed_size = 0; g_autoptr(GVariantBuilder) part_headers = NULL; - g_autoptr(GArray) part_temp_fds = NULL; g_autoptr(GPtrArray) part_temp_paths = NULL; g_autoptr(GVariant) delta_descriptor = NULL; g_autoptr(GVariant) to_commit = NULL; @@ -1325,8 +1329,7 @@ ostree_repo_static_delta_generate (OstreeRepo *self, } part_headers = g_variant_builder_new (G_VARIANT_TYPE ("a" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT)); - part_temp_paths = g_ptr_array_new_with_free_func (g_free); - part_temp_fds = g_array_new (FALSE, TRUE, sizeof(int)); + part_temp_paths = g_ptr_array_new_with_free_func (glnx_tmpfile_clear_p); for (i = 0; i < builder.parts->len; i++) { OstreeStaticDeltaPartBuilder *part_builder = builder.parts->pdata[i]; @@ -1399,17 +1402,15 @@ ostree_repo_static_delta_generate (OstreeRepo *self, } else { - char *part_tempfile; - int part_temp_fd; + GLnxTmpfile *part_tmpf = g_new0 (GLnxTmpfile, 1); if (!glnx_open_tmpfile_linkable_at (tmp_dfd, ".", O_WRONLY | O_CLOEXEC, - &part_temp_fd, &part_tempfile, error)) + part_tmpf, error)) goto out; - /* Transfer tempfile ownership to arrays */ - g_array_append_val (part_temp_fds, part_temp_fd); - g_ptr_array_add (part_temp_paths, g_steal_pointer (&part_tempfile)); - part_temp_outstream = g_unix_output_stream_new (part_temp_fd, FALSE); + /* Transfer tempfile ownership */ + part_temp_outstream = g_unix_output_stream_new (part_tmpf->fd, FALSE); + g_ptr_array_add (part_temp_paths, g_steal_pointer (&part_tmpf)); } part_in = ot_variant_read (delta_part); @@ -1468,17 +1469,16 @@ ostree_repo_static_delta_generate (OstreeRepo *self, { g_autofree char *partstr = g_strdup_printf ("%u", i); /* Take ownership of the path/fd here */ - g_autofree char *path = g_steal_pointer (&part_temp_paths->pdata[i]); - glnx_fd_close int fd = g_array_index (part_temp_fds, int, i); - g_array_index (part_temp_fds, int, i) = -1; + g_auto(GLnxTmpfile) tmpf = *((GLnxTmpfile*)part_temp_paths->pdata[i]); + g_clear_pointer (&(part_temp_paths->pdata[i]), g_free); - if (fchmod (fd, 0644) < 0) + if (fchmod (tmpf.fd, 0644) < 0) { glnx_set_error_from_errno (error); goto out; } - if (!glnx_link_tmpfile_at (tmp_dfd, GLNX_LINK_TMPFILE_REPLACE, fd, path, + if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_REPLACE, descriptor_dfd, partstr, error)) goto out; } @@ -1538,14 +1538,6 @@ ostree_repo_static_delta_generate (OstreeRepo *self, ret = TRUE; out: - if (part_temp_fds) - for (i = 0; i < part_temp_fds->len; i++) - { - int fd = g_array_index (part_temp_fds, int, i); - if (fd == -1) - continue; - (void) close (fd); - } g_clear_pointer (&builder.parts, g_ptr_array_unref); g_clear_pointer (&builder.fallback_objects, g_ptr_array_unref); return ret; |