From d03797e48a33a8f03a37a935cabc5c00478faf22 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 25 Nov 2020 10:24:51 -0800 Subject: [PATCH] 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 --- cmd/sbox/sbox.go | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/cmd/sbox/sbox.go b/cmd/sbox/sbox.go index db483f168..633c6b2cb 100644 --- a/cmd/sbox/sbox.go +++ b/cmd/sbox/sbox.go @@ -207,7 +207,7 @@ func runCommand(command *sbox_proto.Command, tempDir string) (depFile string, er } // 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 @@ func validateOutputFiles(copies []*sbox_proto.Copy, sandboxDir string) []error { 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 @@ func linkOrCopyFiles(copies []*sbox_proto.Copy, fromDir, toDir string) error { 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