Skip to content

Commit

Permalink
Improve file copy on copyfile_darwin
Browse files Browse the repository at this point in the history
Make use of unix.CloneFile()
  • Loading branch information
cfergeau committed Dec 13, 2024
1 parent cff86fb commit 5e7353b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
17 changes: 17 additions & 0 deletions pkg/machinedriver/copyfile_darwin.go
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions pkg/machinedriver/copyfile_nondarwin.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 1 addition & 2 deletions pkg/machinedriver/crcimageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
/*
Expand Down

0 comments on commit 5e7353b

Please sign in to comment.