Merge lp:~mandel/ubuntu-download-manager/remove-after-process into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 150
Merged at revision: 148
Proposed branch: lp:~mandel/ubuntu-download-manager/remove-after-process
Merge into: lp:ubuntu-download-manager
Diff against target: 83 lines (+51/-0)
3 files modified
libubuntudownloadmanager/single_download.cpp (+4/-0)
ubuntu-download-manager-tests/test_download.cpp (+46/-0)
ubuntu-download-manager-tests/test_download.h (+1/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/remove-after-process
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Diego Sarmentero (community) Approve
Review via email: mp+188798@code.launchpad.net

Commit message

Remove the file after the successful execution of the post-download command line.

Description of the change

Remove the file after the successful execution of the post-download command line.

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

Fix missing var.

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

Fix broken tests.

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntudownloadmanager/single_download.cpp'
2--- libubuntudownloadmanager/single_download.cpp 2013-09-25 12:17:16 +0000
3+++ libubuntudownloadmanager/single_download.cpp 2013-10-09 18:58:40 +0000
4@@ -352,6 +352,10 @@
5 qDebug() << __PRETTY_FUNCTION__ << exitCode << exitStatus;
6 Q_Q(SingleDownload);
7 if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
8+ // remove the file since we are done with it
9+ bool success = QFile::remove(_filePath);
10+ if (!success)
11+ qWarning() << "Error removing" << _filePath;
12 q->setState(Download::FINISH);
13 qDebug() << "EMIT finished" << filePath();
14 emit q->finished(filePath());
15
16=== modified file 'ubuntu-download-manager-tests/test_download.cpp'
17--- ubuntu-download-manager-tests/test_download.cpp 2013-09-30 11:07:20 +0000
18+++ ubuntu-download-manager-tests/test_download.cpp 2013-10-09 18:58:40 +0000
19@@ -1550,6 +1550,52 @@
20 }
21
22 void
23+TestDownload::testFileRemoveAfterSuccessfulProcess() {
24+ // assert that the file is indeed removed
25+ QVariantMap metadata;
26+ QStringList command;
27+ command << "grep" << "$file" << "-Rn";
28+ metadata["post-download-command"] = command;
29+
30+ _processFactory->record();
31+ _reqFactory->record();
32+ SingleDownload* download = new SingleDownload(_id, _path, _isConfined,
33+ _rootPath, _url, metadata, _headers,
34+ QSharedPointer<SystemNetworkInfo>(_networkInfo),
35+ QSharedPointer<RequestFactory>(_reqFactory),
36+ QSharedPointer<ProcessFactory>(_processFactory));
37+
38+ // write something in the expected file
39+ QString fileName = download->filePath();
40+ QFile* file = new QFile(fileName);
41+ file->open(QIODevice::ReadWrite | QFile::Append);
42+ file->write("my data goes here");
43+ file->close();
44+
45+ download->start(); // change state
46+ download->startDownload();
47+
48+ // we need to set the data before we pause!!!
49+ QList<MethodData> calledMethods = _reqFactory->calledMethods();
50+ QCOMPARE(1, calledMethods.count());
51+ FakeNetworkReply* reply = reinterpret_cast<FakeNetworkReply*>(
52+ calledMethods[0].params().outParams()[0]);
53+
54+ // makes the process to be executed
55+ reply->emitFinished();
56+
57+ calledMethods = _processFactory->calledMethods();
58+ QCOMPARE(1, calledMethods.count());
59+ FakeProcess* process = reinterpret_cast<FakeProcess*>(
60+ calledMethods[0].params().outParams()[0]);
61+
62+ // emit the finished signal with a result > 0 and ensure error is emitted
63+ process->emitFinished(0, QProcess::NormalExit);
64+ // asser that the file does not longer exist in the system
65+ QVERIFY(!QFile::exists(fileName));
66+}
67+
68+void
69 TestDownload::testSetRawHeaderAcceptEncoding_data() {
70 QTest::addColumn<QMap<QString, QString> >("headers");
71
72
73=== modified file 'ubuntu-download-manager-tests/test_download.h'
74--- ubuntu-download-manager-tests/test_download.h 2013-09-25 12:17:16 +0000
75+++ ubuntu-download-manager-tests/test_download.h 2013-10-09 18:58:40 +0000
76@@ -111,6 +111,7 @@
77 void testProcessFinishedNoError();
78 void testProcessFinishedWithError();
79 void testProcessFinishedCrash();
80+ void testFileRemoveAfterSuccessfulProcess();
81
82 // test related to bug #1224678
83 void testSetRawHeaderAcceptEncoding_data();

Subscribers

People subscribed via source and target branches