Merge pull request #9042 from dcantah/darwin-blockfile-copyfile

Blockfile: Enlighten blockfile copy on Darwin
This commit is contained in:
Derek McGowan 2023-09-01 07:18:44 -07:00 committed by GitHub
commit dc8b0d80b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,12 +22,14 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin" "github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshots" "github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/storage" "github.com/containerd/containerd/snapshots/storage"
"github.com/containerd/continuity/fs"
) )
// viewHookHelper is only used in test for recover the filesystem. // viewHookHelper is only used in test for recover the filesystem.
@ -447,6 +449,17 @@ func (o *snapshotter) Close() error {
} }
func copyFileWithSync(target, source string) error { func copyFileWithSync(target, source string) error {
// 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 waiting below.
//
// TODO: Enlighten other platforms (windows?)
if runtime.GOOS == "darwin" {
return fs.CopyFile(target, source)
}
src, err := os.Open(source) src, err := os.Open(source)
if err != nil { if err != nil {
return fmt.Errorf("failed to open source %s: %w", source, err) return fmt.Errorf("failed to open source %s: %w", source, err)