mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Checksums: Make file ownership more explicit
This commit is contained in:
parent
c84ad025b3
commit
dac2801d67
@ -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()) {
|
||||
|
||||
@ -25,6 +25,8 @@
|
||||
#include <QByteArray>
|
||||
#include <QFutureWatcher>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class QFile;
|
||||
|
||||
namespace OCC {
|
||||
@ -82,6 +84,7 @@ class OCSYNC_EXPORT ComputeChecksum : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ComputeChecksum(QObject *parent = 0);
|
||||
~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<QFile> _file;
|
||||
|
||||
// watcher for the checksum calculation thread
|
||||
QFutureWatcher<QByteArray> _watcher;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user