mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 01:59:07 +00:00
Skip files in contentHash()
If we cannot open file for some reason it is better to skip it instead of exit. Also we should skip symlinks and directories. Signed-off-by: Petr Fedchenkov <giggsoff@gmail.com>
This commit is contained in:
parent
9b636cbf25
commit
49f8faffe0
@ -94,9 +94,20 @@ func (g git) contentHash() (string, error) {
|
||||
}
|
||||
scanner := bufio.NewScanner(strings.NewReader(strings.TrimSpace(out)))
|
||||
for scanner.Scan() {
|
||||
f, err := os.Open(filepath.Join(g.dir, scanner.Text()))
|
||||
filename := filepath.Join(g.dir, scanner.Text())
|
||||
info, err := os.Lstat(filename)
|
||||
if err != nil {
|
||||
return "", err
|
||||
log.Debugf("cannot stat %s: %s, skipped", filename, err)
|
||||
continue
|
||||
}
|
||||
if info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
|
||||
// we do not want to calculate hash of directory or symlinks
|
||||
continue
|
||||
}
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
log.Debugf("cannot open %s: %s, skipped", filename, err)
|
||||
continue
|
||||
}
|
||||
if _, err := io.Copy(hash, f); err != nil {
|
||||
_ = f.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user