diff options
author | Oskar <[email protected]> | 2024-07-04 17:22:47 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-07-04 17:22:47 +0200 |
commit | 4dde5db2ddf83f62c6146f9898feef4df4ad95b3 (patch) | |
tree | 441590d2e12532ed16b09d905f9284c9eb3f9cf4 | |
parent | 08a6c63ec2a418ab9ff1c0ba93628fad0c5e37d1 (diff) |
basic version of L and l is done, will move on to another branch for other functionality
-rw-r--r-- | TODO | 8 | ||||
-rwxr-xr-x | test/gentestfiles.sh | 2 | ||||
-rw-r--r-- | trashsys.c | 23 |
3 files changed, 22 insertions, 11 deletions
@@ -1,7 +1,7 @@ -1. Implement -l and -L. Maybe redo the function. -2. Just a note: When implementing the -L -l functions we need to make it clear what's in tmp and whats not. Not sure exactly how ill do this but i have some ideas. One way of dealing with files in tmp is to force the user to pass the -t argument if they want to deal with tmp stuff. Like if i say: 'tsr -t -l' it will only list files in the tmp trashcan. Maybe that IS the best approach to this? -3. Implement function to read log files? And maybe act upon the read contents? I'll have to think more about this. -4. Handle case where we pass a bunch of options but no filename +1. Divide fill_lfc and -L -l function +2. Handle case where we pass a bunch of options but no filename +3. +4. 5. Clean up some code, remove redundancy and make everything a little smarter where i can 6. ?. For now we are just warning the user to set the env variable HOME to your home dir but maybe we want to handle this even if its not set?
\ No newline at end of file diff --git a/test/gentestfiles.sh b/test/gentestfiles.sh index 18f0b6e..da113d8 100755 --- a/test/gentestfiles.sh +++ b/test/gentestfiles.sh @@ -3,3 +3,5 @@ touch ts_file1.txt touch ts_file2.txt touch ts_file3.txt +touch thisfile.txt +dd if=/dev/zero of=./1gb.img bs=100M count=10 @@ -23,6 +23,7 @@ #define FUNCTION_FAILURE -1 #define FUNCTION_SUCCESS 0 #define REM_SZ(remsz, final) (remsz - strlen(final)) +#define USAGE_OUT(stream) (fprintf(stream, "%s", USAGE)) bool v_cvm_fprintf = false; int choice_mode = MODE_NORMAL; @@ -495,7 +496,7 @@ int write_log_file(struct dynamic_paths *dp, struct trashsys_log_info *tli, cons fprintf(stdout, "%s", tmp_path); } - fprintf(stdout, "logfile path: %s\n", dp->new_logfile_path_incl_name); + cvm_fprintf(v_cvm_fprintf, stdout, "logfile path: %s\n", dp->new_logfile_path_incl_name); FILE *file = fopen(dp->new_logfile_path_incl_name, "w"); if(file == NULL) { printf("%s\n", strerror(errno)); @@ -714,7 +715,7 @@ int choice(const int mode) { int main (int argc, char *argv[]) { if (argc == 1) { - fprintf(stderr, "%s: please specify a filename\n%s\n", argv[0], USAGE); + USAGE_OUT(stderr); return EXIT_FAILURE; } @@ -733,7 +734,7 @@ int main (int argc, char *argv[]) { int opt; //int returnval; //char *optarg_copy = NULL; // We will copy optarg to this - while ((opt = getopt(argc, argv, "ynvfatlLcCR:")) != -1) { + while ((opt = getopt(argc, argv, "ynvfatlLcCR:h")) != -1) { switch (opt) { case 'y': @@ -790,6 +791,10 @@ int main (int argc, char *argv[]) { R_used = true; break; + case 'h': + USAGE_OUT(stdout); + return EXIT_SUCCESS; + break; } } @@ -801,19 +806,23 @@ int main (int argc, char *argv[]) { struct initial_path_info ipi_m; // _m because i just want to keep in mind that we're in main which is a bit easier for me int cctd; if(fill_ipi(t_used, &ipi_m) == FUNCTION_FAILURE) { + fprintf(stderr, "fill_ipi error, exiting...\n"); return EXIT_FAILURE; } cctd = check_create_ts_dirs(&ipi_m); // check for or create directories if(cctd == FUNCTION_FAILURE) { - fprintf(stderr, "check_create_ts_dirs(): Cannot create directories\n"); + fprintf(stderr, "check_create_ts_dirs() error: Cannot create directories\n"); return EXIT_FAILURE; } if(l_used == true && L_used == true) { - fill_lfc(&ipi_m, L_used); + if(fill_lfc(&ipi_m, L_used) == FUNCTION_FAILURE) { return EXIT_FAILURE; } + return EXIT_SUCCESS; + } else if (l_used == true) { + if(fill_lfc(&ipi_m, L_used) == FUNCTION_FAILURE) { return EXIT_FAILURE; } return EXIT_SUCCESS; - } else { - fill_lfc(&ipi_m, false); + } else if (L_used == true) { + if(fill_lfc(&ipi_m, L_used) == FUNCTION_FAILURE) { return EXIT_FAILURE; } return EXIT_SUCCESS; } |