Merge "Revert "Handle symlinks in sbox"" into main am: 25861686fe
am: 08f46ee8d4
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2864655 Change-Id: Iee7203f3f75195524bd606b6c74a1ac5e75334d6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -479,8 +478,7 @@ func copyFiles(copies []*sbox_proto.Copy, fromDir, toDir string, exists existsTy
|
||||
// copyOneFile copies a file and its permissions. If forceExecutable is true it adds u+x to the
|
||||
// permissions. If exists is allowFromNotExists it returns nil if the from path doesn't exist.
|
||||
// If write is onlyWriteIfChanged then the output file is compared to the input file and not written to
|
||||
// if it is the same, avoiding updating the timestamp. If from is a symlink, the symlink itself
|
||||
// will be copied, instead of what it points to.
|
||||
// if it is the same, avoiding updating the timestamp.
|
||||
func copyOneFile(from string, to string, forceExecutable bool, exists existsType,
|
||||
write writeType) error {
|
||||
err := os.MkdirAll(filepath.Dir(to), 0777)
|
||||
@@ -488,7 +486,7 @@ func copyOneFile(from string, to string, forceExecutable bool, exists existsType
|
||||
return err
|
||||
}
|
||||
|
||||
stat, err := os.Lstat(from)
|
||||
stat, err := os.Stat(from)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) && exists == allowFromNotExists {
|
||||
return nil
|
||||
@@ -496,25 +494,6 @@ func copyOneFile(from string, to string, forceExecutable bool, exists existsType
|
||||
return err
|
||||
}
|
||||
|
||||
if stat.Mode()&fs.ModeSymlink != 0 {
|
||||
linkTarget, err := os.Readlink(from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if write == onlyWriteIfChanged {
|
||||
toLinkTarget, err := os.Readlink(to)
|
||||
if err == nil && toLinkTarget == linkTarget {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
err = os.Remove(to)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.Symlink(linkTarget, to)
|
||||
}
|
||||
|
||||
perm := stat.Mode()
|
||||
if forceExecutable {
|
||||
perm = perm | 0100 // u+x
|
||||
|
Reference in New Issue
Block a user