Skip to content

Commit

Permalink
Merge pull request #7108 from nextcloud/backport/7061/stable-3.14
Browse files Browse the repository at this point in the history
[stable-3.14] Bugfix/delete read only remnants folders
  • Loading branch information
mgallien committed Sep 12, 2024
2 parents 5b504a7 + 1d9080a commit 724aa01
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 115 deletions.
23 changes: 23 additions & 0 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ Folder::Folder(const FolderDefinition &definition,

connect(_engine.data(), &SyncEngine::aboutToRemoveAllFiles,
this, &Folder::slotAboutToRemoveAllFiles);
connect(_engine.data(), &SyncEngine::aboutToRemoveRemnantsReadOnlyFolders,
this, &Folder::slotNeedToRemoveRemnantsReadOnlyFolders);
connect(_engine.data(), &SyncEngine::transmissionProgress, this, &Folder::slotTransmissionProgress);
connect(_engine.data(), &SyncEngine::itemCompleted,
this, &Folder::slotItemCompleted);
Expand Down Expand Up @@ -1664,6 +1666,27 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, std::functio
msgBox->open();
}

void Folder::slotNeedToRemoveRemnantsReadOnlyFolders(const QList<SyncFileItemPtr> &folders,
const QString &localPath,
std::function<void (bool)> callback)
{
auto listOfFolders = QStringList{};
for (const auto &oneFolder : folders) {
listOfFolders.push_back(oneFolder->_file);
}

qCInfo(lcFolder()) << "will delete invalid read-only folders:" << listOfFolders.join(", ");

setSyncPaused(true);
for(const auto &oneFolder : folders) {
FileSystem::removeRecursively(localPath + oneFolder->_file);
}
callback(true);
setSyncPaused(false);
_lastEtag.clear();
slotScheduleThisFolder();
}

void Folder::removeLocalE2eFiles()
{
qCDebug(lcFolder) << "Removing local E2EE files";
Expand Down
4 changes: 4 additions & 0 deletions src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ public slots:
// connected to the corresponding signals in the SyncEngine
void slotAboutToRemoveAllFiles(OCC::SyncFileItem::Direction, std::function<void(bool)> callback);

void slotNeedToRemoveRemnantsReadOnlyFolders(const QList<SyncFileItemPtr> &folders,
const QString &localPath,
std::function<void(bool)> callback);

/**
* Starts a sync operation
*
Expand Down
3 changes: 3 additions & 0 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,11 +1831,13 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)
const auto localPath = QString{_discoveryData->_localDir + item->_file};
qCWarning(lcDisco) << "unexpected new folder in a read-only folder will be made read-write" << localPath;
FileSystem::setFolderPermissions(localPath, FileSystem::FolderPermissions::ReadWrite);
emit _discoveryData->remnantReadOnlyFolderDiscovered(item);
return false;
} else if (!item->isDirectory() && !perms.hasPermission(RemotePermissions::CanAddFile)) {
qCWarning(lcDisco) << "checkForPermission: ERROR" << item->_file;
item->_instruction = CSYNC_INSTRUCTION_ERROR;
item->_errorString = tr("Not allowed because you don't have permission to add files in that folder");
emit _discoveryData->remnantReadOnlyFolderDiscovered(item);
return false;
}
break;
Expand Down Expand Up @@ -2035,6 +2037,7 @@ int ProcessDirectoryJob::processSubJobs(int nbJobs)
const auto localPath = QString{_discoveryData->_localDir + _dirItem->_file};
qCWarning(lcDisco) << "unexpected new folder in a read-only folder will be made read-write" << localPath;
FileSystem::setFolderPermissions(localPath, FileSystem::FolderPermissions::ReadWrite);
emit _discoveryData->remnantReadOnlyFolderDiscovered(_dirItem);
}

_dirItem->_direction = _dirItem->_direction == SyncFileItem::Up ? SyncFileItem::Down : SyncFileItem::Up;
Expand Down
1 change: 1 addition & 0 deletions src/libsync/discoveryphase.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ class DiscoveryPhase : public QObject

void addErrorToGui(const SyncFileItem::Status status, const QString &errorMessage, const QString &subject, const OCC::ErrorCategory category);

void remnantReadOnlyFolderDiscovered(const OCC::SyncFileItemPtr &item);
private slots:
void slotItemDiscovered(const OCC::SyncFileItemPtr &item);
};
Expand Down
12 changes: 12 additions & 0 deletions src/libsync/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
removeOk = removeRecursively(path + QLatin1Char('/') + di.fileName(), onDeleted, errors); // recursive
} else {
QString removeError;

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
const auto fileInfo = QFileInfo{di.filePath()};
const auto parentFolderPath = fileInfo.dir().absolutePath();
const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
#endif
removeOk = FileSystem::remove(di.filePath(), &removeError);
if (removeOk) {
if (onDeleted)
Expand All @@ -289,6 +295,12 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
allRemoved = false;
}
if (allRemoved) {
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
const auto fileInfo = QFileInfo{path};
const auto parentFolderPath = fileInfo.dir().absolutePath();
const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
FileSystem::setFolderPermissions(path, FileSystem::FolderPermissions::ReadWrite);
#endif
allRemoved = QDir().rmdir(path);
if (allRemoved) {
if (onDeleted)
Expand Down
Loading

0 comments on commit 724aa01

Please sign in to comment.