Skip to content

Commit

Permalink
Ensure fzz lock directory exists
Browse files Browse the repository at this point in the history
Two improvements:
1. Create log directories before cleanup check
2. Log a debug message and skip cleanup if the directory does not exist
(on Linux usually ~/.config/Fritzing/fzz )
Prior behavior: If the lock directory did not exists (e.g. first start)
unrelated files in the  folder  ~/.config/Fritzing) might be deleted.
Normally this does not cause issues, but if Fritzing is untypically
installed to ~/.config/Fritzing or the folder is used otherwise, this
can cause damage. For example, fritzing would delete its own core parts
folder.
  • Loading branch information
KjellMorgenstern committed Feb 21, 2021
1 parent 2161372 commit 8a1e068
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/fapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,10 +1163,10 @@ int FApplication::startup()
.arg("%1") );
#endif

cleanFzzs();

createUserDataStoreFolderStructures();

cleanFzzs();

ProcessEventBlocker::processEvents();

loadReferenceModel("", false);
Expand Down
12 changes: 10 additions & 2 deletions src/utils/lockmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
#include "lockmanager.h"
#include "folderutils.h"
#include "textutils.h"
#include "../debugdialog.h"

#include <QTimer>
#include <QPointer>
Expand Down Expand Up @@ -127,7 +128,11 @@ void LockManager::releaseLockedFiles(const QString & folder, QHash<QString, Lock
void LockManager::releaseLockedFiles(const QString & folder, QHash<QString, LockedFile *> & lockedFiles, bool remove)
{
QDir backupDir(folder);
backupDir.cdUp();
if (! backupDir.cdUp()) {
DebugDialog::debug(QString("Error, lock directory not found: %1").arg(backupDir.dirName()));
return;
}

foreach (QString sub, lockedFiles.keys()) {
LockedFile * lockedFile = lockedFiles.value(sub);
TheMutex.lock();
Expand All @@ -144,7 +149,10 @@ void LockManager::releaseLockedFiles(const QString & folder, QHash<QString, Lock
void LockManager::checkLockedFiles(const QString & prefix, QFileInfoList & backupList, QHash<QString, LockedFile *> & lockedFiles, bool recurse, long touchFrequency)
{
QDir backupDir(FolderUtils::getTopLevelUserDataStorePath());
backupDir.cd(prefix);
if (! backupDir.cd(prefix)) {
DebugDialog::debug(QString("Error, lock directory not found: %1 %2").arg(backupDir.absolutePath(), prefix));
return;
}
QFileInfoList dirList = backupDir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::NoSymLinks);
foreach (QFileInfo dirInfo, dirList) {
QDir dir(dirInfo.filePath());
Expand Down

0 comments on commit 8a1e068

Please sign in to comment.