diff options
author | Oskar <[email protected]> | 2024-10-18 18:04:11 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-10-18 18:04:11 +0200 |
commit | e345d475790140ec2362dce3a1e4462358b174ea (patch) | |
tree | 61eba9eeba3dba6a99e942a4d9f787bf472761b3 | |
parent | 058fecf6ae7090c2f39cfcdf765697e39bf568b4 (diff) |
a bit of a mess right now but working on it
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | trashsystem2.cpp | 38 | ||||
-rw-r--r-- | trashsystem2.hpp | 28 |
3 files changed, 57 insertions, 13 deletions
@@ -1,5 +1,5 @@ -CC=g++ -CFLAGS_TESTBIN=-O0 -Wfatal-errors -Wall -Werror -Wextra -g3 -fsanitize=address -fsanitize=leak -Wpedantic -Wformat=2 -Wshadow -Wformat-truncation=2 -Wformat-overflow -fno-common -std=c++20 -DDEBUG_S +CC=clang++ +CFLAGS_TESTBIN=-O0 -Wfatal-errors -Wall -Werror -Wextra -g3 -fsanitize=address -fsanitize=leak -Wpedantic -Wformat=2 -Wshadow -fno-common -std=c++20 -DDEBUG_S CFLAGS=-O3 -flto -march=native -DNDEBUG -fomit-frame-pointer -s -static -std=c++20 TARGET=tsr TESTTARGET=tsr-TESTING diff --git a/trashsystem2.cpp b/trashsystem2.cpp index 7ceb816..c308f48 100644 --- a/trashsystem2.cpp +++ b/trashsystem2.cpp @@ -70,7 +70,28 @@ int choice (const int mode) { return FUNCTION_FAILURE; // Should never happen } -TS_FUNCTION_RESULT create_ts_dirs(initial_path_info &ipi) { +TS_FUNCTION_RESULT compare_unixtime (const time_t deleted_time, int const difference_in_days) { + + time_t diff_converted; + time_t current_time; + time_t final; + diff_converted = (time_t)difference_in_days * 86400; + current_time = time(NULL); + if(current_time == -1) { + return FUNCTION_FAILURE; + } + + final = current_time - deleted_time; + if(final < diff_converted) { + DEBUG_STREAM(<< "final is not older than diff_converted\n" << std::endl); + return FUNCTION_FAILURE; + } + + DEBUG_STREAM(<< "final is older than diff_converted\n" << std::endl); + return FUNCTION_SUCCESS; +} + +TS_FUNCTION_RESULT create_ts_dirs(const initial_path_info &ipi) { if(std::filesystem::exists(ipi.rget_ts())) { DEBUG_STREAM( << ipi.rget_ts() << " exists." << std::endl); @@ -105,6 +126,18 @@ TS_FUNCTION_RESULT create_ts_dirs(initial_path_info &ipi) { return FUNCTION_SUCCESS; } +TS_FUNCTION_RESULT get_file_info(const std::filesystem::path &path) { // function that gets all information about a file + + if(path.empty()) {} + return FUNCTION_SUCCESS; +} + +TS_FUNCTION_RESULT write_log_entry(const initial_path_info &ipi) { // function that writes logs + + if(ipi.is_fail()) {} + return FUNCTION_SUCCESS; +} + inline void usage_out(std::ostream &out) { out << USAGE << std::ends; @@ -142,7 +175,7 @@ int main (int argc, char **argv) { bool R_used = false; bool h_used = false; int opt = 0; - while((opt = getopt(argc, argv, "ynfatlLcCR:h")) != -1) { + while((opt = getopt(argc, argv, "ynftlLcCR:h")) != -1) { switch(opt) { case 'y': @@ -281,6 +314,7 @@ int main (int argc, char **argv) { int index = 0; for (index = optind ; index < argc ; index++) { // Actual loop that trashes files etc std::filesystem::path file_to_trash = argv[index]; + std::cout << file_to_trash << std::endl; } diff --git a/trashsystem2.hpp b/trashsystem2.hpp index 0fefbd9..ca41f8b 100644 --- a/trashsystem2.hpp +++ b/trashsystem2.hpp @@ -35,18 +35,28 @@ const TS_FUNCTION_RESULT FUNCTION_SUCCESS = 0; #include <string> #include <vector> #include <cstdlib> + +struct trashsys_log_info { + int64_t ts_log_id; + size_t ts_log_filesize; + time_t ts_log_trashtime; + std::filesystem::path ts_log_filename; + std::filesystem::path ts_log_originalpath; + bool ts_is_dir; +}; + class initial_path_info { // Initial useful strings to create before we do anything. Super useful when programming. public: initial_path_info(); - bool is_fail() { return ipi_fail; } - std::filesystem::path &rget_uh() { return ts_path_user_home; }; - std::filesystem::path &rget_uh_ws() { return ts_path_user_home_withslash; }; - std::filesystem::path &rget_ts() { return ts_path_trashsys; }; - std::filesystem::path &rget_ts_ws() { return ts_path_trashsys_withslash; }; - std::filesystem::path &rget_log() { return ts_path_log; }; - std::filesystem::path &rget_log_ws() { return ts_path_log_withslash; }; - std::filesystem::path &rget_trd() { return ts_path_trashed; }; - std::filesystem::path &rget_trd_ws() { return ts_path_trashed_withslash; }; + bool is_fail() const { return ipi_fail; } + const std::filesystem::path &rget_uh() const { return ts_path_user_home; }; + const std::filesystem::path &rget_uh_ws() const { return ts_path_user_home_withslash; }; + const std::filesystem::path &rget_ts() const { return ts_path_trashsys; }; + const std::filesystem::path &rget_ts_ws() const { return ts_path_trashsys_withslash; }; + const std::filesystem::path &rget_log() const { return ts_path_log; }; + const std::filesystem::path &rget_log_ws() const { return ts_path_log_withslash; }; + const std::filesystem::path &rget_trd() const { return ts_path_trashed; }; + const std::filesystem::path &rget_trd_ws() const { return ts_path_trashed_withslash; }; std::filesystem::path get_uh() { return ts_path_user_home; }; std::filesystem::path get_uh_ws() { return ts_path_user_home_withslash; }; std::filesystem::path get_ts() { return ts_path_trashsys; }; |