63 char BuildVersion[]=
"delagent build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
80 void usage (
char *Name)
82 fprintf(stderr,
"Usage: %s [options]\n",Name);
83 fprintf(stderr,
" List or delete uploads.\n");
84 fprintf(stderr,
" Options\n");
85 fprintf(stderr,
" -i :: Initialize the DB, then exit.\n");
86 fprintf(stderr,
" -u :: List uploads IDs.\n");
87 fprintf(stderr,
" -U # :: Delete upload ID.\n");
88 fprintf(stderr,
" -f :: List folder IDs.\n");
89 fprintf(stderr,
" -F # :: Delete folder ID and all uploads under this folder.\n");
90 fprintf(stderr,
" Folder '1' is the default folder. '-F 1' will delete\n");
91 fprintf(stderr,
" every upload and folder in the navigation tree.\n");
92 fprintf(stderr,
" use -P to indicate parent of the copied folder.\n");
93 fprintf(stderr,
" -s :: Run from the scheduler.\n");
94 fprintf(stderr,
" -T :: TEST -- do not update the DB or delete any files (just pretend)\n");
95 fprintf(stderr,
" -v :: Verbose (-vv for more verbose)\n");
96 fprintf(stderr,
" -c # :: Specify the directory for the system configuration\n");
97 fprintf(stderr,
" -V :: print the version info, then exit.\n");
98 fprintf(stderr,
" --user|-n # :: user name\n");
99 fprintf(stderr,
" --password|-p # :: password\n");
111 if (0 == returnedCode)
113 fprintf(stdout,
"The %s '%ld' is deleted by the user '%s'.\n", kind,
id, userName);
117 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);
162 int main (
int argc,
char *argv[])
165 int listProj=0, listFolder=0;
166 long delUpload=0, delFolder=0, delFolderParent=0;
169 char *agentDesc =
"Deletes upload. Other list/delete options available from the command line.";
172 char agentRev[myBUFSIZ];
174 char *userName = NULL;
175 char *password = NULL;
178 int returnedCode = 0;
182 static struct option long_options[] =
184 {
"user", required_argument, 0,
'n'},
185 {
"password", required_argument, 0,
'p'},
189 while ((c = getopt_long (argc, argv,
"n:p:ifF:lL:sTuU:P:vVc:h",
190 long_options, &optionIndex)) != -1)
208 delFolder=atol(optarg);
212 delFolderParent=atol(optarg);
227 delUpload=atol(optarg);
256 LOG_FATAL(
"User name or password is invalid.\n");
262 sprintf(agentRev,
"%s.%s", version, commitHash);
270 if (returnedCode < 0)
278 if (returnedCode < 0)
286 returnedCode =
deleteUpload(delUpload, userId, userPerm);
292 returnedCode =
deleteFolder(delFolder, delFolderParent, userId, userPerm);
304 return(returnedCode);
int deleteFolder(long cFolder, long pFolder, int userId, int userPerm)
recursively delete a folder
PGconn * pgConn
Database connection.
void doSchedulerTasks()
process the jobs from scheduler
int Verbose
Verbose level.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
void writeMessageAfterDelete(char *kind, long id, char *userName, int returnedCode)
Write message to user after success/failure.
int deleteUpload(long uploadId, int userId, int userPerm)
Given an upload ID, delete it.
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.
FUNCTION void usage(char *name)
int main(int argc, char *argv[])
main function for the delagent
int listFolders(int userId, int userPerm)
List every folder.
void exitNow(int exitVal)
Exit function. This does all cleanup and should be used instead of calling exit() or main() return...
int authentication(char *user, char *password, int *userId, int *userPerm)
if this account is valid
int listUploads(int userId, int userPerm)
List every upload ID.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.