diff options
author | Oskar <[email protected]> | 2024-10-23 22:59:25 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-10-23 22:59:25 +0200 |
commit | 9b49201b8f9aa16d1f13eda4d715d10c1f3d178f (patch) | |
tree | 5d59af132a67f79dcc75f0be644f2091f991c2bb | |
parent | 70e1270b211aa33f2131ee254b05dfca0eb4721a (diff) |
put_files_in_trash
-rwxr-xr-x | test/test_deletefiles.sh | 4 | ||||
-rwxr-xr-x | test/test_deletefiles_tmp.sh | 6 | ||||
-rwxr-xr-x | test/test_generate_delete_tmp.sh | 7 | ||||
-rw-r--r-- | trashsystem2.cpp | 23 |
4 files changed, 19 insertions, 21 deletions
diff --git a/test/test_deletefiles.sh b/test/test_deletefiles.sh index 9cf917d..fa92e44 100755 --- a/test/test_deletefiles.sh +++ b/test/test_deletefiles.sh @@ -1,6 +1,6 @@ #!/bin/sh files="1000b.img 1000mb.img 1023b.img 1023kib.img 1024b.img 1024kib.img 1.1gib.img 1gib.img 1KB.img 1KiB.img 1mb.img 1mib.img 500kib.img thisfile.txt ts_file1.txt ts_file2.txt ts_file3.txt" -options="-v" -./tsr-TESTING $options $files + +./tsr-TESTING $files diff --git a/test/test_deletefiles_tmp.sh b/test/test_deletefiles_tmp.sh deleted file mode 100755 index deb070f..0000000 --- a/test/test_deletefiles_tmp.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -files="1000b.img 1000mb.img 1023b.img 1023kib.img 1024b.img 1024kib.img 1.1gib.img 1gib.img 1KB.img 1KiB.img 1mb.img 1mib.img 500kib.img thisfile.txt ts_file1.txt ts_file2.txt ts_file3.txt" -options="-v -t" - -./tsr-TESTING $options $files diff --git a/test/test_generate_delete_tmp.sh b/test/test_generate_delete_tmp.sh deleted file mode 100755 index 0eed94c..0000000 --- a/test/test_generate_delete_tmp.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -for i in {1..10} -do - ./gentestfiles.sh - ./test_deletefiles_tmp.sh -done diff --git a/trashsystem2.cpp b/trashsystem2.cpp index f23ae09..3c3fdba 100644 --- a/trashsystem2.cpp +++ b/trashsystem2.cpp @@ -243,6 +243,10 @@ TS_FUNCTION_RESULT write_log_entry(const initial_path_info &ipi, const trashsys_ std::string id_and_filename = std::to_string(tli.rget_logid())+":"+filename; std::string id_and_filename_log = id_and_filename+".log"; std::ofstream log_out(std::string(ipi.rget_log_ws())+id_and_filename_log); + if(!log_out) { + return FUNCTION_FAILURE; + } + log_out << tli.rget_logid() << " " << std::string(tli.rget_logfn()) << " " << id_and_filename << " " @@ -387,6 +391,14 @@ TS_FUNCTION_RESULT long_list_trashed(const std::vector<trashsys_log_info> &vtli) return FUNCTION_SUCCESS; } +TS_FUNCTION_RESULT put_in_trash(const initial_path_info &ipi, const trashsys_log_info &tli) { + + std::string id_and_filename = std::to_string(tli.rget_logid())+":"+std::string(tli.rget_logfn()); + std::string prepend_path = std::string(ipi.rget_trd_ws())+id_and_filename; + std::filesystem::rename(tli.rget_logop(), prepend_path); + return FUNCTION_SUCCESS; +} + inline void usage_out(std::ostream &out) { out << USAGE << std::ends; @@ -578,12 +590,11 @@ int main (int argc, char **argv) { continue; } - write_log_entry(ipi, tli); - DEBUG_STREAM( << tli.rget_logid() << std::endl); - DEBUG_STREAM( << tli.rget_logfsz() << std::endl); - DEBUG_STREAM( << tli.rget_logtt() << std::endl); - DEBUG_STREAM( << tli.rget_logfn() << std::endl); - DEBUG_STREAM( << tli.rget_logop() << std::endl); + if(write_log_entry(ipi, tli)) { + return EXIT_FAILURE; + } + + put_in_trash(ipi, tli); } return 0; |