From 7713359c16e4a66966bd539f7e733e1dba7ae824 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Thu, 1 Feb 2024 15:48:40 +0100 Subject: [PATCH] gather more information on exceptions that happen when running tests Signed-off-by: Matthieu Gallien --- src/libsync/propagatedownload.cpp | 38 +++++++++++++------- src/libsync/propagatorjobs.cpp | 46 +++++++++++++++++------- test/testsyncengine.cpp | 60 +++++++++++++++++-------------- 3 files changed, 93 insertions(+), 51 deletions(-) diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 3b77c30150144..a5fadf2792287 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -672,17 +672,23 @@ void PropagateDownloadFile::startDownload() if (_tmpFile.exists()) { FileSystem::setFileReadOnly(_tmpFile.fileName(), false); } - const auto newDirPath = std::filesystem::path{_tmpFile.fileName().toStdWString()}; - Q_ASSERT(newDirPath.has_parent_path()); - _parentFolderPath = newDirPath.parent_path(); - auto parentFolderStatus = std::filesystem::status(_parentFolderPath); - _parentPermissions = parentFolderStatus.permissions(); - if ((_parentPermissions & std::filesystem::perms::owner_write) != std::filesystem::perms::owner_write) { - std::filesystem::permissions(_parentFolderPath, _parentPermissions | std::filesystem::perms::owner_write, std::filesystem::perm_options::replace); - emit propagator()->touchedFile(QString::fromStdWString(_parentFolderPath.wstring())); - _needParentFolderRestorePermissions = true; - } + try { + const auto newDirPath = std::filesystem::path{_tmpFile.fileName().toStdWString()}; + Q_ASSERT(newDirPath.has_parent_path()); + _parentFolderPath = newDirPath.parent_path(); + auto parentFolderStatus = std::filesystem::status(_parentFolderPath); + _parentPermissions = parentFolderStatus.permissions(); + if ((_parentPermissions & std::filesystem::perms::owner_write) != std::filesystem::perms::owner_write) { + std::filesystem::permissions(_parentFolderPath, _parentPermissions | std::filesystem::perms::owner_write, std::filesystem::perm_options::replace); + emit propagator()->touchedFile(QString::fromStdWString(_parentFolderPath.wstring())); + _needParentFolderRestorePermissions = true; + } + } + catch (const std::filesystem::filesystem_error &e) + { + qCWarning(lcPropagateDownload) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str(); + } if (!_tmpFile.open(QIODevice::Append | QIODevice::Unbuffered)) { propagator()->account()->reportClientStatus(ClientStatusReportingStatus::DownloadError_Cannot_Create_File); @@ -1285,9 +1291,15 @@ void PropagateDownloadFile::downloadFinished() } if (_needParentFolderRestorePermissions) { - std::filesystem::permissions(_parentFolderPath, _parentPermissions, std::filesystem::perm_options::replace); - emit propagator()->touchedFile(QString::fromStdWString(_parentFolderPath.wstring())); - _needParentFolderRestorePermissions = false; + try { + std::filesystem::permissions(_parentFolderPath, _parentPermissions, std::filesystem::perm_options::replace); + emit propagator()->touchedFile(QString::fromStdWString(_parentFolderPath.wstring())); + _needParentFolderRestorePermissions = false; + } + catch (const std::filesystem::filesystem_error &e) + { + qCWarning(lcPropagateDownload) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str(); + } } FileSystem::setFileHidden(filename, false); diff --git a/src/libsync/propagatorjobs.cpp b/src/libsync/propagatorjobs.cpp index 8e13f402ad19e..dc8d955ac4adc 100644 --- a/src/libsync/propagatorjobs.cpp +++ b/src/libsync/propagatorjobs.cpp @@ -183,14 +183,22 @@ void PropagateLocalMkdir::startLocalMkdir() return; } - const auto newDirPath = std::filesystem::path{newDirStr.toStdWString()}; - Q_ASSERT(newDirPath.has_parent_path()); - const auto parentFolderPath = newDirPath.parent_path(); - auto parentFolderStatus = std::filesystem::status(parentFolderPath); - const auto parentPermissions = parentFolderStatus.permissions(); - if ((parentPermissions & std::filesystem::perms::owner_write) != std::filesystem::perms::owner_write) { - std::filesystem::permissions(parentFolderPath, parentPermissions | std::filesystem::perms::owner_write, std::filesystem::perm_options::replace); - emit propagator()->touchedFile(QString::fromStdWString(parentFolderPath.wstring())); + auto parentFolderPath = std::filesystem::path{}; + auto parentPermissions = std::filesystem::perms{}; + try { + const auto newDirPath = std::filesystem::path{newDirStr.toStdWString()}; + Q_ASSERT(newDirPath.has_parent_path()); + parentFolderPath = newDirPath.parent_path(); + auto parentFolderStatus = std::filesystem::status(parentFolderPath); + parentPermissions = parentFolderStatus.permissions(); + if ((parentPermissions & std::filesystem::perms::owner_write) != std::filesystem::perms::owner_write) { + std::filesystem::permissions(parentFolderPath, parentPermissions | std::filesystem::perms::owner_write, std::filesystem::perm_options::replace); + emit propagator()->touchedFile(QString::fromStdWString(parentFolderPath.wstring())); + } + } + catch (const std::filesystem::filesystem_error &e) + { + qCWarning(lcPropagateLocalRename) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str(); } emit propagator()->touchedFile(newDirStr); @@ -200,9 +208,15 @@ void PropagateLocalMkdir::startLocalMkdir() return; } - if ((parentPermissions & std::filesystem::perms::owner_write) != std::filesystem::perms::owner_write) { - std::filesystem::permissions(parentFolderPath, parentPermissions, std::filesystem::perm_options::replace); - emit propagator()->touchedFile(QString::fromStdWString(parentFolderPath.wstring())); + try { + if ((parentPermissions & std::filesystem::perms::owner_write) != std::filesystem::perms::owner_write) { + std::filesystem::permissions(parentFolderPath, parentPermissions, std::filesystem::perm_options::replace); + emit propagator()->touchedFile(QString::fromStdWString(parentFolderPath.wstring())); + } + } + catch (const std::filesystem::filesystem_error &e) + { + qCWarning(lcPropagateLocalRename) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str(); } if (!_item->_remotePerm.isNull() && @@ -210,7 +224,15 @@ void PropagateLocalMkdir::startLocalMkdir() !_item->_remotePerm.hasPermission(RemotePermissions::CanRename) && !_item->_remotePerm.hasPermission(RemotePermissions::CanMove) && !_item->_remotePerm.hasPermission(RemotePermissions::CanAddSubDirectories)) { - std::filesystem::permissions(newDirStr.toStdWString(), std::filesystem::perms::owner_write | std::filesystem::perms::group_write | std::filesystem::perms::owner_write, std::filesystem::perm_options::remove); + try { + std::filesystem::permissions(newDirStr.toStdWString(), std::filesystem::perms::owner_write | std::filesystem::perms::group_write | std::filesystem::perms::owner_write, std::filesystem::perm_options::remove); + } + catch (const std::filesystem::filesystem_error &e) + { + qCWarning(lcPropagateLocalRename) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str(); + done(SyncFileItem::NormalError, tr("The folder %1 cannot be made read-only: %2").arg(_item->_file, e.what()), ErrorCategory::GenericError); + return; + } } // Insert the directory into the database. The correct etag will be set later, diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index 8ef503956740a..15ac965f166f2 100644 --- a/test/testsyncengine.cpp +++ b/test/testsyncengine.cpp @@ -15,6 +15,8 @@ #include #include +#include + using namespace OCC; namespace { @@ -813,36 +815,42 @@ private slots: QVERIFY(fakeFolder.currentLocalState().find("A/t𠜎t")); #if !defined(Q_OS_MAC) && !defined(Q_OS_WIN) - // Try again with a locale that can represent ö but not 𠜎 (4-byte utf8). - QTextCodec::setCodecForLocale(QTextCodec::codecForName("ISO-8859-15")); - QVERIFY(QTextCodec::codecForLocale()->mibEnum() == 111); + try { + // Try again with a locale that can represent ö but not 𠜎 (4-byte utf8). + QTextCodec::setCodecForLocale(QTextCodec::codecForName("ISO-8859-15")); + QVERIFY(QTextCodec::codecForLocale()->mibEnum() == 111); - fakeFolder.remoteModifier().insert("B/tößt"); - fakeFolder.remoteModifier().insert("B/t𠜎t"); - QVERIFY(fakeFolder.syncOnce()); - QVERIFY(fakeFolder.currentLocalState().find("B/tößt")); - QVERIFY(!fakeFolder.currentLocalState().find("B/t𠜎t")); - QVERIFY(!fakeFolder.currentLocalState().find("B/t?t")); - QVERIFY(!fakeFolder.currentLocalState().find("B/t??t")); - QVERIFY(!fakeFolder.currentLocalState().find("B/t???t")); - QVERIFY(!fakeFolder.currentLocalState().find("B/t????t")); - QVERIFY(fakeFolder.syncOnce()); - QVERIFY(fakeFolder.currentRemoteState().find("B/tößt")); - QVERIFY(fakeFolder.currentRemoteState().find("B/t𠜎t")); + fakeFolder.remoteModifier().insert("B/tößt"); + fakeFolder.remoteModifier().insert("B/t𠜎t"); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(fakeFolder.currentLocalState().find("B/tößt")); + QVERIFY(!fakeFolder.currentLocalState().find("B/t𠜎t")); + QVERIFY(!fakeFolder.currentLocalState().find("B/t?t")); + QVERIFY(!fakeFolder.currentLocalState().find("B/t??t")); + QVERIFY(!fakeFolder.currentLocalState().find("B/t???t")); + QVERIFY(!fakeFolder.currentLocalState().find("B/t????t")); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(fakeFolder.currentRemoteState().find("B/tößt")); + QVERIFY(fakeFolder.currentRemoteState().find("B/t𠜎t")); - // Try again with plain ascii - QTextCodec::setCodecForLocale(QTextCodec::codecForName("ASCII")); - QVERIFY(QTextCodec::codecForLocale()->mibEnum() == 3); + // Try again with plain ascii + QTextCodec::setCodecForLocale(QTextCodec::codecForName("ASCII")); + QVERIFY(QTextCodec::codecForLocale()->mibEnum() == 3); - fakeFolder.remoteModifier().insert("C/tößt"); - QVERIFY(fakeFolder.syncOnce()); - QVERIFY(!fakeFolder.currentLocalState().find("C/tößt")); - QVERIFY(!fakeFolder.currentLocalState().find("C/t??t")); - QVERIFY(!fakeFolder.currentLocalState().find("C/t????t")); - QVERIFY(fakeFolder.syncOnce()); - QVERIFY(fakeFolder.currentRemoteState().find("C/tößt")); + fakeFolder.remoteModifier().insert("C/tößt"); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(!fakeFolder.currentLocalState().find("C/tößt")); + QVERIFY(!fakeFolder.currentLocalState().find("C/t??t")); + QVERIFY(!fakeFolder.currentLocalState().find("C/t????t")); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(fakeFolder.currentRemoteState().find("C/tößt")); - QTextCodec::setCodecForLocale(utf8Locale); + QTextCodec::setCodecForLocale(utf8Locale); + } + catch (const std::filesystem::filesystem_error &e) + { + qCritical() << e.what() << e.path1().c_str() << e.path2().c_str() << e.code().message().c_str(); + } #endif }