Fix file truncation bug

This commix prevents files from being truncated when attempting to add
a hard-linked package which already exists inside the pool directory.
This commit is contained in:
Simon Aquino
2014-10-16 13:28:08 +01:00
parent 9c834f410c
commit 2173d3ab65
+10 -6
View File
@@ -128,12 +128,16 @@ func (pool *PackagePool) Import(path string, hashMD5 string) error {
// unable to stat target location?
return err
}
// file doesn't exist, that's ok
} else {
if targetInfo.Size() != sourceInfo.Size() {
// trying to overwrite file?
return fmt.Errorf("unable to import into pool: file %s already exists", poolPath)
}
}
if targetInfo.Size() != sourceInfo.Size() {
// trying to overwrite file?
return fmt.Errorf("unable to import into pool: file %s already exists", poolPath)
}
if os.SameFile(targetInfo, sourceInfo) {
// Same file on the filesystem? Just skip it.
return err
}
// create subdirs as necessary