Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS legacy build breakage caused by std::filesystem #6583

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/libsync/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
return false;
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
bool FileSystem::setFolderPermissions(const QString &path,

Check warning on line 198 in src/libsync/filesystem.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/filesystem.cpp:198:18 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 198 in src/libsync/filesystem.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/filesystem.cpp:198:39 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'setFolderPermissions' of similar type are easily swapped by mistake
FileSystem::FolderPermissions permissions) noexcept
{
try {
Expand Down Expand Up @@ -330,6 +331,7 @@
}
#endif

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15

Check warning on line 334 in src/libsync/filesystem.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/filesystem.cpp:334:2 [readability-redundant-preprocessor]

nested redundant #if; consider removing it
try {
switch (permissions) {
case OCC::FileSystem::FolderPermissions::ReadOnly:
Expand All @@ -344,6 +346,7 @@
qCWarning(lcFileSystem()) << "exception when modifying folder permissions" << e.what() << e.path1().c_str() << e.path2().c_str();
return false;
}
#endif

return true;
}
Expand All @@ -361,6 +364,6 @@
return false;
}
}

#endif

} // namespace OCC
4 changes: 4 additions & 0 deletions src/libsync/filesystem.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/libsync/filesystem.h

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/filesystem.h

File src/libsync/filesystem.h does not conform to Custom style guidelines. (lines 108)
* Copyright (C) by Olivier Goffart <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -14,7 +14,7 @@

#pragma once

#include "config.h"

Check failure on line 17 in src/libsync/filesystem.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/filesystem.h:17:10 [clang-diagnostic-error]

'config.h' file not found

#include "owncloudlib.h"
#include "common/filesystembase.h"
Expand All @@ -23,7 +23,9 @@

#include <ctime>
#include <functional>
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
#include <filesystem>
#endif

class QFile;

Expand Down Expand Up @@ -101,7 +103,9 @@
bool OWNCLOUDSYNC_EXPORT setFolderPermissions(const QString &path,
FileSystem::FolderPermissions permissions) noexcept;

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
bool OWNCLOUDSYNC_EXPORT isFolderReadOnly(const std::filesystem::path &path) noexcept;
#endif
}

/** @} */
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,7 @@ void PropagateDirectory::slotSubJobsFinished(SyncFileItem::Status status)
|| _item->_instruction == CSYNC_INSTRUCTION_NEW
|| _item->_instruction == CSYNC_INSTRUCTION_UPDATE_METADATA) {

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (!_item->_remotePerm.isNull() &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanRename) &&
Expand Down Expand Up @@ -1494,6 +1495,7 @@ void PropagateDirectory::slotSubJobsFinished(SyncFileItem::Status status)
_item->_errorString = tr("The folder %1 cannot be made read-only: %2").arg(e.path1().c_str(), e.what());
}
}
#endif

const auto result = propagator()->updateMetadata(*_item);
if (!result) {
Expand Down
4 changes: 4 additions & 0 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* for more details.
*/

#include "config.h"

Check failure on line 15 in src/libsync/propagatedownload.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagatedownload.cpp:15:10 [clang-diagnostic-error]

'config.h' file not found
#include "owncloudpropagator_p.h"
#include "propagatedownload.h"
#include "networkjobs.h"
Expand Down Expand Up @@ -673,6 +673,7 @@
FileSystem::setFileReadOnly(_tmpFile.fileName(), false);
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
try {
const auto newDirPath = std::filesystem::path{_tmpFile.fileName().toStdWString()};
Q_ASSERT(newDirPath.has_parent_path());
Expand All @@ -688,6 +689,7 @@
emit propagator()->touchedFile(QString::fromStdWString(_parentPath.wstring()));
_needParentFolderRestorePermissions = true;
}
#endif

if (!_tmpFile.open(QIODevice::Append | QIODevice::Unbuffered)) {
qCWarning(lcPropagateDownload) << "could not open temporary file" << _tmpFile.fileName();
Expand Down Expand Up @@ -1164,7 +1166,7 @@
}
}

void PropagateDownloadFile::downloadFinished()

Check warning on line 1169 in src/libsync/propagatedownload.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagatedownload.cpp:1169:29 [readability-function-cognitive-complexity]

function 'downloadFinished' has cognitive complexity of 54 (threshold 25)
{
ASSERT(!_tmpFile.isOpen());
const auto filename = propagator()->fullLocalPath(_item->_file);
Expand Down Expand Up @@ -1287,11 +1289,13 @@
return;
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (_needParentFolderRestorePermissions) {
FileSystem::setFolderPermissions(QString::fromStdWString(_parentPath.wstring()), FileSystem::FolderPermissions::ReadWrite);
emit propagator()->touchedFile(QString::fromStdWString(_parentPath.wstring()));
_needParentFolderRestorePermissions = false;
}
#endif

FileSystem::setFileHidden(filename, false);

Expand Down
4 changes: 4 additions & 0 deletions src/libsync/propagatedownload.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
#pragma once

#include "owncloudlib.h"

Check failure on line 16 in src/libsync/propagatedownload.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagatedownload.h:16:10 [clang-diagnostic-error]

'owncloudlib.h' file not found
#include "owncloudpropagator.h"
#include "networkjobs.h"
#include "clientsideencryption.h"
Expand All @@ -23,7 +23,9 @@
#include <QBuffer>
#include <QFile>

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
#include <filesystem>
#endif

namespace OCC {
class PropagateDownloadEncrypted;
Expand Down Expand Up @@ -263,7 +265,9 @@

PropagateDownloadEncrypted *_downloadEncryptedHelper = nullptr;

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
std::filesystem::path _parentPath;
#endif
bool _needParentFolderRestorePermissions = false;
};
}
15 changes: 14 additions & 1 deletion src/libsync/propagatorjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#include <qstack.h>
#include <QCoreApplication>

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
#include <filesystem>
#endif
#include <ctime>


Expand Down Expand Up @@ -60,7 +62,9 @@ bool PropagateLocalRemove::removeRecursively(const QString &path)
QString absolute = propagator()->fullLocalPath(_item->_file + path);
QStringList errors;
QList<QPair<QString, bool>> deleted;
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
FileSystem::setFolderPermissions(absolute, FileSystem::FolderPermissions::ReadWrite);
#endif
bool success = FileSystem::removeRecursively(
absolute,
[&deleted](const QString &path, bool isDir) {
Expand Down Expand Up @@ -184,6 +188,7 @@ void PropagateLocalMkdir::startLocalMkdir()
return;
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
auto parentFolderPath = std::filesystem::path{};
auto parentNeedRollbackPermissions = false;
try {
Expand All @@ -200,6 +205,7 @@ void PropagateLocalMkdir::startLocalMkdir()
{
qCWarning(lcPropagateLocalMkdir) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str();
}
#endif

emit propagator()->touchedFile(newDirStr);
QDir localDir(propagator()->localPath());
Expand All @@ -208,6 +214,7 @@ void PropagateLocalMkdir::startLocalMkdir()
return;
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (!_item->_remotePerm.isNull() &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanRename) &&
Expand All @@ -234,6 +241,7 @@ void PropagateLocalMkdir::startLocalMkdir()
{
qCWarning(lcPropagateLocalMkdir) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str();
}
#endif

// Insert the directory into the database. The correct etag will be set later,
// once all contents have been propagated, because should_update_metadata is true.
Expand Down Expand Up @@ -304,6 +312,7 @@ void PropagateLocalRename::start()
return;
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
auto targetParentFolderPath = std::filesystem::path{};
auto targetParentFolderWasReadOnly = false;
try {
Expand Down Expand Up @@ -348,27 +357,31 @@ void PropagateLocalRename::start()
qCWarning(lcPropagateLocalRename) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str();
}
};
#endif

emit propagator()->touchedFile(existingFile);
emit propagator()->touchedFile(targetFile);
if (QString renameError; !FileSystem::rename(existingFile, targetFile, &renameError)) {
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (targetParentFolderWasReadOnly) {
restoreTargetPermissions(targetParentFolderPath);
}
if (originParentFolderWasReadOnly) {
restoreTargetPermissions(originParentFolderPath);
}

#endif
done(SyncFileItem::NormalError, renameError, ErrorCategory::GenericError);
return;
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (targetParentFolderWasReadOnly) {
restoreTargetPermissions(targetParentFolderPath);
}
if (originParentFolderWasReadOnly) {
restoreTargetPermissions(originParentFolderPath);
}
#endif
}

SyncJournalFileRecord oldRecord;
Expand Down
4 changes: 4 additions & 0 deletions test/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include <QJsonValue>

#include <memory>
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
#include <filesystem>
#endif

PathComponents::PathComponents(const char *path)
: PathComponents { QString::fromUtf8(path) }
Expand Down Expand Up @@ -50,9 +52,11 @@ void DiskFileModifier::remove(const QString &relativePath)
if (fi.isFile()) {
QVERIFY(_rootDir.remove(relativePath));
} else {
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
const auto pathToDelete = fi.filePath().toStdWString();
std::filesystem::permissions(pathToDelete, std::filesystem::perms::owner_exec, std::filesystem::perm_options::add);
QVERIFY(std::filesystem::remove_all(pathToDelete));
#endif
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/testpermissions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

#include <QtTest>

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
#include <filesystem>
#endif
#include <iostream>

using namespace OCC;
Expand Down Expand Up @@ -77,6 +79,7 @@ private slots:
Logger::instance()->setLogDebug(true);
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
void t7pl()
{
FakeFolder fakeFolder{ FileInfo() };
Expand Down Expand Up @@ -384,6 +387,7 @@ private slots:
QCOMPARE(count, 2);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
#endif

static void setAllPerm(FileInfo *fi, OCC::RemotePermissions perm)
{
Expand Down Expand Up @@ -592,6 +596,7 @@ private slots:
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
static void demo_perms(std::filesystem::perms p)
{
using std::filesystem::perms;
Expand Down Expand Up @@ -741,6 +746,7 @@ private slots:
QVERIFY(testFolderStatus.permissions() & std::filesystem::perms::owner_read);
QVERIFY(!static_cast<bool>(testFolderStatus.permissions() & std::filesystem::perms::owner_write));
}
#endif
};

QTEST_GUILESS_MAIN(TestPermissions)
Expand Down
Loading