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

feat: Add reflink FileCopyMethod (copy-on-write) #166

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

eth-p
Copy link

@eth-p eth-p commented Aug 25, 2024

This commit is stacked on top of #165. That must be reviewed and merged first.

Note

I'm calling it reflink because that's what Linux users understand it as.

This brings copy-on-write file copying support as a FileCopyMethod.

Tests are passing: https://github.com/eth-p/forked-copy/actions/runs/10543146003/

TODO

  • Support on MacOS
  • Support on Linux
  • CI Testing MacOS
  • CI Testing Linux

@eth-p eth-p force-pushed the feat-copymethod-reflink branch 2 times, most recently from f225cea to a812a19 Compare August 25, 2024 01:41
This will be used so we can have multiple implementations for copying
a regular file. Currently, there is just CopyBytes, which is the old
fcopy code.

The FileCopyMethod struct is a struct with an un-exported member.
This is done to make the type opaque so the user can't make their
own copy function. There are still design questions left about
passing around the `Options` struct and `os.FileInfo`, so I opted
to do this so that can be figured out later.

The type can be made into `type FileCopyMethod func(...)` later,
and it won't be a breaking change. Or, instead, a
`UserCopy(func (src, dest string) error) FileCopyMethod`
function can be added.
Permission changes, ownership preservation, and access/modify/creation
time presevation is something all implementations need. I brought it
out of the CopyBytes implementation so it can be shared when more
implementations are added later.

A small note:

The "ignore if source file deleted" check had to be brought out of
`CopyBytes`. The way it worked before is it returned no error, which
meant `fcopy` would try and modify the destination file (which was never
created). Instead, I check for the error explicitly in `fcopy`.
External contributors don't do development on the main or develop
branch, but may still need to see the CI results. This lets them
do `gh workflow run Go --repo=<user>/copy` on their own branches.
When we add support for reflinks, we need to make sure we are able
to check that regressions aren't introduced. Explicitly testing
on different filesystems allows us to do that.
We want comprehensive testing, no matter the FileCopyMethod.
Using an environment variable is a quick, clean, and easy way to do
this.
The only `FileCopyMethod` that supports this is CopyBytes.
The only `FileCopyMethod` that supports this is CopyBytes.
@eth-p eth-p force-pushed the feat-copymethod-reflink branch 2 times, most recently from aa3f995 to c75dd17 Compare September 14, 2024 20:45
@eth-p eth-p force-pushed the feat-copymethod-reflink branch 3 times, most recently from 2a79585 to af89a8b Compare September 14, 2024 20:58
@eth-p eth-p marked this pull request as ready for review September 14, 2024 20:58
@eth-p eth-p changed the title [DRAFT] feat: Add reflink FileCopyMethod (copy-on-write) feat: Add reflink FileCopyMethod (copy-on-write) Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant