Merge lp:~stevenk/launchpad/fixes-bug-387049 into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Michael Nelson
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~stevenk/launchpad/fixes-bug-387049
Merge into: lp:launchpad
Diff against target: 75 lines (+54/-0)
2 files modified
lib/lp/soyuz/scripts/packagecopier.py (+15/-0)
lib/lp/soyuz/scripts/tests/test_copypackage.py (+39/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/fixes-bug-387049
Reviewer Review Type Date Requested Status
Michael Nelson (community) code Approve
Jelmer Vernooij (community) code* Approve
Review via email: mp+22516@code.launchpad.net

Commit message

Forbid copies if the destination archive contains the same files with different contents.

Description of the change

This branch changes the copy package backend so that if the destination archive contains the same files with different contents, CannotCopy is raised and the copy is forbidden.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks.

One really nitpicky comment; PEP8 requires two empty lines between top-level items.

review: Approve (code*)
Revision history for this message
Michael Nelson (michael.nelson) wrote :

> Thanks.
>
> One really nitpicky comment; PEP8 requires two empty lines between top-level
> items.

Cheers Jelmer and Steven,

my only additional comment is that I find:

dfc[file.libraryfile.filename]

hard to read, mainly because of the variable names, but it's just a personal preference. See what you think about the changes below, but feel free to ignore them too :)

> + # Check if files with the same filename already exist in the target
> + destination_file_conflicts = self.archive.getPublishedSources(

s/destination_file_conflicts/destination_source_conflicts

> + name=source.sourcepackagerelease.name)
> + dfc = {}

s/dfc/file_conflicts

> + for file in destination_file_conflicts:

s/file/source_pub

> + for inc_file in file.sourcepackagerelease.files:

s/inc_file/file_alias

> + dfc[inc_file.libraryfile.filename] = inc_file.libraryfile

which would mean this would now be:

                   library_file = file_alias.libraryfile
                   file_conflicts[library_file.filename] = library_file

> + for file in source.sourcepackagerelease.files:
> + if file.libraryfile.filename in dfc.keys():
> + if file.libraryfile != dfc[file.libraryfile.filename]:
> + raise CannotCopy(
> + "%s already exists in destination archive with "
> + "different contents." % file.libraryfile.filename)

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/packagecopier.py'
2--- lib/lp/soyuz/scripts/packagecopier.py 2010-04-09 15:46:09 +0000
3+++ lib/lp/soyuz/scripts/packagecopier.py 2010-04-14 09:58:27 +0000
4@@ -339,6 +339,21 @@
5 raise CannotCopy(
6 "binaries conflicting with the existing ones")
7
8+ # Check if files with the same filename already exist in the target
9+ destination_source_conflicts = self.archive.getPublishedSources(
10+ name=source.sourcepackagerelease.name)
11+ file_conflicts = {}
12+ for source_pub in destination_source_conflicts:
13+ for file_alias in source_pub.sourcepackagerelease.files:
14+ library_file = file_alias.libraryfile
15+ file_conflicts[library_file.filename] = library_file
16+ for lf in source.sourcepackagerelease.files:
17+ if lf.libraryfile.filename in file_conflicts.keys():
18+ if lf.libraryfile != file_conflicts[lf.libraryfile.filename]:
19+ raise CannotCopy(
20+ "%s already exists in destination archive with "
21+ "different contents." % lf.libraryfile.filename)
22+
23 def checkCopy(self, source, series, pocket):
24 """Check if the source can be copied to the given location.
25
26
27=== modified file 'lib/lp/soyuz/scripts/tests/test_copypackage.py'
28--- lib/lp/soyuz/scripts/tests/test_copypackage.py 2010-04-09 15:46:09 +0000
29+++ lib/lp/soyuz/scripts/tests/test_copypackage.py 2010-04-14 09:58:27 +0000
30@@ -2450,6 +2450,45 @@
31
32 publish_copies(copied)
33
34+ def testCopySourceWithConflictingFiles(self):
35+ """We can copy source if the source files match, both in name and
36+ contents. We can't if they don't.
37+ """
38+ ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
39+ warty = ubuntu.getSeries('warty')
40+ hoary = ubuntu.getSeries('hoary')
41+ test_publisher = self.getTestPublisher(warty)
42+ test_publisher.addFakeChroots(warty)
43+
44+ proposed_source = test_publisher.getPubSource(
45+ sourcename='test-source', version='1.0-2',
46+ distroseries=warty, archive=warty.main_archive,
47+ pocket=PackagePublishingPocket.PROPOSED,
48+ status=PackagePublishingStatus.PUBLISHED,
49+ section='net')
50+ proposed_tar = test_publisher.addMockFile(
51+ 'test-source_1.0.orig.tar.gz', filecontent='aaabbbccc')
52+ proposed_source.sourcepackagerelease.addFile(proposed_tar)
53+ updates_source = test_publisher.getPubSource(
54+ sourcename='test-source', version='1.0-1',
55+ distroseries=warty, archive=warty.main_archive,
56+ pocket=PackagePublishingPocket.UPDATES,
57+ status=PackagePublishingStatus.PUBLISHED,
58+ section='misc')
59+ updates_tar = test_publisher.addMockFile(
60+ 'test-source_1.0.orig.tar.gz', filecontent='zzzyyyxxx')
61+ updates_source.sourcepackagerelease.addFile(updates_tar)
62+ # Commit to ensure librarian files are written.
63+ self.layer.txn.commit()
64+
65+ checker = CopyChecker(warty.main_archive, include_binaries=False)
66+ self.assertRaisesWithContent(
67+ CannotCopy,
68+ "test-source_1.0.orig.tar.gz already exists in destination "
69+ "archive with different contents.",
70+ checker.checkCopy, proposed_source, warty,
71+ PackagePublishingPocket.UPDATES)
72+
73
74 def test_suite():
75 return unittest.TestLoader().loadTestsFromName(__name__)