Merge lp:~cjwatson/launchpad/gina-remove-source-dir into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18950
Proposed branch: lp:~cjwatson/launchpad/gina-remove-source-dir
Merge into: lp:launchpad
Diff against target: 112 lines (+33/-26)
2 files modified
lib/lp/soyuz/scripts/gina/packages.py (+29/-24)
lib/lp/soyuz/scripts/tests/test_gina.py (+4/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/gina-remove-source-dir
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+366624@code.launchpad.net

Commit message

Clean up gina temporary directories more carefully.

Description of the change

AbstractPackageData.process_package does clean up the whole temporary directory already, but gina didn't do any finer-grained cleanup. This caused a test failure on bionic, because dpkg-source now refuses to overwrite a directory that already exists. We now clean up more carefully in unpack_dsc and read_dsc.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/scripts/gina/packages.py'
2--- lib/lp/soyuz/scripts/gina/packages.py 2018-05-06 08:52:34 +0000
3+++ lib/lp/soyuz/scripts/gina/packages.py 2019-04-28 17:02:38 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Package information classes.
10@@ -105,14 +105,16 @@
11 def unpack_dsc(package, version, component, distro_name, archive_root):
12 dsc_name, dsc_path, component = get_dsc_path(package, version,
13 component, archive_root)
14+ version = re.sub("^\d+:", "", version)
15+ version = re.sub("-[^-]+$", "", version)
16+ source_dir = "%s-%s" % (package, version)
17 try:
18 extract_dpkg_source(dsc_path, ".", vendor=distro_name)
19 except DpkgSourceError as e:
20+ if os.path.isdir(source_dir):
21+ shutil.rmtree(source_dir)
22 raise ExecutionError("Error %d unpacking source" % e.result)
23
24- version = re.sub("^\d+:", "", version)
25- version = re.sub("-[^-]+$", "", version)
26- source_dir = "%s-%s" % (package, version)
27 return source_dir, dsc_path
28
29
30@@ -120,28 +122,31 @@
31 source_dir, dsc_path = unpack_dsc(package, version, component,
32 distro_name, archive_root)
33
34- dsc = open(dsc_path).read().strip()
35+ try:
36+ dsc = open(dsc_path).read().strip()
37
38- fullpath = os.path.join(source_dir, "debian", "changelog")
39- changelog = None
40- if os.path.exists(fullpath):
41- changelog = open(fullpath).read().strip()
42- else:
43- log.warn("No changelog file found for %s in %s" %
44- (package, source_dir))
45+ fullpath = os.path.join(source_dir, "debian", "changelog")
46 changelog = None
47-
48- copyright = None
49- globpath = os.path.join(source_dir, "debian", "*copyright")
50- for fullpath in glob.glob(globpath):
51- if not os.path.exists(fullpath):
52- continue
53- copyright = open(fullpath).read().strip()
54-
55- if copyright is None:
56- log.warn(
57- "No copyright file found for %s in %s" % (package, source_dir))
58- copyright = ''
59+ if os.path.exists(fullpath):
60+ changelog = open(fullpath).read().strip()
61+ else:
62+ log.warn("No changelog file found for %s in %s" %
63+ (package, source_dir))
64+ changelog = None
65+
66+ copyright = None
67+ globpath = os.path.join(source_dir, "debian", "*copyright")
68+ for fullpath in glob.glob(globpath):
69+ if not os.path.exists(fullpath):
70+ continue
71+ copyright = open(fullpath).read().strip()
72+
73+ if copyright is None:
74+ log.warn(
75+ "No copyright file found for %s in %s" % (package, source_dir))
76+ copyright = ''
77+ finally:
78+ shutil.rmtree(source_dir)
79
80 return dsc, changelog, copyright
81
82
83=== modified file 'lib/lp/soyuz/scripts/tests/test_gina.py'
84--- lib/lp/soyuz/scripts/tests/test_gina.py 2016-03-20 22:47:48 +0000
85+++ lib/lp/soyuz/scripts/tests/test_gina.py 2019-04-28 17:02:38 +0000
86@@ -1,4 +1,4 @@
87-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
88+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
89 # GNU Affero General Public License version 3 (see the file LICENSE).
90
91 from doctest import DocTestSuite
92@@ -20,8 +20,8 @@
93 from lp.services.database.constants import UTC_NOW
94 from lp.services.features.testing import FeatureFixture
95 from lp.services.log.logger import DevNullLogger
96+from lp.services.osutils import write_file
97 from lp.services.tarfile_helpers import LaunchpadWriteTarFile
98-from lp.services.osutils import write_file
99 from lp.soyuz.enums import PackagePublishingStatus
100 from lp.soyuz.scripts.gina import ExecutionError
101 from lp.soyuz.scripts.gina.archive import (
102@@ -276,8 +276,10 @@
103 # Unpacking this in an Ubuntu context fails.
104 self.assertRaises(
105 ExecutionError, sp_data.do_package, "ubuntu", archive_root)
106+ self.assertFalse(os.path.exists("foo-1.0"))
107 # But all is well in a Debian context.
108 sp_data.do_package("debian", archive_root)
109+ self.assertFalse(os.path.exists("foo-1.0"))
110
111 def test_process_package_cleans_up_after_unpack_failure(self):
112 archive_root = self.useTempDir()