Skip to content

Commit

Permalink
fixup! rofiles: Add --copyup option
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Dec 28, 2017
1 parent 086efd6 commit 276f54d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/rofiles-fuse/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ gioerror_to_errno (GIOErrorEnum e)
}

static int
verify_write_or_copyup (const char *path, const struct stat *stbuf)
verify_write_or_copyup_full (const char *path, const struct stat *stbuf,
gboolean is_truncating)
{
struct stat stbuf_local;

Expand All @@ -272,6 +273,13 @@ verify_write_or_copyup (const char *path, const struct stat *stbuf)
g_autoptr(GError) tmp_error = NULL;
if (!ostree_break_hardlink (basefd, path, FALSE, NULL, &tmp_error))
return -gioerror_to_errno ((GIOErrorEnum)tmp_error->code);
if (is_truncating)
{
glnx_fd_close int fd =
openat (basefd, path, O_WRONLY | O_TRUNC);
if (fd < 0)
return -errno;
}
}
else
return -EROFS;
Expand All @@ -280,6 +288,13 @@ verify_write_or_copyup (const char *path, const struct stat *stbuf)
return 0;
}


static int
verify_write_or_copyup (const char *path, const struct stat *stbuf)
{
return verify_write_or_copyup_full (path, stbuf, FALSE);
}

/* Given a path (which is absolute), convert it
* to a relative path (even for the caller) and
* perform either write verification or copy-up.
Expand Down Expand Up @@ -364,7 +379,9 @@ do_open (const char *path, mode_t mode, struct fuse_file_info *finfo)
/* Write */

/* We need to specially handle O_TRUNC */
fd = openat (basefd, path, finfo->flags & ~O_TRUNC, mode);
int notrunc_flags = finfo->flags & ~O_TRUNC;
gboolean is_truncating = (finfo->flags & O_TRUNC) > 0;
fd = openat (basefd, path, notrunc_flags, mode);
if (fd == -1)
return -errno;

Expand All @@ -374,7 +391,7 @@ do_open (const char *path, mode_t mode, struct fuse_file_info *finfo)
return -errno;
}

int r = verify_write_or_copyup (path, &stbuf);
int r = verify_write_or_copyup_full (path, &stbuf, is_truncating);
if (r != 0)
{
(void) close (fd);
Expand All @@ -385,7 +402,7 @@ do_open (const char *path, mode_t mode, struct fuse_file_info *finfo)
if (opt_copyup)
{
(void) close (fd);
fd = openat (basefd, path, finfo->flags & ~O_TRUNC, mode);
fd = openat (basefd, path, finfo->flags & ~(O_EXCL|O_CREAT), mode);
if (fd == -1)
return -errno;
}
Expand Down
1 change: 1 addition & 0 deletions tests/test-rofiles-fuse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ firstfile_orig_inode=$(stat -c %i checkout-test2/firstfile)
for path in firstfile{,-link}; do
echo truncating > mnt/${path}
assert_file_has_content mnt/${path} truncating
assert_not_file_has_content mnt/${path} first
done
firstfile_new_inode=$(stat -c %i checkout-test2/firstfile)
assert_not_streq "${firstfile_orig_inode}" "${firstfile_new_inode}"
Expand Down

0 comments on commit 276f54d

Please sign in to comment.