Merge lp:~mandel/ubuntu-download-manager/improve-file-logging into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 212
Merged at revision: 212
Proposed branch: lp:~mandel/ubuntu-download-manager/improve-file-logging
Merge into: lp:ubuntu-download-manager
Diff against target: 174 lines (+30/-26)
1 file modified
ubuntu-download-manager-priv/downloads/file_download.cpp (+30/-26)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/improve-file-logging
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
PS Jenkins bot continuous-integration Approve
Diego Sarmentero (community) Approve
Review via email: mp+201751@code.launchpad.net

Commit message

Ensure that the error code from a fail file removal is logged.

Description of the change

Ensure that the error code from a fail file removal is logged.

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
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Mike McCracken (mikemc) wrote :

Thanks for adding the logging, no thanks for throwing in a bunch of unrelated nullptr changes. (And not even in a separate revision!)

Mostly kidding, thanks for doing this so quickly.

review: Approve
Revision history for this message
Manuel de la Peña (mandel) wrote :

> Thanks for adding the logging, no thanks for throwing in a bunch of unrelated nullptr changes.
> (And not even in a separate revision!)

Sorry!!! I wanted to remove NULL for nullptr because is more C++

> Mostly kidding, thanks for doing this so quickly.

But nevertheless right.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu-download-manager-priv/downloads/file_download.cpp'
2--- ubuntu-download-manager-priv/downloads/file_download.cpp 2013-12-20 22:57:15 +0000
3+++ ubuntu-download-manager-priv/downloads/file_download.cpp 2014-01-15 11:01:16 +0000
4@@ -84,7 +84,7 @@
5 }
6
7 FileDownload::~FileDownload() {
8- if (_currentData != NULL) {
9+ if (_currentData != nullptr) {
10 _currentData->close();
11 }
12 delete _currentData;
13@@ -95,13 +95,13 @@
14 FileDownload::cancelDownload() {
15 TRACE << _url;
16
17- if (_reply != NULL) {
18+ if (_reply != nullptr) {
19 // disconnect so that we do not get useless signals
20 // and remove the reply
21 disconnectFromReplySignals();
22 _reply->abort();
23 _reply->deleteLater();
24- _reply = NULL;
25+ _reply = nullptr;
26 }
27
28 // remove current data and metadata
29@@ -114,7 +114,7 @@
30 FileDownload::pauseDownload() {
31 TRACE << _url;
32
33- if (_reply == NULL) {
34+ if (_reply == nullptr) {
35 // cannot pause because is not running
36 qDebug() << "Cannot pause download because reply is NULL";
37 qDebug() << "EMIT paused(false)";
38@@ -135,7 +135,7 @@
39 emit paused(false);
40 } else {
41 _reply->deleteLater();
42- _reply = NULL;
43+ _reply = nullptr;
44 qDebug() << "EMIT paused(true)";
45 _downloading = false;
46 emit paused(true);
47@@ -146,7 +146,7 @@
48 FileDownload::resumeDownload() {
49 qDebug() << __PRETTY_FUNCTION__ << _url;
50
51- if (_reply != NULL) {
52+ if (_reply != nullptr) {
53 // cannot resume because it is already running
54 qDebug() << "Cannot resume download because reply != NULL";
55 qDebug() << "EMIT resumed(false)";
56@@ -177,7 +177,7 @@
57 FileDownload::startDownload() {
58 TRACE << _url;
59
60- if (_reply != NULL) {
61+ if (_reply != nullptr) {
62 // the download was already started, lets say that we did it
63 qDebug() << "Cannot start download because reply != NULL";
64 qDebug() << "EMIT started(false)";
65@@ -208,7 +208,7 @@
66
67 qulonglong
68 FileDownload::progress() {
69- return (_currentData == NULL) ? 0 : _currentData->size();
70+ return (_currentData == nullptr) ? 0 : _currentData->size();
71 }
72
73 qulonglong
74@@ -220,7 +220,7 @@
75 FileDownload::setThrottle(qulonglong speed) {
76 TRACE << _url;
77 Download::setThrottle(speed);
78- if (_reply != NULL)
79+ if (_reply != nullptr)
80 _reply->setReadBufferSize(speed);
81 }
82
83@@ -336,7 +336,7 @@
84
85 // clean the reply
86 _reply->deleteLater();
87- _reply = NULL;
88+ _reply = nullptr;
89 }
90
91 void
92@@ -359,9 +359,7 @@
93 TRACE << exitCode << exitStatus;
94 if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
95 // remove the file since we are done with it
96- bool success = QFile::remove(_filePath);
97- if (!success)
98- qWarning() << "Error removing" << _filePath;
99+ cleanUpCurrentData();
100 setState(Download::FINISH);
101 qDebug() << "EMIT finished" << filePath();
102 emit finished(filePath());
103@@ -385,7 +383,7 @@
104
105 // if no longer online yet we have a reply (that is, we are trying
106 // to get data from the missing connection) we pause
107- if (!_connected && _reply != NULL) {
108+ if (!_connected && _reply != nullptr) {
109 pauseDownload();
110 // set it to be downloading even when pause download sets it
111 // to false
112@@ -415,7 +413,7 @@
113
114 void
115 FileDownload::connectToReplySignals() {
116- if (_reply != NULL) {
117+ if (_reply != nullptr) {
118 connect(_reply, &NetworkReply::downloadProgress,
119 this, &FileDownload::onDownloadProgress);
120 connect(_reply, &NetworkReply::error,
121@@ -429,7 +427,7 @@
122
123 void
124 FileDownload::disconnectFromReplySignals() {
125- if (_reply != NULL) {
126+ if (_reply != nullptr) {
127 disconnect(_reply, &NetworkReply::downloadProgress,
128 this, &FileDownload::onDownloadProgress);
129 disconnect(_reply, &NetworkReply::error,
130@@ -488,20 +486,26 @@
131
132 void
133 FileDownload::cleanUpCurrentData() {
134- bool success;
135- QString fileName;
136- if (_currentData) {
137- // delete the current data, we did cancel.
138- fileName = _currentData->fileName();
139+ bool success = true;
140+ QFile::FileError error = QFile::NoError;
141+ if (_currentData != nullptr) {
142 success = _currentData->remove();
143+
144+ if (!success)
145+ error = _currentData->error();
146+
147 _currentData->deleteLater();
148- _currentData = NULL;
149+ _currentData = nullptr;
150+ } else {
151+ QScopedPointer<QFile> tempFile(new QFile(_filePath));
152+ success = tempFile->remove();
153 if (!success)
154- qWarning() << "Error removing" << fileName;
155+ error = tempFile->error();
156 }
157- success = QFile::remove(_filePath);
158+
159 if (!success)
160- qWarning() << "Error removing" << _filePath;
161+ qWarning() << "Error " << error <<
162+ "removing file with path" << _filePath;
163 }
164
165 QNetworkRequest
166@@ -527,7 +531,7 @@
167 TRACE << error;
168 disconnectFromReplySignals();
169 _reply->deleteLater();
170- _reply = NULL;
171+ _reply = nullptr;
172 cleanUpCurrentData();
173 Download::emitError(error);
174 }

Subscribers

People subscribed via source and target branches