mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 15:06:08 +03:00
Checksums: Improve logging and add global disable #5017
This commit is contained in:
parent
096cd348f0
commit
3f7b3ca962
1 changed files with 14 additions and 0 deletions
|
@ -133,6 +133,12 @@ QByteArray contentChecksumType()
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool checksumComputationEnabled()
|
||||||
|
{
|
||||||
|
static bool enabled = qgetenv("OWNCLOUD_DISABLE_CHECKSUM_COMPUTATIONS").isEmpty();
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
ComputeChecksum::ComputeChecksum(QObject *parent)
|
ComputeChecksum::ComputeChecksum(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -150,6 +156,8 @@ QByteArray ComputeChecksum::checksumType() const
|
||||||
|
|
||||||
void ComputeChecksum::start(const QString &filePath)
|
void ComputeChecksum::start(const QString &filePath)
|
||||||
{
|
{
|
||||||
|
qCInfo(lcChecksums) << "Computing" << checksumType() << "checksum of" << filePath << "in a thread";
|
||||||
|
|
||||||
// Calculate the checksum in a different thread first.
|
// Calculate the checksum in a different thread first.
|
||||||
connect(&_watcher, &QFutureWatcherBase::finished,
|
connect(&_watcher, &QFutureWatcherBase::finished,
|
||||||
this, &ComputeChecksum::slotCalculationDone,
|
this, &ComputeChecksum::slotCalculationDone,
|
||||||
|
@ -159,6 +167,11 @@ void ComputeChecksum::start(const QString &filePath)
|
||||||
|
|
||||||
QByteArray ComputeChecksum::computeNow(const QString &filePath, const QByteArray &checksumType)
|
QByteArray ComputeChecksum::computeNow(const QString &filePath, const QByteArray &checksumType)
|
||||||
{
|
{
|
||||||
|
if (!checksumComputationEnabled()) {
|
||||||
|
qCWarning(lcChecksums) << "Checksum computation disabled by environment variable";
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
if (checksumType == checkSumMD5C) {
|
if (checksumType == checkSumMD5C) {
|
||||||
return FileSystem::calcMd5(filePath);
|
return FileSystem::calcMd5(filePath);
|
||||||
} else if (checksumType == checkSumSHA1C) {
|
} else if (checksumType == checkSumSHA1C) {
|
||||||
|
@ -237,6 +250,7 @@ QByteArray CSyncChecksumHook::hook(const QByteArray &path, const QByteArray &oth
|
||||||
if (type.isEmpty())
|
if (type.isEmpty())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
qCInfo(lcChecksums) << "Computing" << type << "checksum of" << path << "in the csync hook";
|
||||||
QByteArray checksum = ComputeChecksum::computeNow(QString::fromUtf8(path), type);
|
QByteArray checksum = ComputeChecksum::computeNow(QString::fromUtf8(path), type);
|
||||||
if (checksum.isNull()) {
|
if (checksum.isNull()) {
|
||||||
qCWarning(lcChecksums) << "Failed to compute checksum" << type << "for" << path;
|
qCWarning(lcChecksums) << "Failed to compute checksum" << type << "for" << path;
|
||||||
|
|
Loading…
Reference in a new issue