52 char BuildVersion[]=
"delagent build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
69 void usage (
char *Name)
71 fprintf(stderr,
"Usage: %s [options]\n",Name);
72 fprintf(stderr,
" List or delete uploads.\n");
73 fprintf(stderr,
" Options\n");
74 fprintf(stderr,
" -i :: Initialize the DB, then exit.\n");
75 fprintf(stderr,
" -u :: List uploads IDs.\n");
76 fprintf(stderr,
" -U # :: Delete upload ID.\n");
77 fprintf(stderr,
" -f :: List folder IDs.\n");
78 fprintf(stderr,
" -F # :: Delete folder ID and all uploads under this folder.\n");
79 fprintf(stderr,
" Folder '1' is the default folder. '-F 1' will delete\n");
80 fprintf(stderr,
" every upload and folder in the navigation tree.\n");
81 fprintf(stderr,
" use -P to indicate parent of the copied folder.\n");
82 fprintf(stderr,
" -s :: Run from the scheduler.\n");
83 fprintf(stderr,
" -T :: TEST -- do not update the DB or delete any files (just pretend)\n");
84 fprintf(stderr,
" -v :: Verbose (-vv for more verbose)\n");
85 fprintf(stderr,
" -c # :: Specify the directory for the system configuration\n");
86 fprintf(stderr,
" -V :: print the version info, then exit.\n");
87 fprintf(stderr,
" --user|-n # :: user name\n");
88 fprintf(stderr,
" --password|-p # :: password\n");
100 if (0 == returnedCode)
102 fprintf(stdout,
"The %s '%ld' is deleted by the user '%s'.\n", kind,
id, userName);
106 fprintf(stdout,
"Deletion failed: user '%s' does not have the permsssion to delete the %s '%ld', or the %s '%ld' does not exist.\n", userName, kind,
id, kind,
id);
151 int main (
int argc,
char *argv[])
154 int listProj=0, listFolder=0;
155 long delUpload=0, delFolder=0, delFolderParent=0;
158 char *agentDesc =
"Deletes upload. Other list/delete options available from the command line.";
161 char agentRev[myBUFSIZ];
163 char *userName = NULL;
164 char *password = NULL;
167 int returnedCode = 0;
171 static struct option long_options[] =
173 {
"user", required_argument, 0,
'n'},
174 {
"password", required_argument, 0,
'p'},
178 while ((c = getopt_long (argc, argv,
"n:p:ifF:lL:sTuU:P:vVc:h",
179 long_options, &optionIndex)) != -1)
197 delFolder=atol(optarg);
201 delFolderParent=atol(optarg);
216 delUpload=atol(optarg);
245 LOG_FATAL(
"User name or password is invalid.\n");
251 sprintf(agentRev,
"%s.%s", version, commitHash);
259 if (returnedCode < 0)
267 if (returnedCode < 0)
275 returnedCode =
deleteUpload(delUpload, userId, userPerm);
281 returnedCode =
deleteFolder(delFolder, delFolderParent, userId, userPerm);
293 return(returnedCode);
PGconn * pgConn
Database connection.
void doSchedulerTasks()
process the jobs from scheduler
int authentication(char *user, char *password, int *userId, int *userPerm)
if this account is valid
void exitNow(int exitVal)
Exit function. This does all cleanup and should be used instead of calling exit() or main() return.
int Verbose
Verbose level.
int listUploads(int userId, int userPerm)
List every upload ID.
int listFolders(int userId, int userPerm)
List every folder.
int deleteUpload(long uploadId, int userId, int userPerm)
Given an upload ID, delete it.
int deleteFolder(long cFolder, long pFolder, int userId, int userPerm)
recursively delete a folder
int main(int argc, char *argv[])
main function for the delagent
void writeMessageAfterDelete(char *kind, long id, char *userName, int returnedCode)
Write message to user after success/failure.
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_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
FUNCTION void usage(char *name)