diff --git a/shared/common.cpp b/shared/common.cpp index ff33d63..f929ef0 100644 --- a/shared/common.cpp +++ b/shared/common.cpp @@ -17,6 +17,7 @@ #define SETTINGS_KEY_FIRSTRUN "firstrun" #define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath" #define SETTINGS_KEY_PDFVIEWER "pdfviewer" +#define SETTINGS_KEY_EXCLUDEDPATHS "excludedpaths" inline void initResources() { @@ -162,3 +163,18 @@ QString Common::ipcSocketPath() // QSettings settings; // return settings.value(SETTINGS_KEY_IPCSOCKETPATH, "/tmp/.looqs/looqs-ipc-socket").toString(); } + +static QStringList excludedPaths = {"/proc", "/sys", "/dev", "/tmp", "/var/run", "/run"}; + +QStringList Common::excludedPaths() +{ + static int ran = false; + if(!ran) + { + QSettings settings; + QStringList userExcludedPaths = settings.value(SETTINGS_KEY_EXCLUDEDPATHS).toStringList(); + ran = true; + ::excludedPaths.append(userExcludedPaths); + } + return ::excludedPaths; +} diff --git a/shared/common.h b/shared/common.h index 4e0e888..ab0457a 100644 --- a/shared/common.h +++ b/shared/common.h @@ -11,5 +11,6 @@ void setPdfViewer(); QString findInPath(QString needle); bool initSqliteDatabase(QString path); void ensureConfigured(); +QStringList excludedPaths(); } // namespace Common #endif diff --git a/shared/filesaver.cpp b/shared/filesaver.cpp index 7362358..6f8043f 100644 --- a/shared/filesaver.cpp +++ b/shared/filesaver.cpp @@ -23,6 +23,7 @@ SaveFileResult FileSaver::addFile(QString path) { QFileInfo info(path); QString absPath = info.absoluteFilePath(); + auto mtime = info.lastModified().toSecsSinceEpoch(); if(this->dbService->fileExistsInDatabase(absPath, mtime)) { @@ -95,7 +96,7 @@ int FileSaver::processFiles(const QVector paths, std::function pageData; - QString absPath = fileInfo.absoluteFilePath(); + QString canonicalPath = fileInfo.canonicalFilePath(); int status = -1; @@ -106,9 +107,17 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo) if(fileInfo.isFile()) { + for(QString &excludedPath : this->excludedPaths) + { + if(canonicalPath.startsWith(excludedPath)) + { + return SKIPPED; + } + } + QProcess process; QStringList args; - args << "process" << absPath; + args << "process" << canonicalPath; process.setProcessChannelMode(QProcess::ForwardedErrorChannel); process.start("/proc/self/exe", args); process.waitForStarted(); @@ -132,7 +141,7 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo) status = process.exitCode(); if(status != 0 && status != NOTHING_PROCESSED) { - Logger::error() << "FileSaver::saveFile(): Error while processing" << absPath << ":" + Logger::error() << "FileSaver::saveFile(): Error while processing" << canonicalPath << ":" << "Exit code " << status << Qt::endl; return PROCESSFAIL; @@ -142,7 +151,7 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo) // Could happen if a file corrupted for example if(pageData.isEmpty() && status != NOTHING_PROCESSED) { - Logger::error() << "Could not get any content for " << absPath << Qt::endl; + Logger::error() << "Could not get any content for " << canonicalPath << Qt::endl; } return this->dbService->saveFile(fileInfo, pageData); diff --git a/shared/filesaver.h b/shared/filesaver.h index fb5b82a..c6199f2 100644 --- a/shared/filesaver.h +++ b/shared/filesaver.h @@ -5,11 +5,12 @@ #include "pagedata.h" #include "filedata.h" #include "sqlitedbservice.h" - +#include "common.h" class FileSaver { private: SqliteDbService *dbService; + QStringList excludedPaths = Common::excludedPaths(); public: FileSaver(SqliteDbService &dbService);