Wrap all use of std::filesystem in ifdefs to fix legacy build for <macOS 10.15

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-03-27 00:58:22 +08:00 committed by Claudio Cambra
parent 9c5b41abda
commit 42504d0a0f
6 changed files with 32 additions and 2 deletions

View File

@ -194,6 +194,7 @@ bool FileSystem::getInode(const QString &filename, quint64 *inode)
return false; 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, bool FileSystem::setFolderPermissions(const QString &path,
FileSystem::FolderPermissions permissions) noexcept FileSystem::FolderPermissions permissions) noexcept
{ {
@ -330,6 +331,7 @@ bool FileSystem::setFolderPermissions(const QString &path,
} }
#endif #endif
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
try { try {
switch (permissions) { switch (permissions) {
case OCC::FileSystem::FolderPermissions::ReadOnly: case OCC::FileSystem::FolderPermissions::ReadOnly:
@ -344,6 +346,7 @@ bool FileSystem::setFolderPermissions(const QString &path,
qCWarning(lcFileSystem()) << "exception when modifying folder permissions" << e.what() << e.path1().c_str() << e.path2().c_str(); qCWarning(lcFileSystem()) << "exception when modifying folder permissions" << e.what() << e.path1().c_str() << e.path2().c_str();
return false; return false;
} }
#endif
return true; return true;
} }
@ -361,6 +364,6 @@ bool FileSystem::isFolderReadOnly(const std::filesystem::path &path) noexcept
return false; return false;
} }
} }
#endif
} // namespace OCC } // namespace OCC

View File

@ -23,7 +23,9 @@
#include <ctime> #include <ctime>
#include <functional> #include <functional>
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
#include <filesystem> #include <filesystem>
#endif
class QFile; class QFile;
@ -101,7 +103,9 @@ namespace FileSystem {
bool OWNCLOUDSYNC_EXPORT setFolderPermissions(const QString &path, bool OWNCLOUDSYNC_EXPORT setFolderPermissions(const QString &path,
FileSystem::FolderPermissions permissions) noexcept; 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; bool OWNCLOUDSYNC_EXPORT isFolderReadOnly(const std::filesystem::path &path) noexcept;
#endif
} }
/** @} */ /** @} */

View File

@ -1443,6 +1443,7 @@ void PropagateDirectory::slotSubJobsFinished(SyncFileItem::Status status)
|| _item->_instruction == CSYNC_INSTRUCTION_NEW || _item->_instruction == CSYNC_INSTRUCTION_NEW
|| _item->_instruction == CSYNC_INSTRUCTION_UPDATE_METADATA) { || _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() && if (!_item->_remotePerm.isNull() &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) && !_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanRename) && !_item->_remotePerm.hasPermission(RemotePermissions::CanRename) &&
@ -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()); _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); const auto result = propagator()->updateMetadata(*_item);
if (!result) { if (!result) {

View File

@ -673,6 +673,7 @@ void PropagateDownloadFile::startDownload()
FileSystem::setFileReadOnly(_tmpFile.fileName(), false); FileSystem::setFileReadOnly(_tmpFile.fileName(), false);
} }
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
try { try {
const auto newDirPath = std::filesystem::path{_tmpFile.fileName().toStdWString()}; const auto newDirPath = std::filesystem::path{_tmpFile.fileName().toStdWString()};
Q_ASSERT(newDirPath.has_parent_path()); Q_ASSERT(newDirPath.has_parent_path());
@ -688,6 +689,7 @@ void PropagateDownloadFile::startDownload()
emit propagator()->touchedFile(QString::fromStdWString(_parentPath.wstring())); emit propagator()->touchedFile(QString::fromStdWString(_parentPath.wstring()));
_needParentFolderRestorePermissions = true; _needParentFolderRestorePermissions = true;
} }
#endif
if (!_tmpFile.open(QIODevice::Append | QIODevice::Unbuffered)) { if (!_tmpFile.open(QIODevice::Append | QIODevice::Unbuffered)) {
qCWarning(lcPropagateDownload) << "could not open temporary file" << _tmpFile.fileName(); qCWarning(lcPropagateDownload) << "could not open temporary file" << _tmpFile.fileName();
@ -1287,11 +1289,13 @@ void PropagateDownloadFile::downloadFinished()
return; return;
} }
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (_needParentFolderRestorePermissions) { if (_needParentFolderRestorePermissions) {
FileSystem::setFolderPermissions(QString::fromStdWString(_parentPath.wstring()), FileSystem::FolderPermissions::ReadWrite); FileSystem::setFolderPermissions(QString::fromStdWString(_parentPath.wstring()), FileSystem::FolderPermissions::ReadWrite);
emit propagator()->touchedFile(QString::fromStdWString(_parentPath.wstring())); emit propagator()->touchedFile(QString::fromStdWString(_parentPath.wstring()));
_needParentFolderRestorePermissions = false; _needParentFolderRestorePermissions = false;
} }
#endif
FileSystem::setFileHidden(filename, false); FileSystem::setFileHidden(filename, false);

View File

@ -23,7 +23,9 @@
#include <QBuffer> #include <QBuffer>
#include <QFile> #include <QFile>
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
#include <filesystem> #include <filesystem>
#endif
namespace OCC { namespace OCC {
class PropagateDownloadEncrypted; class PropagateDownloadEncrypted;
@ -263,7 +265,9 @@ private:
PropagateDownloadEncrypted *_downloadEncryptedHelper = nullptr; PropagateDownloadEncrypted *_downloadEncryptedHelper = nullptr;
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
std::filesystem::path _parentPath; std::filesystem::path _parentPath;
#endif
bool _needParentFolderRestorePermissions = false; bool _needParentFolderRestorePermissions = false;
}; };
} }

View File

@ -32,7 +32,9 @@
#include <qstack.h> #include <qstack.h>
#include <QCoreApplication> #include <QCoreApplication>
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
#include <filesystem> #include <filesystem>
#endif
#include <ctime> #include <ctime>
@ -60,7 +62,9 @@ bool PropagateLocalRemove::removeRecursively(const QString &path)
QString absolute = propagator()->fullLocalPath(_item->_file + path); QString absolute = propagator()->fullLocalPath(_item->_file + path);
QStringList errors; QStringList errors;
QList<QPair<QString, bool>> deleted; 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); FileSystem::setFolderPermissions(absolute, FileSystem::FolderPermissions::ReadWrite);
#endif
bool success = FileSystem::removeRecursively( bool success = FileSystem::removeRecursively(
absolute, absolute,
[&deleted](const QString &path, bool isDir) { [&deleted](const QString &path, bool isDir) {
@ -184,6 +188,7 @@ void PropagateLocalMkdir::startLocalMkdir()
return; return;
} }
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
auto parentFolderPath = std::filesystem::path{}; auto parentFolderPath = std::filesystem::path{};
auto parentNeedRollbackPermissions = false; auto parentNeedRollbackPermissions = false;
try { try {
@ -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(); qCWarning(lcPropagateLocalMkdir) << "exception when checking parent folder access rights" << e.what() << e.path1().c_str() << e.path2().c_str();
} }
#endif
emit propagator()->touchedFile(newDirStr); emit propagator()->touchedFile(newDirStr);
QDir localDir(propagator()->localPath()); QDir localDir(propagator()->localPath());
@ -208,6 +214,7 @@ void PropagateLocalMkdir::startLocalMkdir()
return; return;
} }
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (!_item->_remotePerm.isNull() && if (!_item->_remotePerm.isNull() &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) && !_item->_remotePerm.hasPermission(RemotePermissions::CanAddFile) &&
!_item->_remotePerm.hasPermission(RemotePermissions::CanRename) && !_item->_remotePerm.hasPermission(RemotePermissions::CanRename) &&
@ -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(); 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, // 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. // once all contents have been propagated, because should_update_metadata is true.
@ -304,6 +312,7 @@ void PropagateLocalRename::start()
return; return;
} }
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
auto targetParentFolderPath = std::filesystem::path{}; auto targetParentFolderPath = std::filesystem::path{};
auto targetParentFolderWasReadOnly = false; auto targetParentFolderWasReadOnly = false;
try { try {
@ -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(); 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(existingFile);
emit propagator()->touchedFile(targetFile); emit propagator()->touchedFile(targetFile);
if (QString renameError; !FileSystem::rename(existingFile, targetFile, &renameError)) { 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) { if (targetParentFolderWasReadOnly) {
restoreTargetPermissions(targetParentFolderPath); restoreTargetPermissions(targetParentFolderPath);
} }
if (originParentFolderWasReadOnly) { if (originParentFolderWasReadOnly) {
restoreTargetPermissions(originParentFolderPath); restoreTargetPermissions(originParentFolderPath);
} }
#endif
done(SyncFileItem::NormalError, renameError, ErrorCategory::GenericError); done(SyncFileItem::NormalError, renameError, ErrorCategory::GenericError);
return; return;
} }
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
if (targetParentFolderWasReadOnly) { if (targetParentFolderWasReadOnly) {
restoreTargetPermissions(targetParentFolderPath); restoreTargetPermissions(targetParentFolderPath);
} }
if (originParentFolderWasReadOnly) { if (originParentFolderWasReadOnly) {
restoreTargetPermissions(originParentFolderPath); restoreTargetPermissions(originParentFolderPath);
} }
#endif
} }
SyncJournalFileRecord oldRecord; SyncJournalFileRecord oldRecord;