Remove hardlink optmization in sbox
The hardlink optimization attempts to save I/O by hardlinking input
files into the sandbox instead of copying them, but it never works on
a Linux build due to nsjail always making out and the source tree into
separate bind-mounted filesystems. If the optimization did work it
would actually cause build failures when it hardlinked the relative
bionic/libc/fs_config_generator.py symlink into the sandbox directory
without the target. Just remove the optimization for now since it
never works.
Test: m checkbuild
Change-Id: I96e8c0c145e7c99958639594edf8a93b69ae90eb
diff --git a/cmd/sbox/sbox.go b/cmd/sbox/sbox.go
index db483f1..633c6b2 100644
--- a/cmd/sbox/sbox.go
+++ b/cmd/sbox/sbox.go
@@ -207,7 +207,7 @@
}
// Copy in any files specified by the manifest.
- err = linkOrCopyFiles(command.CopyBefore, "", tempDir)
+ err = copyFiles(command.CopyBefore, "", tempDir)
if err != nil {
return "", err
}
@@ -315,12 +315,12 @@
return missingOutputErrors
}
-// linkOrCopyFiles hardlinks or copies files in or out of the sandbox.
-func linkOrCopyFiles(copies []*sbox_proto.Copy, fromDir, toDir string) error {
+// copyFiles copies files in or out of the sandbox.
+func copyFiles(copies []*sbox_proto.Copy, fromDir, toDir string) error {
for _, copyPair := range copies {
fromPath := joinPath(fromDir, copyPair.GetFrom())
toPath := joinPath(toDir, copyPair.GetTo())
- err := linkOrCopyOneFile(fromPath, toPath)
+ err := copyOneFile(fromPath, toPath)
if err != nil {
return fmt.Errorf("error copying %q to %q: %w", fromPath, toPath, err)
}
@@ -328,30 +328,13 @@
return nil
}
-// linkOrCopyOneFile first attempts to hardlink a file to a destination, and falls back to making
-// a copy if the hardlink fails.
-func linkOrCopyOneFile(from string, to string) error {
+// copyOneFile copies a file.
+func copyOneFile(from string, to string) error {
err := os.MkdirAll(filepath.Dir(to), 0777)
if err != nil {
return err
}
- // First try hardlinking
- err = os.Link(from, to)
- if err != nil {
- // Retry with copying in case the source an destination are on different filesystems.
- // TODO: check for specific hardlink error?
- err = copyOneFile(from, to)
- if err != nil {
- return err
- }
- }
-
- return nil
-}
-
-// copyOneFile copies a file.
-func copyOneFile(from string, to string) error {
stat, err := os.Stat(from)
if err != nil {
return err