Skip to content

Commit 1676498

Browse files
committed
refactor(delagent): rewrite DeleteUpload and more
- rewritten /refactored functions: - `DeleteUpload` - `DeleteLicense` - `UnlinkContent` - and more - rewrite naming of `TempTable` - remove all unnecessary `memset` calls - make return codes more consistend - remove dead code - die on permission failure - this change was made to show delagent jobs, which have had permission problems, as failed agents (i.e. red).
1 parent f9e5c1c commit 1676498

File tree

7 files changed

+318
-580
lines changed

7 files changed

+318
-580
lines changed

src/delagent/agent/delagent.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
delagent: Remove an upload from the DB and repository
33
44
Copyright (C) 2007-2013 Hewlett-Packard Development Company, L.P.
5+
Copyright (C) 2015-2016 Siemens AG
56
67
This program is free software; you can redistribute it and/or
78
modify it under the terms of the GNU General Public License
@@ -68,37 +69,41 @@ void writeMessageAfterDelete(char *kind, long id, char *user_name, int returnedC
6869
{
6970
fprintf(stdout, "The %s '%ld' is deleted by the user '%s'.\n", kind, id, user_name);
7071
}
72+
else if (2 == returnedCode)
73+
{
74+
fprintf(stdout, "The %s '%ld' could not be found by the user '%s'.\n", kind, id, user_name);
75+
}
7176
else
7277
{
73-
LOG_FATAL("You '%s' does not have the permsssion to delete the %s '%ld', or the %s '%ld' does not exist.\n", user_name, kind, id, kind, id);
74-
exit(returnedCode);
78+
fprintf(stdout, "Deletion failed: user '%s' does not have the permsssion to delete the %s '%ld', or the %s '%ld' does not exist.\n", user_name, kind, id, kind, id);
79+
exit(-1);
7580
}
7681
}
7782

7883
/**
7984
* \brief main function for the delagent
8085
*
8186
* There are 2 ways to use the delagent agent:
82-
* 1. Command Line :: delete/list upload from the command line
87+
* 1. Command Line :: delete/list upload/folder/license from the command line
8388
* 2. Agent Based :: run from the scheduler
8489
*
8590
* +-----------------------+
8691
* | Command Line Analysis |
8792
* +-----------------------+
8893
*
8994
* List or delete uploads.
90-
* -h :: help (print this message), then exit.
91-
* -i :: Initialize the DB
92-
* -u :: List uploads IDs.
93-
* -U # :: Delete upload ID.
94-
* -L # :: Delete ALL licenses associated with upload ID.
95-
* -f :: List folder IDs.
96-
* -F # :: Delete folder ID and all uploads under this folder.
97-
* -T :: TEST -- do not update the DB or delete any files (just pretend).
98-
* -v :: Verbose (-vv for more verbose).
99-
* -V :: print the version info, then exit.
95+
* -h :: help (print this message), then exit.
96+
* -i :: Initialize the DB
97+
* -u :: List uploads IDs.
98+
* -U # :: Delete upload ID.
99+
* -L # :: Delete ALL licenses associated with upload ID.
100+
* -f :: List folder IDs.
101+
* -F # :: Delete folder ID and all uploads under this folder.
102+
* -T :: TEST -- do not update the DB or delete any files (just pretend).
103+
* -v :: Verbose (-vv for more verbose).
104+
* -V :: print the version info, then exit.
100105
* -c SYSCONFDIR :: Specify the directory for the system configuration.
101-
* --user # :: user name
106+
* --user # :: user name
102107
* --password # :: password
103108
*
104109
* +----------------------+

src/delagent/agent/delagent.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/********************************************************
22
Copyright (C) 2007-2012 Hewlett-Packard Development Company, L.P.
3+
Copyright (C) 2015-2016 Siemens AG
34
45
This program is free software; you can redistribute it and/or
56
modify it under the terms of the GNU General Public License
@@ -46,7 +47,9 @@ extern PGconn* db_conn;
4647
/* authentication and permission checking */
4748
int authentication(char *user, char * password, int *user_id, int *user_perm);
4849

49-
int check_permission_upload(long upload_id, int user_id, int user_perm);
50+
int check_permission_upload(int wantedPermissions, long upload_id, int user_id, int user_perm);
51+
int check_read_permission_upload(long upload_id, int user_id, int user_perm);
52+
int check_write_permission_upload(long upload_id, int user_id, int user_perm);
5053
int check_permission_folder(long folder_id, int user_id, int user_perm);
5154
int check_permission_license(long license_id, int user_perm);
5255

0 commit comments

Comments
 (0)