FileSaver: Don't add files in blacklisted paths
We now resolve symlinks when adding, so we can properly check whether a path is excluded or not. This accidently also helps with duplicates. Excluded paths are hardcoded and can also be appended to by the user using the settings. Closes: #34
This commit is contained in:
parent
483ea04638
commit
06ac77d0ef
@ -17,6 +17,7 @@
|
|||||||
#define SETTINGS_KEY_FIRSTRUN "firstrun"
|
#define SETTINGS_KEY_FIRSTRUN "firstrun"
|
||||||
#define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath"
|
#define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath"
|
||||||
#define SETTINGS_KEY_PDFVIEWER "pdfviewer"
|
#define SETTINGS_KEY_PDFVIEWER "pdfviewer"
|
||||||
|
#define SETTINGS_KEY_EXCLUDEDPATHS "excludedpaths"
|
||||||
|
|
||||||
inline void initResources()
|
inline void initResources()
|
||||||
{
|
{
|
||||||
@ -162,3 +163,18 @@ QString Common::ipcSocketPath()
|
|||||||
// QSettings settings;
|
// QSettings settings;
|
||||||
// return settings.value(SETTINGS_KEY_IPCSOCKETPATH, "/tmp/.looqs/looqs-ipc-socket").toString();
|
// 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;
|
||||||
|
}
|
||||||
|
@ -11,5 +11,6 @@ void setPdfViewer();
|
|||||||
QString findInPath(QString needle);
|
QString findInPath(QString needle);
|
||||||
bool initSqliteDatabase(QString path);
|
bool initSqliteDatabase(QString path);
|
||||||
void ensureConfigured();
|
void ensureConfigured();
|
||||||
|
QStringList excludedPaths();
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,6 +23,7 @@ SaveFileResult FileSaver::addFile(QString path)
|
|||||||
{
|
{
|
||||||
QFileInfo info(path);
|
QFileInfo info(path);
|
||||||
QString absPath = info.absoluteFilePath();
|
QString absPath = info.absoluteFilePath();
|
||||||
|
|
||||||
auto mtime = info.lastModified().toSecsSinceEpoch();
|
auto mtime = info.lastModified().toSecsSinceEpoch();
|
||||||
if(this->dbService->fileExistsInDatabase(absPath, mtime))
|
if(this->dbService->fileExistsInDatabase(absPath, mtime))
|
||||||
{
|
{
|
||||||
@ -95,7 +96,7 @@ int FileSaver::processFiles(const QVector<QString> paths, std::function<SaveFile
|
|||||||
SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
||||||
{
|
{
|
||||||
QVector<PageData> pageData;
|
QVector<PageData> pageData;
|
||||||
QString absPath = fileInfo.absoluteFilePath();
|
QString canonicalPath = fileInfo.canonicalFilePath();
|
||||||
|
|
||||||
int status = -1;
|
int status = -1;
|
||||||
|
|
||||||
@ -106,9 +107,17 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
|||||||
|
|
||||||
if(fileInfo.isFile())
|
if(fileInfo.isFile())
|
||||||
{
|
{
|
||||||
|
for(QString &excludedPath : this->excludedPaths)
|
||||||
|
{
|
||||||
|
if(canonicalPath.startsWith(excludedPath))
|
||||||
|
{
|
||||||
|
return SKIPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << "process" << absPath;
|
args << "process" << canonicalPath;
|
||||||
process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
||||||
process.start("/proc/self/exe", args);
|
process.start("/proc/self/exe", args);
|
||||||
process.waitForStarted();
|
process.waitForStarted();
|
||||||
@ -132,7 +141,7 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
|||||||
status = process.exitCode();
|
status = process.exitCode();
|
||||||
if(status != 0 && status != NOTHING_PROCESSED)
|
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;
|
<< "Exit code " << status << Qt::endl;
|
||||||
|
|
||||||
return PROCESSFAIL;
|
return PROCESSFAIL;
|
||||||
@ -142,7 +151,7 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
|||||||
// Could happen if a file corrupted for example
|
// Could happen if a file corrupted for example
|
||||||
if(pageData.isEmpty() && status != NOTHING_PROCESSED)
|
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);
|
return this->dbService->saveFile(fileInfo, pageData);
|
||||||
|
@ -5,11 +5,12 @@
|
|||||||
#include "pagedata.h"
|
#include "pagedata.h"
|
||||||
#include "filedata.h"
|
#include "filedata.h"
|
||||||
#include "sqlitedbservice.h"
|
#include "sqlitedbservice.h"
|
||||||
|
#include "common.h"
|
||||||
class FileSaver
|
class FileSaver
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SqliteDbService *dbService;
|
SqliteDbService *dbService;
|
||||||
|
QStringList excludedPaths = Common::excludedPaths();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileSaver(SqliteDbService &dbService);
|
FileSaver(SqliteDbService &dbService);
|
||||||
|
Loading…
Reference in New Issue
Block a user