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:
2022-05-29 15:46:06 +02:00
parent 483ea04638
commit b6926d510f
4 changed files with 32 additions and 7 deletions

View File

@ -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<QString> paths, std::function<SaveFile
SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
{
QVector<PageData> 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);