29 LOG_VERBOSE(
"ProcessFile: %s",FilePath);
32 fin = fopen(FilePath,
"r");
35 LOG_ERROR(
"FATAL: %s.%s.%d Failure to open file %s.\nError: %s\n",
36 __FILE__,
"ProcessFile()", __LINE__, FilePath, strerror(errno));
41 rv = fread(FileResult->
Buf,
sizeof(
char),
sizeof(FileResult->
Buf), fin);
74 char *RepoArea =
"files";
76 char *ufile_mode =
"10000000";
80 char* SelectFilename_sql =
"\
81 SELECT pfile_pk, pfile_sha1 || '.' || pfile_md5 || '.' || pfile_size AS pfilename \
82 FROM ( SELECT distinct(pfile_fk) AS PF FROM uploadtree \
83 WHERE upload_fk = %d and (ufile_mode&x'%s'::int)=0 \
85 left outer join demomod on (PF = pfile_fk ) \
86 inner join pfile on (PF = pfile_pk) \
87 WHERE demomod_pk IS null or agent_fk <> %d";
88 char* SelectFilename2_sql =
"\
89 SELECT pfile_pk, pfile_sha1 || '.' || pfile_md5 || '.' || pfile_size AS pfilename \
90 FROM ( SELECT distinct(pfile_fk) AS PF FROM %s \
91 WHERE (ufile_mode&x'%s'::int)=0 \
93 left outer join demomod on (PF = pfile_fk ) \
94 inner join pfile on (PF = pfile_pk) \
95 WHERE demomod_pk IS null or agent_fk <> %d";
101 LOG_FATAL(
"demomod passed invalid upload, upload_pk = %d",
upload_pk);
109 if (LastChar >=
'0' && LastChar <=
'9')
111 snprintf(sqlbuf,
sizeof(sqlbuf), SelectFilename2_sql,
uploadtree_tablename, ufile_mode, agent_fk);
115 snprintf(sqlbuf,
sizeof(sqlbuf), SelectFilename_sql,
upload_pk, ufile_mode, agent_fk);
120 result = PQexec(
pgConn, sqlbuf);
122 numrows = PQntuples(result);
125 for (i=0; i<numrows; i++)
127 strcpy(FileName, PQgetvalue(result, i, 1));
128 pfile_pk = atoi(PQgetvalue(result, i, 0));
132 LOG_FATAL(
"demomod was unable to derive a file path for pfile %d. Check your HOSTS configuration.", pfile_pk);
142 snprintf(DataBuf,
sizeof(DataBuf),
"%d\t%d\t%s\n", pfile_pk, agent_fk, FileResult.
HexStr);
char * uploadtree_tablename
upload.uploadtree_tablename
FUNCTION int ProcessUpload(int upload_pk, int agent_fk)
Process a single upload - read the first 32 bytes in each file.
PGconn * pgConn
Database connection.
FUNCTION int ProcessFile(char *FilePath, pFileResult_t FileResult)
Process a single file - read the first 32 bytes.
psqlCopy_t psqlcpy
fo_sqlCopy struct used for fast data insertion
FUNCTION void Char2Hex(char *InBuf, int NumBytes, char *OutBuf)
Convert a character buffer to a hex string.
FUNCTION void ExitNow(int ExitVal)
Exit function. This does all cleanup and should be used instead of calling exit() or main() return.
FUNCTION char * GetUploadtreeTableName(PGconn *pgConn, int upload_pk)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree".
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
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 fo_sqlCopyAdd(psqlCopy_t pCopy, char *DataRow)
Add a data row to an sqlCopy Use '\N' to pass in a null.
char HexStr[(DataSize *2)+1]
Hexadecimal string.
char Buf[DataSize]
Buffer.