From 2173d3ab658502adfc50cbeb3db7df353d3e3671 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Thu, 16 Oct 2014 13:28:08 +0100 Subject: [PATCH 1/4] 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 From 951b6e900413018a38c32d781fb3fb557ee031a9 Mon Sep 17 00:00:00 2001 From: Simon Aquino Date: Thu, 16 Oct 2014 14:51:42 +0100 Subject: [PATCH 2/4] Test to avoid published file truncation when added to repo This test will make sure that when a published file is added to repo, it doesn't get truncated. --- system/lib.py | 4 ++++ system/t09_repo/add.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/system/lib.py b/system/lib.py index 2e328bdd..2f4ee6be 100644 --- a/system/lib.py +++ b/system/lib.py @@ -258,6 +258,10 @@ class BaseTest(object): if os.path.exists(os.path.join(os.environ["HOME"], ".aptly", path)): raise Exception("path %s exists" % (path, )) + def check_file_not_empty(self, path): + if os.stat(path)[6] == 0: + raise Exception("file %s is empty" % (path, )) + def check_equal(self, a, b): if a != b: self.verify_match(a, b, match_prepare=pprint.pformat) diff --git a/system/t09_repo/add.py b/system/t09_repo/add.py index 9b5d9319..21e30e7e 100644 --- a/system/t09_repo/add.py +++ b/system/t09_repo/add.py @@ -267,3 +267,19 @@ class AddRepo13Test(BaseTest): # check pool self.check_exists('pool/72/16/dmraid-udeb_1.0.0.rc16-4.1_amd64.udeb') self.check_exists('pool/b7/2c/pyspi_0.6.1-1.3.dsc') + +class AddRepo14Test(BaseTest): + """ + add same package to local repo twice and make sure the file doesn't get truncated. + """ + fixtureCmds = [ + "aptly repo create -comment=Repo1 -distribution=squeeze repo1", + ] + runCmd = "aptly repo add repo1 ${files}/libboost-program-options-dev_1.49.0.1_i386.deb; + aptly repo add repo1 pool/00/35/libboost-program-options-dev_1.49.0.1_i386.deb" + + def check(self): + # check pool + self.check_file_not_empty('pool/00/35/libboost-program-options-dev_1.49.0.1_i386.deb') + + From 2a9871e2e9cb31ce1cbd78c9cc3a28b1eb5734ad Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 17 Oct 2014 00:54:15 +0400 Subject: [PATCH 3/4] We should never ever overwrite files in package pool. #127 --- files/package_pool.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/files/package_pool.go b/files/package_pool.go index 6895766f..a03ebdc0 100644 --- a/files/package_pool.go +++ b/files/package_pool.go @@ -128,16 +128,15 @@ func (pool *PackagePool) Import(path string, hashMD5 string) error { // unable to stat target location? return err } - } + } else { + // target already exists + 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 + // assume that target is already there + return nil } // create subdirs as necessary From 9fbe33b3566173b81f76f3c63944696a7b94b7c8 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 17 Oct 2014 00:54:42 +0400 Subject: [PATCH 4/4] System test for file override from pool. #127 --- system/lib.py | 5 +++-- system/t09_repo/AddRepo14Test_gold | 2 ++ system/t09_repo/add.py | 10 +++++----- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 system/t09_repo/AddRepo14Test_gold diff --git a/system/lib.py b/system/lib.py index 2f4ee6be..7782729e 100644 --- a/system/lib.py +++ b/system/lib.py @@ -156,6 +156,7 @@ class BaseTest(object): 'files': os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files"), 'udebs': os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "udebs"), 'testfiles': os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), self.__class__.__name__), + 'aptlyroot': os.path.join(os.environ["HOME"], ".aptly"), } if self.fixtureWebServer: params['url'] = self.webServerUrl @@ -259,8 +260,8 @@ class BaseTest(object): raise Exception("path %s exists" % (path, )) def check_file_not_empty(self, path): - if os.stat(path)[6] == 0: - raise Exception("file %s is empty" % (path, )) + if os.stat(os.path.join(os.environ["HOME"], ".aptly", path))[6] == 0: + raise Exception("file %s is empty" % (path, )) def check_equal(self, a, b): if a != b: diff --git a/system/t09_repo/AddRepo14Test_gold b/system/t09_repo/AddRepo14Test_gold new file mode 100644 index 00000000..d08ab1e1 --- /dev/null +++ b/system/t09_repo/AddRepo14Test_gold @@ -0,0 +1,2 @@ +Loading packages... +[+] libboost-program-options-dev_1.49.0.1_i386 added diff --git a/system/t09_repo/add.py b/system/t09_repo/add.py index 21e30e7e..3c26cea1 100644 --- a/system/t09_repo/add.py +++ b/system/t09_repo/add.py @@ -268,18 +268,18 @@ class AddRepo13Test(BaseTest): self.check_exists('pool/72/16/dmraid-udeb_1.0.0.rc16-4.1_amd64.udeb') self.check_exists('pool/b7/2c/pyspi_0.6.1-1.3.dsc') + class AddRepo14Test(BaseTest): """ add same package to local repo twice and make sure the file doesn't get truncated. """ fixtureCmds = [ - "aptly repo create -comment=Repo1 -distribution=squeeze repo1", + "aptly repo create -comment=Repo14 -distribution=squeeze repo14", + "aptly repo add repo14 ${files}/libboost-program-options-dev_1.49.0.1_i386.deb" ] - runCmd = "aptly repo add repo1 ${files}/libboost-program-options-dev_1.49.0.1_i386.deb; - aptly repo add repo1 pool/00/35/libboost-program-options-dev_1.49.0.1_i386.deb" + runCmd = "aptly repo add repo14 $aptlyroot/pool/00/35/libboost-program-options-dev_1.49.0.1_i386.deb" def check(self): + super(AddRepo14Test, self).check() # check pool self.check_file_not_empty('pool/00/35/libboost-program-options-dev_1.49.0.1_i386.deb') - -