Skip to content

Commit

Permalink
libglnx porting: Migrate to new tempfile code
Browse files Browse the repository at this point in the history
In general this is even cleaner now, though it was better after I
extracted a helper function for the "write tempfile with contents"
bits that were shared between metadata and regular file codepaths.
  • Loading branch information
cgwalters committed Jul 12, 2016
1 parent 35b4131 commit 6aa19d0
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -19,7 +19,7 @@ include Makefile-decls.am

shortened_sysconfdir = $$(echo "$(sysconfdir)" | sed -e 's|^$(prefix)||' -e 's|^/||')

ACLOCAL_AMFLAGS = -I buildutil ${ACLOCAL_FLAGS}
ACLOCAL_AMFLAGS = -I buildutil -I libglnx ${ACLOCAL_FLAGS}
AM_CPPFLAGS += -DDATADIR='"$(datadir)"' -DLIBEXECDIR='"$(libexecdir)"' \
-DLOCALEDIR=\"$(datadir)/locale\" -DSYSCONFDIR=\"$(sysconfdir)\" \
-DSHORTENED_SYSCONFDIR=\"$(shortened_sysconfdir)\" \
Expand Down
3 changes: 3 additions & 0 deletions autogen.sh
Expand Up @@ -36,6 +36,9 @@ fi
sed -e 's,$(libglnx_srcpath),libglnx,g' < libglnx/Makefile-libglnx.am >libglnx/Makefile-libglnx.am.inc
sed -e 's,$(libbsdiff_srcpath),bsdiff,g' < bsdiff/Makefile-bsdiff.am >bsdiff/Makefile-bsdiff.am.inc

# FIXME - figure out how to get aclocal to find this by default
ln -sf ../libglnx/libglnx.m4 buildutil/libglnx.m4

autoreconf --force --install --verbose

test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -35,6 +35,7 @@ OSTREE_FEATURES=""
AC_SUBST([OSTREE_FEATURES])

GLIB_TESTS
LIBGLNX_CONFIGURE

AC_CHECK_HEADER([sys/xattr.h],,[AC_MSG_ERROR([You must have sys/xattr.h from glibc])])

Expand Down
2 changes: 1 addition & 1 deletion libglnx
Submodule libglnx updated from a6d086 to d2e588
61 changes: 33 additions & 28 deletions src/libostree/ostree-repo-checkout.c
Expand Up @@ -45,27 +45,26 @@ checkout_object_for_uncompressed_cache (OstreeRepo *self,
gboolean ret = FALSE;
g_autofree char *temp_filename = NULL;
g_autoptr(GOutputStream) temp_out = NULL;
int fd;
glnx_fd_close int fd = -1;
int res;
guint32 file_mode;

/* Don't make setuid files in uncompressed cache */
file_mode = g_file_info_get_attribute_uint32 (src_info, "unix::mode");
file_mode &= ~(S_ISUID|S_ISGID);

if (!gs_file_open_in_tmpdir_at (self->tmp_dir_fd, file_mode,
&temp_filename, &temp_out,
cancellable, error))
if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY | O_CLOEXEC,
&fd, &temp_filename,
error))
goto out;
temp_out = g_unix_output_stream_new (fd, FALSE);

if (g_output_stream_splice (temp_out, content, 0, cancellable, error) < 0)
goto out;

if (!g_output_stream_flush (temp_out, cancellable, error))
goto out;

fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*)temp_out);

if (!self->disable_fsync)
{
do
Expand All @@ -81,23 +80,22 @@ checkout_object_for_uncompressed_cache (OstreeRepo *self,
if (!g_output_stream_close (temp_out, cancellable, error))
goto out;

if (fchmod (fd, file_mode) < 0)
{
glnx_set_error_from_errno (error);
goto out;
}

if (!_ostree_repo_ensure_loose_objdir_at (self->uncompressed_objects_dir_fd,
loose_path,
cancellable, error))
goto out;

if (G_UNLIKELY (renameat (self->tmp_dir_fd, temp_filename,
self->uncompressed_objects_dir_fd, loose_path) == -1))
{
if (errno != EEXIST)
{
glnx_set_error_from_errno (error);
g_prefix_error (error, "Storing file '%s': ", temp_filename);
goto out;
}
else
(void) unlinkat (self->tmp_dir_fd, temp_filename, 0);
}
if (!glnx_link_tmpfile_at (self->tmp_dir_fd, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST,
fd, temp_filename,
self->uncompressed_objects_dir_fd, loose_path,
error))
goto out;

ret = TRUE;
out:
Expand Down Expand Up @@ -292,9 +290,16 @@ checkout_file_unioning_from_input_at (OstreeRepo *repo,
xattrs, cancellable, error))
goto out;
}
if (G_UNLIKELY (renameat (destination_dfd, temp_filename,
destination_dfd, destination_name) == -1))
{
glnx_set_error_from_errno (error);
goto out;
}
}
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
{
glnx_fd_close int temp_fd = -1;
g_autoptr(GOutputStream) temp_out = NULL;
guint32 file_mode;

Expand All @@ -303,25 +308,25 @@ checkout_file_unioning_from_input_at (OstreeRepo *repo,
if (options->mode == OSTREE_REPO_CHECKOUT_MODE_USER)
file_mode &= ~(S_ISUID|S_ISGID);

if (!gs_file_open_in_tmpdir_at (destination_dfd, file_mode,
&temp_filename, &temp_out,
cancellable, error))
if (!glnx_open_tmpfile_linkable_at (destination_dfd, ".", O_WRONLY | O_CLOEXEC,
&temp_fd, &temp_filename,
error))
goto out;
temp_out = g_unix_output_stream_new (temp_fd, FALSE);

if (!write_regular_file_content (repo, options, temp_out, file_info, xattrs, input,
cancellable, error))
goto out;

if (!glnx_link_tmpfile_at (destination_dfd, GLNX_LINK_TMPFILE_REPLACE,
temp_fd, temp_filename, destination_dfd,
destination_name,
error))
goto out;
}
else
g_assert_not_reached ();

if (G_UNLIKELY (renameat (destination_dfd, temp_filename,
destination_dfd, destination_name) == -1))
{
glnx_set_error_from_errno (error);
goto out;
}

ret = TRUE;
out:
return ret;
Expand Down

0 comments on commit 6aa19d0

Please sign in to comment.