shared SandBoxedProcessor: Return SaveFileResult, remove defines

Not entirely ideal as SandboxedProcessor does not save anything,
but an improvement nevertheless over the current mess
This commit is contained in:
Albert S. 2022-06-24 17:10:43 +02:00
parent cf0c940b15
commit b6b3e2f3c0
5 changed files with 9 additions and 11 deletions

View File

@ -98,7 +98,7 @@ int main(int argc, char *argv[])
QString file = args.at(1); QString file = args.at(1);
SandboxedProcessor processor(file); SandboxedProcessor processor(file);
return processor.process(); return static_cast<int>(processor.process());
} }
Command *cmd = commandFromName(commandName, dbService); Command *cmd = commandFromName(commandName, dbService);
if(cmd != nullptr) if(cmd != nullptr)

View File

@ -114,7 +114,7 @@ int main(int argc, char *argv[])
QString file = args.at(2); QString file = args.at(2);
SandboxedProcessor processor(file); SandboxedProcessor processor(file);
return processor.process(); return static_cast<int>(processor.process());
} }
} }
QString ipcSocketPath = Common::ipcSocketPath(); QString ipcSocketPath = Common::ipcSocketPath();

View File

@ -10,9 +10,6 @@ enum DataSource
ARRAY ARRAY
}; };
#define NOTHING_PROCESSED 4
#define NO_ACCESS 5
class Processor class Processor
{ {
public: public:

View File

@ -80,7 +80,7 @@ void SandboxedProcessor::printResults(const QVector<PageData> &pageData)
fsstdout.close(); fsstdout.close();
} }
int SandboxedProcessor::process() SaveFileResult SandboxedProcessor::process()
{ {
QFileInfo fileInfo(this->filePath); QFileInfo fileInfo(this->filePath);
Processor *processor = processors.value(fileInfo.suffix(), nullptr); Processor *processor = processors.value(fileInfo.suffix(), nullptr);
@ -94,12 +94,12 @@ int SandboxedProcessor::process()
} }
if(!fileInfo.isReadable()) if(!fileInfo.isReadable())
{ {
return NO_ACCESS; return NOACCESS;
} }
if(processor == nullptr || processor == nothingProcessor) if(processor == nullptr || processor == nothingProcessor)
{ {
/* Nothing to do */ /* Nothing to do */
return NOTHING_PROCESSED; return OK;
} }
QVector<PageData> pageData; QVector<PageData> pageData;
@ -123,9 +123,9 @@ int SandboxedProcessor::process()
catch(LooqsGeneralException &e) catch(LooqsGeneralException &e)
{ {
Logger::error() << "SandboxedProcessor: Error while processing" << absPath << ":" << e.message << Qt::endl; Logger::error() << "SandboxedProcessor: Error while processing" << absPath << ":" << e.message << Qt::endl;
return 3 /* PROCESSFAIL */; return PROCESSFAIL;
} }
printResults(pageData); printResults(pageData);
return 0; return pageData.isEmpty() ? OK_WASEMPTY : OK;
} }

View File

@ -3,6 +3,7 @@
#include <QString> #include <QString>
#include <QMimeDatabase> #include <QMimeDatabase>
#include "pagedata.h" #include "pagedata.h"
#include "savefileresult.h"
class SandboxedProcessor class SandboxedProcessor
{ {
@ -19,7 +20,7 @@ class SandboxedProcessor
this->filePath = filepath; this->filePath = filepath;
} }
int process(); SaveFileResult process();
}; };
#endif // SANDBOXEDPROCESSOR_H #endif // SANDBOXEDPROCESSOR_H