12 #include "maintagent.h"
26 if (exitVal) LOG_ERROR(
"Exiting with status %d", exitVal);
42 while ((*p = toupper(*p)))
67 FUNCTION
void recurseDir(
const char* type,
char* path,
int level)
74 LOG_ERROR(
"Unable to open dir: '%s'", path);
75 LOG_ERROR(
"Error: %s", strerror(errno));
78 while ((entry = readdir(dir)) != NULL)
80 if (strcmp(entry->d_name,
".") != 0 && strcmp(entry->d_name,
"..") != 0)
82 char nextpath[myBUFSIZ];
86 strncpy(nextpath, path, myBUFSIZ - 1);
87 strncat(nextpath,
"/", myBUFSIZ - 1);
88 strncat(nextpath, entry->d_name, myBUFSIZ - 1);
101 memset(sha1,
'\0', 41);
102 memset(md5,
'\0', 33);
103 strncpy(nextpath, entry->d_name, myBUFSIZ - 1);
104 ptr = strtok(nextpath, delim);
107 LOG_FATAL(
"Unable to split path '%s' for pfile.", nextpath);
110 strncpy(sha1, ptr, 40);
111 ptr = strtok(NULL, delim);
112 strncpy(md5, ptr, 32);
113 ptr = strtok(NULL, delim);
138 "SELECT pfile_pk FROM pfile "
139 "WHERE pfile_md5 = $1 AND pfile_sha1 = $2 AND pfile_size = $3) "
140 "SELECT 1 AS exists FROM uploadtree INNER JOIN pf "
141 "ON pf.pfile_pk = pfile_fk "
143 "SELECT 1 AS exists FROM upload INNER JOIN pf "
144 "ON pf.pfile_pk = pfile_fk;";
146 existsStatement = fo_dbManager_PrepareStamement(
dbManager,
"checkPfileExists",
147 sql,
char*,
char*,
long);
155 countTuples = PQntuples(result);
180 char filename[myBUFSIZ];
183 snprintf(filename, myBUFSIZ,
"%s.%s.%ld", sha1, md5, fsize);
185 unlink(goldFilePath);
PGconn * pgConn
Database connection.
int s
The socket that the CLI will use to communicate.
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_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...
fo_dbManager * dbManager
fo_dbManager object
FUNCTION char * strtoupper(char *s)
Helper function to upper case a string.
FUNCTION void exitNow(int exitVal)
Exit function. This does all cleanup and should be used instead of calling exit() or main() return.
FUNCTION void checkPFileExists(char *sha1, char *md5, long fsize, const char *type)
Check if given checksums exists in DB, if not call deleteRepoFile()
FUNCTION void deleteRepoFile(char *sha1, char *md5, long fsize, const char *type)
Take a file checksum, generate repo path and call unlink()
FUNCTION void recurseDir(const char *type, char *path, int level)
Recursively read directory till level is 0.
PGresult * fo_dbManager_ExecPrepared(fo_dbManager_PreparedStatement *preparedStatement,...)
Execute a prepared statement.
void fo_dbManager_free(fo_dbManager *dbManager)
Un-allocate the memory from a DB manager.