19 #include "ninkawrapper.hpp" 27 return State(agentId);
32 char* COMMIT_HASH =
fo_sysconfig(AGENT_NAME,
"COMMIT_HASH");
36 if (!asprintf(&agentRevision,
"%s.%s", VERSION, COMMIT_HASH))
51 int agentId = state.getAgentId();
53 return fo_WriteARS(connection, arsId, uploadId, agentId, AGENT_ARS, NULL, success);
56 void bail(
int exitval)
64 vector<unsigned long> fileIds = databaseHandler.queryFileIdsForUpload(uploadId);
71 size_t pFileCount = fileIds.size();
73 for (
size_t it = 0; it < pFileCount; ++it)
78 unsigned long pFileId = fileIds[it];
101 cout <<
"File not found " << pFileId << endl;
105 char* fileName = NULL;
107 #pragma omp critical (repo_mk_path) 122 cout <<
"PFile not found in repo " << pFileId << endl;
131 string ninkaResult = scanFileWithNinka(state, file);
132 vector<string> ninkaLicenseNames = extractLicensesFromNinkaResult(ninkaResult);
133 vector<LicenseMatch> matches = createMatches(ninkaLicenseNames);
134 return saveLicenseMatchesToDatabase(state, matches, file.
getId(), databaseHandler);
137 bool saveLicenseMatchesToDatabase(
const State& state,
const vector<LicenseMatch>& matches,
unsigned long pFileId,
NinkaDatabaseHandler& databaseHandler)
139 for (vector<LicenseMatch>::const_iterator it = matches.begin(); it != matches.end(); ++it)
142 databaseHandler.insertOrCacheLicenseIdForName(match.getLicenseName());
145 if (!databaseHandler.
begin())
148 for (vector<LicenseMatch>::const_iterator it = matches.begin(); it != matches.end(); ++it)
152 int agentId = state.getAgentId();
153 string rfShortname = match.getLicenseName();
154 unsigned percent = match.getPercentage();
156 unsigned long licenseId = databaseHandler.getCachedLicenseIdForName(rfShortname);
161 cout <<
"cannot get licenseId for shortname '" + rfShortname +
"'" << endl;
166 if (!databaseHandler.saveLicenseMatch(agentId, pFileId, licenseId, percent))
169 cout <<
"failing save licenseMatch" << endl;
174 return databaseHandler.
commit();
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
Store the results of a regex match.
bool commit() const
COMMIT a transaction block in DB.
CopyrightState getState(CliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
bool rollback() const
ROLLBACK a transaction block in DB.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
char * getPFileNameForFileId(unsigned long pfileId) const
Get the file name of a give pfile id.
PGconn * getConnection() const
void matchFileWithLicenses(const string &sContent, unsigned long pFileId, CopyrightState const &state, int agentId, CopyrightDatabaseHandler &databaseHandler)
Scan a given file with all available scanners and save findings to database.
Class to handle file related operations.
bool processUploadId(const CopyrightState &state, int agentId, int uploadId, CopyrightDatabaseHandler &databaseHandler, bool ignoreFilesWithMimeType)
Process a given upload id, scan from statements and add to database.
bool begin() const
BEGIN a transaction block in DB.
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
unsigned long getId() const
fo_dbManager * dbManager
fo_dbManager object
int queryAgentId(PGconn *dbConn)
Get agent id, exit if agent id is incorrect.
FUNCTION int fo_GetAgentKey(PGconn *pgConn, const char *agent_name, long Upload_pk, const char *rev, const char *agent_desc)
Get the latest enabled agent key (agent_pk) from the database.
fo namespace holds the FOSSology library functions.
FUNCTION int fo_WriteARS(PGconn *pgConn, int ars_pk, int upload_pk, int agent_pk, const char *tableName, const char *ars_status, int ars_success)
Write ars record.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager)
Call C function fo_WriteARS() and translate the arguments.
void matchPFileWithLicenses(CopyrightState const &state, int agentId, unsigned long pFileId, CopyrightDatabaseHandler &databaseHandler)
Get the file contents, scan for statements and save findings to database.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.