diff options
author | Oskar <[email protected]> | 2024-06-27 17:05:22 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-06-27 17:05:22 +0200 |
commit | 99a1c79f37afd378955b6fe1cf1e8fe9bc3b138f (patch) | |
tree | 703320bc248795c245793bdee63428c106edaa0a | |
parent | baa775cdd7f936573bdeaa6c10757495ac48c172 (diff) |
find_highest_id is done, tested it some and added some debug cvm_fprintf's. I think it works? Testing will probably prove me wrong but ill deal with it when it happens.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | trashsys.c | 21 |
3 files changed, 22 insertions, 7 deletions
@@ -1,5 +1,5 @@ CC=gcc -CFLAGS_TESTBIN=-O3 -Wfatal-errors -Wall -Werror -Wextra -g -fsanitize=address -Wpedantic -std=gnu99 +CFLAGS_TESTBIN=-O0 -Wfatal-errors -Wall -Werror -Wextra -g -fsanitize=address -Wpedantic -std=gnu99 CFLAGS=-O3 -flto -march=native -DNDEBUG -fomit-frame-pointer -s -static -std=gnu99 TARGET=tsr TESTTARGET=tsr-TESTING @@ -1,5 +1,5 @@ -1. Finish find highest ID +1. Start implementing some commandline arguments. I will probably start with -v (verbose) and -y/-n. 2. Clean up some code, remove redundancy and make everything a little smarter where i can. -3. Change fill_ipi function again because i found a slightly better way to do things -4. Start implementing some commandline arguments. I will probably start with -v (verbose) and -y/-n. +3. +4. ?. 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 @@ -219,6 +219,19 @@ uint64_t find_highest_id (struct initial_path_info *ipi) { // Find highest id an if(S_ISREG(d_or_f.st_mode)) { // check if given file is actually a file fprintf(stdout, "%s\n", ddd->d_name); + char *endptr; + uint64_t strtoull_ID = strtoull(ddd->d_name, &endptr, 10); + if(ddd->d_name == endptr) { + cvm_fprintf(v_cvm_fprintf, stdout, "d_name == endptr | d_name: %p | endptr: %p | d_name string: %s\n", ddd->d_name, endptr, ddd->d_name); + continue; + } + if(*endptr != ':') { + cvm_fprintf(v_cvm_fprintf, stdout, "':' not found for file: %s\n", ddd->d_name); + continue; + } + if(strtoull_ID > id) { // If id is bigger then update it + id = strtoull_ID; + } } } @@ -226,10 +239,11 @@ uint64_t find_highest_id (struct initial_path_info *ipi) { // Find highest id an return id; } -int tli_fill_info (struct trashsys_log_info *tli, char* filename, bool log_tmp, struct initial_path_info *ipi) { +int tli_fill_info (struct trashsys_log_info *tli, char* filename, bool log_tmp, struct initial_path_info *ipi) { + // This function will be the main function that gathers and fills out info that will be in the log file for a file a user wants to trash /* struct trashsys_log_info { - uint64_t ts_log_id; // Find a new suitable ID for this new file + uint64_t ts_log_id; X char ts_log_filename[FILENAME_MAX]; X size_t ts_log_filesize; X time_t ts_log_trashtime; X @@ -261,7 +275,8 @@ struct trashsys_log_info { fclose(file); tli->ts_log_filesize = (size_t)filesize; - tli->ts_log_id = find_highest_id(ipi); + uint64_t ID = find_highest_id(ipi); + tli->ts_log_id = ID + 1; // +1 because if we are making a new file we need to give it one above highest ID. return 0; } |