aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/fileslist
diff options
context:
space:
mode:
authorSen Jiang <senj@google.com>2017-03-28 15:54:05 -0700
committerSen Jiang <senj@google.com>2017-03-29 13:43:41 -0700
commit1b4141fbdf2d6b277d70e06c6e594583d7ca05b3 (patch)
tree01fb73e23fcd4db08b9490a371dfd7f0a9e292c8 /cmd/fileslist
parent32b692240f01023b92858b163790bf06d194f746 (diff)
downloadbuild_soong-1b4141fbdf2d6b277d70e06c6e594583d7ca05b3.tar.gz
build_soong-1b4141fbdf2d6b277d70e06c6e594583d7ca05b3.tar.bz2
build_soong-1b4141fbdf2d6b277d70e06c6e594583d7ca05b3.zip
fileslist: hash the content of symlink, not the file it points to.
IsDir() doesn't handle the case where the file is a symlink to a directory, which cause fileslist to crash. The hash is used to validate whether system image is the same, so hashing the content of symlink makes more sense. Bug: 36274890 Test: joule builds Change-Id: I6359418a5b28f8da13f85b01a30a72228fecf4ce
Diffstat (limited to 'cmd/fileslist')
-rwxr-xr-xcmd/fileslist/fileslist.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/cmd/fileslist/fileslist.go b/cmd/fileslist/fileslist.go
index 1cf948f7..56ea66d9 100755
--- a/cmd/fileslist/fileslist.go
+++ b/cmd/fileslist/fileslist.go
@@ -64,18 +64,26 @@ func (n *Node) scan() bool {
n.Size = n.stat.Size()
// Calculate SHA256.
- f, err := os.Open(n.path)
- if err != nil {
- // If the file can't be read, it's probably a symlink to an absolute path...
- // Returns the following to mimic the behavior of fileslist.py.
- n.SHA256 = "----------------------------------------------------------------"
- return true
- }
- defer f.Close()
-
h := sha256.New()
- if _, err := io.Copy(h, f); err != nil {
- panic(err)
+ if n.stat.Mode()&os.ModeSymlink == 0 {
+ f, err := os.Open(n.path)
+ if err != nil {
+ panic(err)
+ }
+ defer f.Close()
+
+ if _, err := io.Copy(h, f); err != nil {
+ panic(err)
+ }
+ } else {
+ // Hash the content of symlink, not the file it points to.
+ s, err := os.Readlink(n.path)
+ if err != nil {
+ panic(err)
+ }
+ if _, err := io.WriteString(h, s); err != nil {
+ panic(err)
+ }
}
n.SHA256 = fmt.Sprintf("%x", h.Sum(nil))
return true