diff --git a/pkg/machinedriver/copyfile_darwin.go b/pkg/machinedriver/copyfile_darwin.go new file mode 100644 index 00000000..d175b461 --- /dev/null +++ b/pkg/machinedriver/copyfile_darwin.go @@ -0,0 +1,17 @@ +package macadam + +import ( + crcos "github.com/crc-org/crc/v2/pkg/os" + "golang.org/x/sys/unix" +) + +func copyFile(src, dst string) error { + if err := unix.Clonefile(src, dst, 0); err != nil { + // fall back to a regular sparse copy, the error may be caused by the filesystem not supporting unix.CloneFile + if err := crcos.CopyFileSparse(src, dst); err != nil { + return err + } + } + + return nil +} diff --git a/pkg/machinedriver/copyfile_nondarwin.go b/pkg/machinedriver/copyfile_nondarwin.go new file mode 100644 index 00000000..67f6695c --- /dev/null +++ b/pkg/machinedriver/copyfile_nondarwin.go @@ -0,0 +1,11 @@ +//go:build !darwin + +package macadam + +import ( + crcos "github.com/crc-org/crc/v2/pkg/os" +) + +func copyFile(src, dst string) error { + return crcos.CopyFile(src, dst) +} diff --git a/pkg/machinedriver/crcimageprovider.go b/pkg/machinedriver/crcimageprovider.go index 8ed22894..fc91c3fc 100644 --- a/pkg/machinedriver/crcimageprovider.go +++ b/pkg/machinedriver/crcimageprovider.go @@ -8,7 +8,6 @@ import ( "github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/vmconfigs" - crcos "github.com/crc-org/crc/v2/pkg/os" ) type CrcImagePuller struct { @@ -93,7 +92,7 @@ func (puller *CrcImagePuller) Download() error { slog.Info(fmt.Sprintf("%+v", puller)) slog.Info("file copy", "source", puller.sourcePath, "dest", imagePath.GetPath()) - if err := crcos.CopyFile(puller.sourcePath, imagePath.GetPath()); err != nil { + if err := copyFile(puller.sourcePath, imagePath.GetPath()); err != nil { return err } /*