Skip to content

Commit

Permalink
add FileMonitoringManager::handleFileDeleteEvent()
Browse files Browse the repository at this point in the history
  • Loading branch information
fxdeniz committed Nov 25, 2023
1 parent f303f6f commit d8a9516
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
64 changes: 36 additions & 28 deletions Server/FileMonitorSubSystem/FileMonitoringManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions Server/FileMonitorSubSystem/FileMonitoringManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Server/FileMonitorSubSystem/FileSystemEventDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Server/FileMonitorSubSystem/FileSystemEventDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d8a9516

Please sign in to comment.