From d8a951669c2d2c7abe477d14fe948fedba00fc28 Mon Sep 17 00:00:00 2001 From: fxdeniz <104620840+fxdeniz@users.noreply.github.com> Date: Sun, 26 Nov 2023 00:46:55 +0200 Subject: [PATCH] add `FileMonitoringManager::handleFileDeleteEvent()` --- .../FileMonitoringManager.cpp | 64 +++++++++++-------- .../FileMonitoringManager.h | 1 + .../FileSystemEventDb.cpp | 2 +- .../FileMonitorSubSystem/FileSystemEventDb.h | 2 +- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/Server/FileMonitorSubSystem/FileMonitoringManager.cpp b/Server/FileMonitorSubSystem/FileMonitoringManager.cpp index 0ff5b97..404489c 100644 --- a/Server/FileMonitorSubSystem/FileMonitoringManager.cpp +++ b/Server/FileMonitorSubSystem/FileMonitoringManager.cpp @@ -84,31 +84,8 @@ void FileMonitoringManager::slotOnDeleteEventDetected(const QString &fileOrFolde QString _dir = QDir::toNativeSeparators(dir); - if(!_dir.endsWith(QDir::separator())) - _dir.append(QDir::separator()); - handleFolderDeleteEvent(_dir, fileOrFolderName); - - QString currentPath = _dir + fileOrFolderName; - - if(eventDb->getNewAddedFileSet(_dir).contains(fileOrFolderName)) - eventDb->removeNewAddedFile(_dir, fileOrFolderName); - - auto fsm = FileStorageManager::instance(); - - if(!eventDb->resolveFileRenaming(_dir, fileOrFolderName).isEmpty()) - currentPath = eventDb->resolveFileRenaming(_dir, fileOrFolderName); - - QJsonObject fileJson = fsm->getFileJsonByUserPath(currentPath); - - bool isFilePersists = fileJson[JsonKeys::IsExist].toBool(); - bool isFileFrozen = fileJson[JsonKeys::File::IsFrozen].toBool(); - - if(isFilePersists && !isFileFrozen) - { - eventDb->setStatusOfMonitoredFile(_dir, fileJson[JsonKeys::File::FileName].toString(), FileSystemEventDb::ItemStatus::Deleted); - eventDb->removeFileRenamingEntru(_dir, fileOrFolderName); - } + handleFileDeleteEvent(_dir, fileOrFolderName); } void FileMonitoringManager::slotOnModificationEventDetected(const QString &fileName, const QString &dir) @@ -186,10 +163,12 @@ void FileMonitoringManager::handleFolderDeleteEvent(const QString &parentDirPath if(!_parentDirPath.endsWith(QDir::separator())) _parentDirPath.append(QDir::separator()); - QString currentPath = _parentDirPath + folderName; + QString _folderName = folderName; - if(!currentPath.endsWith(QDir::separator())) - currentPath.append(QDir::separator()); + if(!_folderName.endsWith(QDir::separator())) + _folderName.append(QDir::separator()); + + QString currentPath = _parentDirPath + _folderName; if(eventDb->getNewAddedFolderMap().contains(currentPath)) eventDb->removeNewAddedFolder(currentPath); @@ -207,7 +186,36 @@ void FileMonitoringManager::handleFolderDeleteEvent(const QString &parentDirPath if(isFolderPersists && !isFolderFrozen) { eventDb->setStatusOfMonitoredFolder(currentPath, FileSystemEventDb::ItemStatus::Deleted); - eventDb->removeFolderRenamingEntry(currentPath); + eventDb->removeFolderRenamingEntry(_parentDirPath + _folderName); + } +} + +void FileMonitoringManager::handleFileDeleteEvent(const QString &parentDirPath, const QString &fileName) +{ + QString _parentDirPath = parentDirPath; + + if(!_parentDirPath.endsWith(QDir::separator())) + _parentDirPath.append(QDir::separator()); + + QString currentPath = _parentDirPath + fileName; + + if(eventDb->getNewAddedFileSet(_parentDirPath).contains(fileName)) + eventDb->removeNewAddedFile(_parentDirPath, fileName); + + auto fsm = FileStorageManager::instance(); + + if(!eventDb->resolveFileRenaming(_parentDirPath, fileName).isEmpty()) + currentPath = eventDb->resolveFileRenaming(_parentDirPath, fileName); + + QJsonObject fileJson = fsm->getFileJsonByUserPath(currentPath); + + bool isFilePersists = fileJson[JsonKeys::IsExist].toBool(); + bool isFileFrozen = fileJson[JsonKeys::File::IsFrozen].toBool(); + + if(isFilePersists && !isFileFrozen) + { + eventDb->setStatusOfMonitoredFile(_parentDirPath, fileJson[JsonKeys::File::FileName].toString(), FileSystemEventDb::ItemStatus::Deleted); + eventDb->removeFileRenamingEntry(_parentDirPath, fileName); } } diff --git a/Server/FileMonitorSubSystem/FileMonitoringManager.h b/Server/FileMonitorSubSystem/FileMonitoringManager.h index 335b196..5414895 100644 --- a/Server/FileMonitorSubSystem/FileMonitoringManager.h +++ b/Server/FileMonitorSubSystem/FileMonitoringManager.h @@ -28,6 +28,7 @@ private slots: void handleFolderAddEvent(const QString &parentDirPath, const QString &folderName); void handleFileAddEvent(const QString &parentDirPath, const QString &fileName); void handleFolderDeleteEvent(const QString &parentDirPath, const QString &folderName); + void handleFileDeleteEvent(const QString &parentDirPath, const QString &fileName); void handleFolderMoveEvent(const QString &parentDirPath, const QString &oldFolderName, const QString &newFolderName); void handleFileMoveEvent(const QString &parentDirPath, const QString &oldFileName, const QString &newFileName); void handleFileModificationEvent(const QString &parentDirPath, const QString &fileName); diff --git a/Server/FileMonitorSubSystem/FileSystemEventDb.cpp b/Server/FileMonitorSubSystem/FileSystemEventDb.cpp index a22f06a..9ee484f 100644 --- a/Server/FileMonitorSubSystem/FileSystemEventDb.cpp +++ b/Server/FileMonitorSubSystem/FileSystemEventDb.cpp @@ -224,7 +224,7 @@ QString FileSystemEventDb::resolveFileRenaming(const QString &userFolderPath, co return result; } -void FileSystemEventDb::removeFileRenamingEntru(const QString &userFolderPath, const QString &newFileName) +void FileSystemEventDb::removeFileRenamingEntry(const QString &userFolderPath, const QString &newFileName) { QWriteLocker writeLocker(lock); diff --git a/Server/FileMonitorSubSystem/FileSystemEventDb.h b/Server/FileMonitorSubSystem/FileSystemEventDb.h index c87dd84..d7134a0 100644 --- a/Server/FileMonitorSubSystem/FileSystemEventDb.h +++ b/Server/FileMonitorSubSystem/FileSystemEventDb.h @@ -42,7 +42,7 @@ class FileSystemEventDb void addFileRenamingEntry(const QString &userFolderPath, const QString &oldFileName, const QString &newFileName); QString resolveFileRenaming(const QString &userFolderPath, const QString &fileName) const; - void removeFileRenamingEntru(const QString &userFolderPath, const QString &newFileName); + void removeFileRenamingEntry(const QString &userFolderPath, const QString &newFileName); void addNewAddedFolder(const QString &userFolderPath, efsw::WatchID watchID); void removeNewAddedFolder(const QString &userFolderPath);