8 #include "ninkawrapper.hpp"
16 return State(agentId);
21 char* COMMIT_HASH =
fo_sysconfig(AGENT_NAME,
"COMMIT_HASH");
25 if (!asprintf(&agentRevision,
"%s.%s", VERSION, COMMIT_HASH))
39 PGconn* connection =
dbManager.getConnection();
42 return fo_WriteARS(connection, arsId, uploadId, agentId, AGENT_ARS, NULL, success);
45 void bail(
int exitval)
53 vector<unsigned long> fileIds = databaseHandler.queryFileIdsForUpload(uploadId);
60 size_t pFileCount = fileIds.size();
62 for (
size_t it = 0; it < pFileCount; ++it)
67 unsigned long pFileId = fileIds[it];
90 cout <<
"File not found " << pFileId << endl;
94 char* fileName = NULL;
96 #pragma omp critical (repo_mk_path)
111 cout <<
"PFile not found in repo " << pFileId << endl;
120 string ninkaResult = scanFileWithNinka(state, file);
121 vector<string> ninkaLicenseNames = extractLicensesFromNinkaResult(ninkaResult);
122 vector<LicenseMatch> matches = createMatches(ninkaLicenseNames);
123 return saveLicenseMatchesToDatabase(state, matches, file.
getId(), databaseHandler);
126 bool saveLicenseMatchesToDatabase(
const State& state,
const vector<LicenseMatch>& matches,
unsigned long pFileId,
NinkaDatabaseHandler& databaseHandler)
128 for (vector<LicenseMatch>::const_iterator it = matches.begin(); it != matches.end(); ++it)
131 databaseHandler.insertOrCacheLicenseIdForName(
match.getLicenseName());
134 if (!databaseHandler.
begin())
137 for (vector<LicenseMatch>::const_iterator it = matches.begin(); it != matches.end(); ++it)
142 string rfShortname =
match.getLicenseName();
143 unsigned percent =
match.getPercentage();
145 unsigned long licenseId = databaseHandler.getCachedLicenseIdForName(rfShortname);
150 cout <<
"cannot get licenseId for shortname '" + rfShortname +
"'" << endl;
155 if (!databaseHandler.saveLicenseMatch(agentId, pFileId, licenseId, percent))
158 cout <<
"failing save licenseMatch" << endl;
163 return databaseHandler.
commit();
bool processUploadId(const CompatibilityState &state, int uploadId, CompatibilityDatabaseHandler &databaseHandler, int groupId)
CompatibilityState getState(DbManager &dbManager, CompatibilityCliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
int writeARS(const CompatibilityState &state, int arsId, int uploadId, int success, DbManager &dbManager)
int queryAgentId(DbManager &dbManager)
int getAgentId() const
getter function for agent Id
bool commit() const
COMMIT a transaction block in DB.
bool begin() const
BEGIN a transaction block in DB.
char * getPFileNameForFileId(unsigned long pfileId) const
Get the file name of a give pfile id.
bool rollback() const
ROLLBACK a transaction block in DB.
Class to handle file related operations.
unsigned long getId() const
void matchPFileWithLicenses(CopyrightState const &state, int agentId, unsigned long pFileId, CopyrightDatabaseHandler &databaseHandler)
Get the file contents, scan for statements and save findings to database.
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.
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.
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.
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
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...
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
fo_dbManager * dbManager
fo_dbManager object
fo namespace holds the FOSSology library functions.
Store the results of a regex match.