From 2173d3ab658502adfc50cbeb3db7df353d3e3671 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Thu, 16 Oct 2014 13:28:08 +0100 Subject: [PATCH] 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. --- files/package_pool.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/files/package_pool.go b/files/package_pool.go index 385ed050..6895766f 100644 --- a/files/package_pool.go +++ b/files/package_pool.go @@ -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