Merge lp:~mandel/ubuntu-download-manager/fix-1250181 into lp:ubuntu-download-manager/saucy

Proposed by Manuel de la Peña
Status: Merged
Merged at revision: 153
Proposed branch: lp:~mandel/ubuntu-download-manager/fix-1250181
Merge into: lp:ubuntu-download-manager/saucy
Diff against target: 81 lines (+37/-1)
3 files modified
libubuntudownloadmanager/group_download.cpp (+12/-0)
ubuntu-download-manager-tests/test_group_download.cpp (+22/-1)
ubuntu-download-manager-tests/test_group_download.h (+3/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/fix-1250181
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+194914@code.launchpad.net

Commit message

Ensure that a local file is only present once in a group download.

Description of the change

Ensure that a local file is only present once in a group download.

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntudownloadmanager/group_download.cpp'
2--- libubuntudownloadmanager/group_download.cpp 2013-09-30 11:07:20 +0000
3+++ libubuntudownloadmanager/group_download.cpp 2013-11-12 18:38:27 +0000
4@@ -70,6 +70,7 @@
5 Q_Q(GroupDownload);
6 QVariantMap metadata = q->metadata();
7 QMap<QString, QString> headers = q->headers();
8+ QStringList localPaths;
9
10 // build downloads and add them to the q, it will take care of
11 // starting them etc..
12@@ -103,6 +104,17 @@
13 headers));
14 }
15
16+ // ensure that the local path is not used by any other download.
17+ QString localFilePath = singleDownload->filePath();
18+ qDebug() << localFilePath;
19+ if (localPaths.contains(localFilePath)) {
20+ q->setIsValid(false);
21+ q->setLastError("Duplicated local path passed: " + localFilePath);
22+ break;
23+ } else {
24+ localPaths.append(localFilePath);
25+ }
26+
27 // check that the download is valid, if it is not set to invalid
28 // and use the last error from the download
29 if (!singleDownload->isValid()) {
30
31=== modified file 'ubuntu-download-manager-tests/test_group_download.cpp'
32--- ubuntu-download-manager-tests/test_group_download.cpp 2013-09-30 11:07:20 +0000
33+++ ubuntu-download-manager-tests/test_group_download.cpp 2013-11-12 18:38:27 +0000
34@@ -30,7 +30,7 @@
35 BaseTestCase::init();
36 _id = QUuid::createUuid();
37 _path = "/group/dbus/path";
38- _isConfined = true;
39+ _isConfined = false;
40 _rootPath = "/random/dbus/path";
41 _algo = "Md5";
42 _isGSMDownloadAllowed = true;
43@@ -902,3 +902,24 @@
44
45 QVERIFY(group->isValid());
46 }
47+
48+void
49+TestGroupDownload::testDuplicatedLocalPath() {
50+ QString filePath = testDirectory() + QDir::separator() + "test_file.jpg";
51+
52+ QList<GroupDownloadStruct> downloadsStruct;
53+ downloadsStruct.append(GroupDownloadStruct("http://one.ubuntu.com",
54+ filePath, ""));
55+ downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
56+ filePath, ""));
57+ downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
58+ "other_reddit_local_file", ""));
59+
60+ GroupDownload* group = new GroupDownload(_id, _path, false, _rootPath,
61+ downloadsStruct, "md5", _isGSMDownloadAllowed, _metadata, _headers,
62+ QSharedPointer<SystemNetworkInfo>(_networkInfo),
63+ QSharedPointer<DownloadFactory>(_downloadFactory),
64+ QSharedPointer<FileManager>(_fileManager));
65+
66+ QVERIFY(!group->isValid());
67+}
68
69=== modified file 'ubuntu-download-manager-tests/test_group_download.h'
70--- ubuntu-download-manager-tests/test_group_download.h 2013-09-25 12:17:16 +0000
71+++ ubuntu-download-manager-tests/test_group_download.h 2013-11-12 18:38:27 +0000
72@@ -78,6 +78,9 @@
73 void testInvalidFilePresent();
74 void testValidFileNotPresent();
75
76+ // ensure that local paths are just used one
77+ void testDuplicatedLocalPath();
78+
79 private:
80 QUuid _id;
81 QString _path;

Subscribers

People subscribed via source and target branches