Skip to content

Commit ed4bac1

Browse files
committed
Blockfile: Enlighten blockfile copy on Darwin
The Go stdlib does not seem to have an efficient os.File.ReadFrom routine for other platforms like it does on Linux with copy_file_range. For Darwin at least we can use clonefile in its place, otherwise if we have a sparse file we'd have a fun surprise with the io.Copy approach.. We should see if there's other platforms that we can enhance here. I've forgotten what's the right route on Windows. Signed-off-by: Danny Canter <[email protected]> (cherry picked from commit 13ff185) Signed-off-by: Danny Canter <[email protected]>
1 parent c2978c2 commit ed4bac1

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

snapshots/blockfile/blockfile.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222
"io"
2323
"os"
2424
"path/filepath"
25+
"runtime"
2526

2627
"github.com/containerd/containerd/log"
2728
"github.com/containerd/containerd/mount"
2829
"github.com/containerd/containerd/plugin"
2930
"github.com/containerd/containerd/snapshots"
3031
"github.com/containerd/containerd/snapshots/storage"
32+
"github.com/containerd/continuity/fs"
3133
)
3234

3335
// viewHookHelper is only used in test for recover the filesystem.
@@ -447,6 +449,17 @@ func (o *snapshotter) Close() error {
447449
}
448450

449451
func copyFileWithSync(target, source string) error {
452+
// The Go stdlib does not seem to have an efficient os.File.ReadFrom
453+
// routine for other platforms like it does on Linux with
454+
// copy_file_range. For Darwin at least we can use clonefile
455+
// in its place, otherwise if we have a sparse file we'd have
456+
// a fun surprise waiting below.
457+
//
458+
// TODO: Enlighten other platforms (windows?)
459+
if runtime.GOOS == "darwin" {
460+
return fs.CopyFile(target, source)
461+
}
462+
450463
src, err := os.Open(source)
451464
if err != nil {
452465
return fmt.Errorf("failed to open source %s: %w", source, err)

0 commit comments

Comments
 (0)