From 61a446ec2d8e4cba384c235a64a38ed678d9e9f9 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 5 Jun 2022 20:53:37 +0200 Subject: [PATCH] shared: common: Add mountPaths() Mountpaths indicate mount points of external devices. Files located under such paths should not be removed on sync, because they may have not been deleted, but are just inaccessible right now. --- shared/common.cpp | 27 +++++++++++++++++++++++++++ shared/common.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/shared/common.cpp b/shared/common.cpp index a956997..3a7836e 100644 --- a/shared/common.cpp +++ b/shared/common.cpp @@ -19,6 +19,7 @@ #define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath" #define SETTINGS_KEY_PDFVIEWER "pdfviewer" #define SETTINGS_KEY_EXCLUDEDPATHS "excludedpaths" +#define SETTINGS_KEY_MOUNTPATHS "mountpaths" inline void initResources() { @@ -180,6 +181,32 @@ QStringList Common::excludedPaths() return ::excludedPaths; } +QStringList Common::mountPaths() +{ + static int ran = false; + static QStringList mountPaths; + if(!ran) + { + QSettings settings; + mountPaths = settings.value(SETTINGS_KEY_MOUNTPATHS, QStringList{"/media", "/mnt"}).toStringList(); + ran = true; + } + return mountPaths; +} + +bool Common::isMountPath(QString path) +{ + QStringList mountPaths = Common::mountPaths(); + for(QString &mountPath : mountPaths) + { + if(path.startsWith(mountPath)) + { + return true; + } + } + return false; +} + bool Common::isTextFile(QFileInfo fileInfo) { /* TODO: This is not sandboxed yet ... */ diff --git a/shared/common.h b/shared/common.h index 5980650..0971e79 100644 --- a/shared/common.h +++ b/shared/common.h @@ -12,7 +12,9 @@ QString findInPath(QString needle); bool initSqliteDatabase(QString path); void ensureConfigured(); QStringList excludedPaths(); +QStringList mountPaths(); bool isTextFile(QFileInfo fileInfo); +bool isMountPath(QString path); QString versionText(); } // namespace Common #endif