Skip to content

Commit

Permalink
uses cloning on CoW filesystems like btrfs
Browse files Browse the repository at this point in the history
This improves the time it takes to write the changes to disk.
  • Loading branch information
taukakao committed Jan 5, 2024
1 parent 90db930 commit 48f45f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 2 additions & 7 deletions core/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ func OciExportRootFs(buildImageName string, imageRecipe *ImageRecipe, transDir s
return err
}

// cleanup dest
err = os.RemoveAll(dest)
if err != nil {
PrintVerboseErr("OciExportRootFs", 2, err)
return err
}
// create dest if it doesn't exist
err = os.MkdirAll(dest, 0755)
if err != nil {
PrintVerboseErr("OciExportRootFs", 3, err)
Expand Down Expand Up @@ -93,7 +88,7 @@ func OciExportRootFs(buildImageName string, imageRecipe *ImageRecipe, transDir s
}

// copy mount dir contents to dest
err = rsyncCmd(mountDir+"/", dest, []string{}, false)
err = rsyncCmd(mountDir+"/", dest, []string{"--delete"}, false)
if err != nil {
PrintVerboseErr("OciExportRootFs", 9, err)
return err
Expand Down
13 changes: 13 additions & 0 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,19 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
PrintVerboseErr("ABSystemRunOperation", 4.1, err)
return err
}
} else {
PrintVerbose("ABSystemRunOperation: Creating a reflink clone of the old system to copy into")
err := os.RemoveAll(systemNew)
if err != nil {
PrintVerbose("ABSystemRunOperation:err(4.0.2): could not cleanup old systemNew folder %s", err)
return err
}
err = exec.Command("cp", "--reflink", "-a", systemOld, systemNew).Run()
if err != nil {
PrintVerbose("ABSystemRunOperation:warn(4.0.3): reflink copy of system failed, falling back to slow copy, reason: %s", err)
// can be safely ignored
// file system doesn't support CoW
}
}

err = OciExportRootFs(
Expand Down

0 comments on commit 48f45f1

Please sign in to comment.