local: add server-side copy with xattrs on macOS (part-fix #1710)

Before this change, macOS-specific metadata was not preserved by rclone, even for
local-to-local transfers (it does not use the "user." prefix, nor is Mac metadata
limited to xattrs.) Additionally, rclone did not take advantage of APFS's native
"cloning" functionality for fast and deduplicated transfers.

After this change, local (on macOS only) supports "server-side copy" similarly to
other remotes, and achieves this by using (when possible) macOS's native APFS
"cloning", which is the same underlying mechanism deployed when a user
duplicates a file via the Finder UI. This has several advantages over the
previous behavior:

- It is extremely fast (even large files can be cloned instantly)
- It is very efficient in terms of storage, as it automatically deduplicates when
possible (i.e. so that having two identical files does not consume more storage
than having just one.) (The concept is similar to a "hard link", but subsequent
modifications will not affect the original file.)
- It preserves Mac-specific metadata to the maximum degree, including not only
xattrs but also metadata not easily settable by other methods, including Finder
and Spotlight params.

When server-side "clone" is not available (for example, on non-APFS volumes), it
falls back to server-side "copy" (still preserving metadata but using more disk
storage.) It is only used when both remotes are local (and not wrapped by other
remotes, such as crypt.) The behavior of local on non-mac systems is unchanged.
This commit is contained in:
nielash
2023-12-28 12:30:47 -05:00
committed by Nick Craig-Wood
parent 3e12612aae
commit 87ec26001f
6 changed files with 99 additions and 0 deletions

View File

@ -1382,6 +1382,12 @@ func testSyncWithMaxDuration(t *testing.T, cutoffMode fs.CutoffMode) {
r.CheckLocalItems(t, file1, file2)
r.CheckRemoteItems(t)
if runtime.GOOS == "darwin" {
r.Flocal.Features().Disable("Copy") // macOS cloning is too fast for this test!
if r.Fremote.Features().IsLocal {
r.Fremote.Features().Disable("Copy") // macOS cloning is too fast for this test!
}
}
accounting.GlobalStats().ResetCounters()
// ctx = predictDstFromLogger(ctx) // not currently supported (but tests do pass for CutoffModeSoft)
startTime := time.Now()
@ -2569,6 +2575,14 @@ func TestMaxTransfer(t *testing.T) {
r.CheckLocalItems(t, file1, file2, file3)
r.CheckRemoteItems(t)
if runtime.GOOS == "darwin" {
// disable server-side copies as they don't count towards transfer size stats
r.Flocal.Features().Disable("Copy")
if r.Fremote.Features().IsLocal {
r.Fremote.Features().Disable("Copy")
}
}
accounting.GlobalStats().ResetCounters()
// ctx = predictDstFromLogger(ctx) // not currently supported