From 04684104a172dc7a2d3d52d2667881922ef097d0 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Sun, 26 Jun 2016 13:39:22 +0100 Subject: Permit the upload of a compressed empty file as a package file Permit the upload of a compressed empty file as a package file Adjust a test pacakge to exercise that case --- calm/uploads.py | 22 ++++++++++++--------- .../testpackage2-subpackage-1.0-1.tar.bz2 | Bin 195 -> 14 bytes test/testdata/uploads/pkglist.expected | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/calm/uploads.py b/calm/uploads.py index 59c3d70..d2d75ee 100644 --- a/calm/uploads.py +++ b/calm/uploads.py @@ -170,15 +170,19 @@ def scan(m, all_packages, arch, args): # verify compressed archive files are valid if re.search(r'\.tar\.(bz2|gz|lzma|xz)$', f): valid = True - try: - # we need to extract all of an archive contents to validate - # it - with tarfile.open(fn) as a: - a.getmembers() - except Exception as e: - valid = False - logging.error("exception %s while reading %s" % (type(e).__name__, fn)) - logging.debug('', exc_info=True) + + # accept a compressed empty file, even though it isn't a valid + # compressed archive + if os.path.getsize(fn) > 32: + try: + # we need to extract all of an archive contents to validate + # it + with tarfile.open(fn) as a: + a.getmembers() + except Exception as e: + valid = False + logging.error("exception %s while reading %s" % (type(e).__name__, fn)) + logging.debug('', exc_info=True) if not valid: files.remove(f) diff --git a/test/testdata/homes/Blooey McFooey/x86/release/testpackage2/testpackage2-subpackage/testpackage2-subpackage-1.0-1.tar.bz2 b/test/testdata/homes/Blooey McFooey/x86/release/testpackage2/testpackage2-subpackage/testpackage2-subpackage-1.0-1.tar.bz2 index a1145fb..b56f3b9 100644 Binary files a/test/testdata/homes/Blooey McFooey/x86/release/testpackage2/testpackage2-subpackage/testpackage2-subpackage-1.0-1.tar.bz2 and b/test/testdata/homes/Blooey McFooey/x86/release/testpackage2/testpackage2-subpackage/testpackage2-subpackage-1.0-1.tar.bz2 differ diff --git a/test/testdata/uploads/pkglist.expected b/test/testdata/uploads/pkglist.expected index bbe52b0..695aa09 100644 --- a/test/testdata/uploads/pkglist.expected +++ b/test/testdata/uploads/pkglist.expected @@ -9,6 +9,6 @@ 'ldesc': '"A test subpackage"', 'category': 'Devel', 'external-source': 'testpackage'}), - 'testpackage2-subpackage': Package('x86/release/testpackage2/testpackage2-subpackage', {'testpackage2-subpackage-1.0-1.tar.bz2': Tar('aff488008bee3486e25b539fe6ccd1397bd3c5c0ba2ee2cf34af279554baa195af7493ee51d6f8510735c9a2ea54436d776a71e768165716762aec286abbbf83', 195, False)}, {'sdesc': '"A test subpackage 2"', + 'testpackage2-subpackage': Package('x86/release/testpackage2/testpackage2-subpackage', {'testpackage2-subpackage-1.0-1.tar.bz2': Tar('6de201dfed1d45412509c65deb34690dc2d09c6aafccfe491fd2f440f92842b9c755b61dc7bcdd4cc0c9f18cf46c2b3a1241e99c4c2a33fff5555e7b2f0b6348', 14, True)}, {'sdesc': '"A test subpackage 2"', 'ldesc': '"A test subpackage 2"', 'category': 'Devel'})} -- cgit v1.2.3