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

[stable-3.12] Fix crash when deleting a local sync folder during sync. #6481

Merged
merged 1 commit into from
Feb 23, 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
45 changes: 32 additions & 13 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,19 +561,21 @@

auto relativePath = path.midRef(this->path().size());

if (pathIsIgnored(path)) {
const auto pinState = _vfs->pinState(relativePath.toString());
if (!pinState || *pinState != PinState::Excluded) {
if (!_vfs->setPinState(relativePath.toString(), PinState::Excluded)) {
qCWarning(lcFolder) << "Could not set pin state of" << relativePath << "to excluded";
if (_vfs) {
if (pathIsIgnored(path)) {
const auto pinState = _vfs->pinState(relativePath.toString());
if (!pinState || *pinState != PinState::Excluded) {
if (!_vfs->setPinState(relativePath.toString(), PinState::Excluded)) {
qCWarning(lcFolder) << "Could not set pin state of" << relativePath << "to excluded";
}
}
}
return;
} else {
const auto pinState = _vfs->pinState(relativePath.toString());
if (pinState && *pinState == PinState::Excluded) {
if (!_vfs->setPinState(relativePath.toString(), PinState::Inherited)) {
qCWarning(lcFolder) << "Could not switch pin state of" << relativePath << "from" << *pinState << "to inherited";
return;
} else {

Check warning on line 573 in src/gui/folder.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/folder.cpp:573:11 [readability-else-after-return]

do not use 'else' after 'return'
const auto pinState = _vfs->pinState(relativePath.toString());
if (pinState && *pinState == PinState::Excluded) {
if (!_vfs->setPinState(relativePath.toString(), PinState::Inherited)) {
qCWarning(lcFolder) << "Could not switch pin state of" << relativePath << "from" << *pinState << "to inherited";
}
}
}
}
Expand Down Expand Up @@ -610,7 +612,7 @@
// an attribute change (pin state) that caused the notification
bool spurious = false;
if (record.isValid()
&& !FileSystem::fileChanged(path, record._fileSize, record._modtime)) {
&& !FileSystem::fileChanged(path, record._fileSize, record._modtime) && _vfs) {
spurious = true;

if (auto pinState = _vfs->pinState(relativePath.toString())) {
Expand Down Expand Up @@ -971,6 +973,8 @@
// Delete files that have been partially downloaded.
slotDiscardDownloadProgress();

disconnectFolderWatcher();

// Unregister the socket API so it does not keep the .sync_journal file open
FolderMan::instance()->socketApi()->slotUnregisterPath(alias());
_journal.close(); // close the sync journal
Expand Down Expand Up @@ -1588,6 +1592,21 @@
_folderWatcher->startNotificatonTest(path() + QLatin1String(".nextcloudsync.log"));
}

void Folder::disconnectFolderWatcher()

Check warning on line 1595 in src/gui/folder.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/folder.cpp:1595:14 [readability-convert-member-functions-to-static]

method 'disconnectFolderWatcher' can be made static
{
if (!_folderWatcher) {
return;
}
disconnect(_folderWatcher.data(), &FolderWatcher::pathChanged, nullptr, nullptr);
disconnect(_folderWatcher.data(), &FolderWatcher::lostChanges, this, &Folder::slotNextSyncFullLocalDiscovery);
disconnect(_folderWatcher.data(), &FolderWatcher::becameUnreliable, this, &Folder::slotWatcherUnreliable);
if (_accountState->account()->capabilities().filesLockAvailable()) {
disconnect(_folderWatcher.data(), &FolderWatcher::filesLockReleased, this, &Folder::slotFilesLockReleased);
disconnect(_folderWatcher.data(), &FolderWatcher::lockedFilesFound, this, &Folder::slotLockedFilesFound);
}
disconnect(_folderWatcher.data(), &FolderWatcher::filesLockImposed, this, &Folder::slotFilesLockImposed);
}

bool Folder::virtualFilesEnabled() const
{
return _definition.virtualFilesMode != Vfs::Off && !isVfsOnOffSwitchPending();
Expand Down
5 changes: 5 additions & 0 deletions src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ public slots:
private slots:
void slotSyncStarted();
void slotSyncFinished(bool);
/*
* Disconnects all the slots from the FolderWatcher
* Needs to be called each time a folder is removed
*/
void disconnectFolderWatcher();

/** Adds a error message that's not tied to a specific item.
*/
Expand Down
Loading