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
This commit is contained in:
@@ -64,18 +64,26 @@ func (n *Node) scan() bool {
|
|||||||
n.Size = n.stat.Size()
|
n.Size = n.stat.Size()
|
||||||
|
|
||||||
// Calculate SHA256.
|
// 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()
|
h := sha256.New()
|
||||||
if _, err := io.Copy(h, f); err != nil {
|
if n.stat.Mode()&os.ModeSymlink == 0 {
|
||||||
panic(err)
|
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))
|
n.SHA256 = fmt.Sprintf("%x", h.Sum(nil))
|
||||||
return true
|
return true
|
||||||
|
Reference in New Issue
Block a user