forked from bazel-contrib/bazel-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: use darwin's clonefile syscall (bazel-contrib#893)
* perf: use darwin's clonefile syscall This saves time and disk-space when copying files around on the same device. File clones (aka reflinks) share backing disk blocks; they differ from hardlinks in that inodes are not shared and the contents are copy-on-write. The Go standard library (as of v1.22) arranges to do a similar thing for file copies on Linux (see: https://cs.opensource.google/go/go/+/refs/tags/go1.22.6:src/os/zero_copy_linux.go;l=53). Unfortunately, Mac OS' more limited API is less amenable to that form of transparent wrapping. * Assign to named return params and use naked returns
- Loading branch information
Showing
4 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build darwin | ||
|
||
package common | ||
|
||
import ( | ||
"golang.org/x/sys/unix" | ||
"os" | ||
) | ||
|
||
// https://keith.github.io/xcode-man-pages/clonefile.2.html | ||
func cloneFile(src, dst string) (supported bool, err error) { | ||
supported = true | ||
if err = unix.Clonefile(src, dst, 0); err != nil { | ||
err = &os.LinkError{ | ||
Op: "clonefile", | ||
Old: src, | ||
New: dst, | ||
Err: err, | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build !darwin | ||
|
||
package common | ||
|
||
func cloneFile(src, dst string) (supported bool, err error) { | ||
supported = false | ||
err = nil | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters