From: Christian Kamm Date: Thu, 15 Nov 2018 08:06:23 +0000 (+0100) Subject: Checksums: Make file ownership more explicit X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~389 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a5264f77407fb5740dd5737e84a51d1be42cc63f;p=nextcloud-desktop.git Checksums: Make file ownership more explicit --- diff --git a/src/common/checksums.cpp b/src/common/checksums.cpp index 3776c601f..354b88f5c 100644 --- a/src/common/checksums.cpp +++ b/src/common/checksums.cpp @@ -208,6 +208,10 @@ ComputeChecksum::ComputeChecksum(QObject *parent) { } +ComputeChecksum::~ComputeChecksum() +{ +} + void ComputeChecksum::setChecksumType(const QByteArray &type) { _checksumType = type; @@ -221,13 +225,13 @@ QByteArray ComputeChecksum::checksumType() const void ComputeChecksum::start(const QString &filePath) { qCInfo(lcChecksums) << "Computing" << checksumType() << "checksum of" << filePath << "in a thread"; - _file = new QFile(filePath, this); + _file.reset(new QFile(filePath)); if (!_file->open(QIODevice::ReadOnly)) { qCWarning(lcChecksums) << "Could not open file" << filePath << "for reading to compute a checksum" << _file->errorString(); emit done(QByteArray(), QByteArray()); return; } - start(_file); + start(_file.get()); } void ComputeChecksum::start(QIODevice *device) @@ -286,8 +290,7 @@ QByteArray ComputeChecksum::computeNow(QIODevice *device, const QByteArray &chec void ComputeChecksum::slotCalculationDone() { // Close the file and delete the instance - if (_file) - delete _file; + _file.reset(nullptr); QByteArray checksum = _watcher.future().result(); if (!checksum.isNull()) { diff --git a/src/common/checksums.h b/src/common/checksums.h index 754e1ae5a..e057fb7ad 100644 --- a/src/common/checksums.h +++ b/src/common/checksums.h @@ -25,6 +25,8 @@ #include #include +#include + class QFile; namespace OCC { @@ -82,6 +84,7 @@ class OCSYNC_EXPORT ComputeChecksum : public QObject Q_OBJECT public: explicit ComputeChecksum(QObject *parent = nullptr); + ~ComputeChecksum(); /** * Sets the checksum type to be used. The default is empty. @@ -129,7 +132,7 @@ private: QByteArray _checksumType; // The convenience wrapper may open a file and must close it too - QFile *_file = nullptr; + std::unique_ptr _file; // watcher for the checksum calculation thread QFutureWatcher _watcher;