Merge lp:~mandel/ubuntu-download-manager/throw-error-exists into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Roberto Alsina
Approved revision: 136
Merged at revision: 146
Proposed branch: lp:~mandel/ubuntu-download-manager/throw-error-exists
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/use-standard-dirs
Diff against target: 231 lines (+139/-10)
6 files modified
libubuntudownloadmanager/group_download.cpp (+8/-9)
libubuntudownloadmanager/single_download.cpp (+16/-0)
ubuntu-download-manager-tests/test_download.cpp (+62/-1)
ubuntu-download-manager-tests/test_download.h (+5/-0)
ubuntu-download-manager-tests/test_group_download.cpp (+46/-0)
ubuntu-download-manager-tests/test_group_download.h (+2/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/throw-error-exists
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+187527@code.launchpad.net

Commit message

Deal with the presence of the download file in a nicer way.

Description of the change

Deal with the presence of the download file in a nicer way. This branch takes care of two possible cases:

1. Local file and not confined app => returns a dbus error.
2. All other cases (either confined or not but with the local path) => appends uuid at the end of the file.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
134. By Manuel de la Peña

Merged use-standard-dirs into throw-error-exists.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
135. By Manuel de la Peña

Merged use-standard-dirs into throw-error-exists.

136. By Manuel de la Peña

Merged with trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libubuntudownloadmanager/group_download.cpp'
--- libubuntudownloadmanager/group_download.cpp 2013-09-27 21:56:44 +0000
+++ libubuntudownloadmanager/group_download.cpp 2013-09-30 11:43:31 +0000
@@ -78,15 +78,6 @@
78 QUrl url(download.getUrl());78 QUrl url(download.getUrl());
79 QString hash = download.getHash();79 QString hash = download.getHash();
8080
81 // before we create the download ensure that the url is valid
82 // if not we set the error and stop the loop
83 if (!url.isValid()) {
84 q->setIsValid(false);
85 q->setLastError(QString("Invalid URL: '%1'").arg(
86 url.toString()));
87 break;
88 }
89
90 SingleDownload* singleDownload;81 SingleDownload* singleDownload;
91 QVariantMap downloadMetadata = QVariantMap(metadata);82 QVariantMap downloadMetadata = QVariantMap(metadata);
92 downloadMetadata[LOCAL_PATH_KEY] = download.getLocalFile();83 downloadMetadata[LOCAL_PATH_KEY] = download.getLocalFile();
@@ -112,6 +103,14 @@
112 headers));103 headers));
113 }104 }
114105
106 // check that the download is valid, if it is not set to invalid
107 // and use the last error from the download
108 if (!singleDownload->isValid()) {
109 q->setIsValid(false);
110 q->setLastError(singleDownload->lastError());
111 break;
112 }
113
115 singleDownload->allowGSMDownload(isGSMDownloadAllowed);114 singleDownload->allowGSMDownload(isGSMDownloadAllowed);
116 _downloads.append(singleDownload);115 _downloads.append(singleDownload);
117 _downloadsProgress[singleDownload->url()] =116 _downloadsProgress[singleDownload->url()] =
118117
=== modified file 'libubuntudownloadmanager/single_download.cpp'
--- libubuntudownloadmanager/single_download.cpp 2013-09-25 09:12:24 +0000
+++ libubuntudownloadmanager/single_download.cpp 2013-09-30 11:43:31 +0000
@@ -28,6 +28,7 @@
28#include "./single_download.h"28#include "./single_download.h"
29#include "./network_reply.h"29#include "./network_reply.h"
3030
31
31#define DATA_FILE_NAME "data.download"32#define DATA_FILE_NAME "data.download"
32#define METADATA_FILE_NAME "metadata"33#define METADATA_FILE_NAME "metadata"
33#define METADATA_COMMAND_KEY "post-download-command"34#define METADATA_COMMAND_KEY "post-download-command"
@@ -417,8 +418,23 @@
417 if (!q->isConfined() && metadata.contains(LOCAL_PATH_KEY)) {418 if (!q->isConfined() && metadata.contains(LOCAL_PATH_KEY)) {
418 qDebug() << "App is not confined and provided a local path";419 qDebug() << "App is not confined and provided a local path";
419 finalPath = metadata[LOCAL_PATH_KEY].toString();420 finalPath = metadata[LOCAL_PATH_KEY].toString();
421
422 // in this case and because the app is not confined we are
423 // going to check if the file exists, if it does we will
424 // raise an error
425 if (QFile::exists(finalPath)) {
426 q->setIsValid(false);
427 q->setLastError(QString("File already exists at: '%1'").arg(
428 finalPath));
429 }
420 } else {430 } else {
421 finalPath = q->rootPath() + QDir::separator() + basename;431 finalPath = q->rootPath() + QDir::separator() + basename;
432
433 // check if the file exists, if it does lets append the uuid to it
434 if (QFile::exists(finalPath)) {
435 finalPath += q->downloadId().toString().replace(
436 QRegExp("[-{}]"), "");
437 }
422 }438 }
423439
424 return finalPath;440 return finalPath;
425441
=== modified file 'ubuntu-download-manager-tests/test_download.cpp'
--- ubuntu-download-manager-tests/test_download.cpp 2013-09-27 23:43:33 +0000
+++ ubuntu-download-manager-tests/test_download.cpp 2013-09-30 11:43:31 +0000
@@ -54,7 +54,6 @@
54 delete _reqFactory;54 delete _reqFactory;
55 if (_processFactory)55 if (_processFactory)
56 delete _processFactory;56 delete _processFactory;
57
58}57}
5958
60void59void
@@ -1750,3 +1749,65 @@
1750 QSharedPointer<ProcessFactory>(_processFactory));1749 QSharedPointer<ProcessFactory>(_processFactory));
1751 QVERIFY(download->isValid());1750 QVERIFY(download->isValid());
1752}1751}
1752
1753void
1754TestDownload::testInvalidFilePresent() {
1755 // create a file so that we get an error
1756 QString filePath = testDirectory() + QDir::separator() + "test_file.jpg";
1757 QFile* file = new QFile(filePath);
1758 file->open(QIODevice::ReadWrite | QFile::Append);
1759 file->write("data data data!");
1760 file->close();
1761
1762 QVariantMap metadata;
1763 metadata["local-path"] = filePath;
1764
1765 SingleDownload* download = new SingleDownload(_id, _path, false,
1766 _rootPath, _url, metadata, _headers,
1767 QSharedPointer<SystemNetworkInfo>(_networkInfo),
1768 QSharedPointer<RequestFactory>(_reqFactory),
1769 QSharedPointer<ProcessFactory>(_processFactory));
1770 QVERIFY(!download->isValid());
1771}
1772
1773void
1774TestDownload::testValidFileNotPresent() {
1775 QString filePath = testDirectory() + QDir::separator() + "test_file.jpg";
1776
1777 QVariantMap metadata;
1778 metadata["local-path"] = filePath;
1779
1780 SingleDownload* download = new SingleDownload(_id, _path, false,
1781 _rootPath, _url, metadata, _headers,
1782 QSharedPointer<SystemNetworkInfo>(_networkInfo),
1783 QSharedPointer<RequestFactory>(_reqFactory),
1784 QSharedPointer<ProcessFactory>(_processFactory));
1785 QVERIFY(download->isValid());
1786}
1787
1788void
1789TestDownload::testDownloadPresent() {
1790 // create a download and get the filename to use, then write it
1791 // and create the same download and assert that the filename is diff
1792
1793 SingleDownload* download = new SingleDownload(_id, _path, true,
1794 _rootPath, _url, _metadata, _headers,
1795 QSharedPointer<SystemNetworkInfo>(_networkInfo),
1796 QSharedPointer<RequestFactory>(_reqFactory),
1797 QSharedPointer<ProcessFactory>(_processFactory));
1798
1799 QString filePath = download->filePath();
1800
1801 QFile* file = new QFile(filePath);
1802 file->open(QIODevice::ReadWrite | QFile::Append);
1803 file->write("data data data!");
1804 file->close();
1805
1806 download = new SingleDownload(_id, _path, true,
1807 _rootPath, _url, _metadata, _headers,
1808 QSharedPointer<SystemNetworkInfo>(_networkInfo),
1809 QSharedPointer<RequestFactory>(_reqFactory),
1810 QSharedPointer<ProcessFactory>(_processFactory));
1811
1812 QVERIFY(filePath != download->filePath());
1813}
17531814
=== modified file 'ubuntu-download-manager-tests/test_download.h'
--- ubuntu-download-manager-tests/test_download.h 2013-09-25 10:30:57 +0000
+++ ubuntu-download-manager-tests/test_download.h 2013-09-30 11:43:31 +0000
@@ -130,6 +130,11 @@
130 void testInvalidHashAlgorithm();130 void testInvalidHashAlgorithm();
131 void testValidHashAlgorithm_data();131 void testValidHashAlgorithm_data();
132 void testValidHashAlgorithm();132 void testValidHashAlgorithm();
133 void testInvalidFilePresent();
134 void testValidFileNotPresent();
135
136 // filename tests
137 void testDownloadPresent();
133138
134 private:139 private:
135 QUuid _id;140 QUuid _id;
136141
=== modified file 'ubuntu-download-manager-tests/test_group_download.cpp'
--- ubuntu-download-manager-tests/test_group_download.cpp 2013-09-27 23:43:33 +0000
+++ ubuntu-download-manager-tests/test_group_download.cpp 2013-09-30 11:43:31 +0000
@@ -856,3 +856,49 @@
856856
857 QVERIFY(group->isValid());857 QVERIFY(group->isValid());
858}858}
859
860void
861TestGroupDownload::testInvalidFilePresent() {
862 QString filePath = testDirectory() + QDir::separator() + "test_file.jpg";
863 QFile* file = new QFile(filePath);
864 file->open(QIODevice::ReadWrite | QFile::Append);
865 file->write("data data data!");
866 file->close();
867
868 QList<GroupDownloadStruct> downloadsStruct;
869 downloadsStruct.append(GroupDownloadStruct("http://one.ubuntu.com",
870 "local_file", ""));
871 downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
872 filePath, ""));
873 downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
874 "other_reddit_local_file", ""));
875
876 GroupDownload* group = new GroupDownload(_id, _path, false, _rootPath,
877 downloadsStruct, "md5", _isGSMDownloadAllowed, _metadata, _headers,
878 QSharedPointer<SystemNetworkInfo>(_networkInfo),
879 QSharedPointer<DownloadFactory>(_downloadFactory),
880 QSharedPointer<FileManager>(_fileManager));
881
882 QVERIFY(!group->isValid());
883}
884
885void
886TestGroupDownload::testValidFileNotPresent() {
887 QString filePath = testDirectory() + QDir::separator() + "test_file.jpg";
888
889 QList<GroupDownloadStruct> downloadsStruct;
890 downloadsStruct.append(GroupDownloadStruct("http://one.ubuntu.com",
891 "local_file", ""));
892 downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
893 filePath, ""));
894 downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
895 "other_reddit_local_file", ""));
896
897 GroupDownload* group = new GroupDownload(_id, _path, false, _rootPath,
898 downloadsStruct, "md5", _isGSMDownloadAllowed, _metadata, _headers,
899 QSharedPointer<SystemNetworkInfo>(_networkInfo),
900 QSharedPointer<DownloadFactory>(_downloadFactory),
901 QSharedPointer<FileManager>(_fileManager));
902
903 QVERIFY(group->isValid());
904}
859905
=== modified file 'ubuntu-download-manager-tests/test_group_download.h'
--- ubuntu-download-manager-tests/test_group_download.h 2013-09-25 10:30:57 +0000
+++ ubuntu-download-manager-tests/test_group_download.h 2013-09-30 11:43:31 +0000
@@ -75,6 +75,8 @@
75 void testInvalidHashAlgorithm();75 void testInvalidHashAlgorithm();
76 void testValidHashAlgorithm_data();76 void testValidHashAlgorithm_data();
77 void testValidHashAlgorithm();77 void testValidHashAlgorithm();
78 void testInvalidFilePresent();
79 void testValidFileNotPresent();
7880
79 private:81 private:
80 QUuid _id;82 QUuid _id;

Subscribers

People subscribed via source and target branches