Skip to content

Commit

Permalink
Merge pull request #136 from fxdeniz/issue_135
Browse files Browse the repository at this point in the history
Issue 135
  • Loading branch information
fxdeniz authored Mar 23, 2023
2 parents d36f719 + 8fad003 commit ef0f8c2
Show file tree
Hide file tree
Showing 133 changed files with 3,147 additions and 11,044 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "Dependency/efsw"]
path = Dependency/efsw
url = https://github.com/SpartanJ/efsw
[submodule "Dependency/quazip"]
path = Dependency/quazip
url = https://github.com/stachenov/quazip.git
8 changes: 8 additions & 0 deletions Backend/FileMonitorSubSystem/FileMonitoringManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ void FileMonitoringManager::slotOnMoveEventDetected(const QString &fileName, con

database->setNameOfFile(currentOldPath, fileName);

emit signalEventDbUpdated();
}
else if(isOldFileMonitored && isNewFileMonitored) // Delete temp file (Issue #81).
{
bool isFilePersists = fsm->getFileJsonByUserPath(currentNewPath)[JsonKeys::IsExist].toBool();
if(isFilePersists)
database->deleteFile(currentOldPath);

emit signalEventDbUpdated();
}
}
Expand Down
113 changes: 70 additions & 43 deletions Backend/FileMonitorSubSystem/FileSystemEventDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,64 +64,49 @@ bool FileSystemEventDb::isFileExist(const QString &pathToFile) const

bool FileSystemEventDb::addFolder(const QString &pathToFolder)
{
// Workaround for #133
database.close();
database.open();
//
QString nativePath = QDir::toNativeSeparators(pathToFolder);

bool result = false;
if(nativePath.endsWith(QDir::separator()))
nativePath.chop(1);

if(database.transaction())
QString queryTemplate = "INSERT INTO Folder(folder_path, parent_folder_path, event_timestamp) VALUES(:1, :2, :3);" ;
QStringList folderNames = nativePath.split(QDir::separator());
QString parentFolderPath = "";

for(const QString &folder : folderNames)
{
QString nativePath = QDir::toNativeSeparators(pathToFolder);
// Start constructing from root path
QString currentSubFolderPath = folder + QDir::separator();
QString currentFolderPath = parentFolderPath + currentSubFolderPath;

if(nativePath.endsWith(QDir::separator()))
nativePath.chop(1);
bool isInsertingRootPath = currentFolderPath == QDir::toNativeSeparators(QDir::rootPath());

QString queryTemplate = "INSERT INTO Folder(folder_path, parent_folder_path, event_timestamp) VALUES(:1, :2, :3);" ;
QStringList folderNames = nativePath.split(QDir::separator());
QString parentFolderPath = "";
bool isAlreadyInDb = isFolderExist(currentFolderPath);

for(const QString &folder : folderNames)
if(!isAlreadyInDb) // If root path not in db
{
// Start constructing from root path
QString currentSubFolderPath = folder + QDir::separator();
QString currentFolderPath = parentFolderPath + currentSubFolderPath;

bool isInsertingRootPath = currentFolderPath == QDir::separator();

bool isAlreadyInDb = isFolderExist(currentFolderPath);
QSqlQuery query(database);
query.prepare(queryTemplate);

if(!isAlreadyInDb) // If root path not in db
{
QSqlQuery query(database);
query.prepare(queryTemplate);
query.bindValue(":1", currentFolderPath);
query.bindValue(":3", QDateTime::currentDateTime());

query.bindValue(":1", currentFolderPath);
query.bindValue(":3", QDateTime::currentDateTime());
if(isInsertingRootPath)
query.bindValue(":2", QVariant()); // Bind null value.
else
query.bindValue(":2", parentFolderPath);

if(isInsertingRootPath)
query.bindValue(":2", QVariant()); // Bind null value.
else
query.bindValue(":2", parentFolderPath);
query.exec();

query.exec();

if(query.lastError().type() != QSqlError::ErrorType::NoError)
{
database.rollback();
return false;
}
}

// Set last inserted path as root path
parentFolderPath += currentSubFolderPath;
if(query.lastError().type() != QSqlError::ErrorType::NoError)
return false;
}

result = database.commit();
// Set last inserted path as root path
parentFolderPath += currentSubFolderPath;
}

return result;
return true;
}

bool FileSystemEventDb::addFile(const QString &pathToFile)
Expand Down Expand Up @@ -692,6 +677,48 @@ QStringList FileSystemEventDb::getEventfulFileListOfFolder(const QString &pathTo
return result;
}

bool FileSystemEventDb::isContainAnyFolderEvent() const
{
bool result = false;

QString columnName = "result_column";
QString queryTemplate = "SELECT COUNT(*) AS %1 FROM Folder WHERE status != :1;" ;
queryTemplate = queryTemplate.arg(columnName);

QSqlQuery query(database);
query.prepare(queryTemplate);
query.bindValue(":1", ItemStatus::Monitored);
query.exec();
query.next();

int count = query.record().value(columnName).toInt();
if(count >= 1)
result = true;

return result;
}

bool FileSystemEventDb::isContainAnyFileEvent() const
{
bool result = false;

QString columnName = "result_column";
QString queryTemplate = "SELECT COUNT(*) AS %1 FROM File WHERE status != :1;" ;
queryTemplate = queryTemplate.arg(columnName);

QSqlQuery query(database);
query.prepare(queryTemplate);
query.bindValue(":1", ItemStatus::Monitored);
query.exec();
query.next();

int count = query.record().value(columnName).toInt();
if(count >= 1)
result = true;

return result;
}

bool FileSystemEventDb::addMonitoringError(const QString &location, const QString &during, qlonglong error)
{
bool result = false;
Expand Down
2 changes: 2 additions & 0 deletions Backend/FileMonitorSubSystem/FileSystemEventDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class FileSystemEventDb
QStringList getDirectChildFolderListOfFolder(const QString pathToFolder) const;
QStringList getDirectChildFileListOfFolder(const QString &pathToFolder) const;
QStringList getEventfulFileListOfFolder(const QString &pathToFolder) const;
bool isContainAnyFolderEvent() const;
bool isContainAnyFileEvent() const;
bool addMonitoringError(const QString &location, const QString &during, qlonglong error);

private:
Expand Down
3 changes: 1 addition & 2 deletions Backend/FileMonitorSubSystem/FileSystemEventListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define FILESYSTEMEVENTLISTENER

#include <QObject>

#include "Backend/FileMonitorSubSystem/efsw/efsw.hpp"
#include <efsw/efsw.hpp>

class FileSystemEventListener : public QObject, public efsw::FileWatchListener
{
Expand Down
55 changes: 0 additions & 55 deletions Backend/FileMonitorSubSystem/efsw/Atomic.hpp

This file was deleted.

85 changes: 0 additions & 85 deletions Backend/FileMonitorSubSystem/efsw/Debug.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions Backend/FileMonitorSubSystem/efsw/Debug.hpp

This file was deleted.

Loading

0 comments on commit ef0f8c2

Please sign in to comment.