Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rofiles: Add --copyup option #1382

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/rofiles-fuse/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,12 @@ 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);
/* Note that unlike the initial open, we will pass through
* O_TRUNC. More ideally in this copyup case we'd avoid copying
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so then we don't need to ftruncate down below again, right? Shouldn't the if condition at 399 be changed to

if (!opt_copyup && (finfo->flags & O_TRUNC))

?

* the whole file in the first place, but eh. It's not like we're
* high performance anyways.
*/
fd = openat (basefd, path, finfo->flags & ~(O_EXCL|O_CREAT), mode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we filtering out O_EXCL and O_CREAT here? This is something that should've been caught by the first openat, right? Or is this just to not have a TOCTOU race on the file existing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're internally reopening the file we just created. So if the user provided O_EXCL we need to filter that out. We might as well drop O_CREAT too.

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