From 9b49201b8f9aa16d1f13eda4d715d10c1f3d178f Mon Sep 17 00:00:00 2001 From: Oskar Date: Wed, 23 Oct 2024 22:59:25 +0200 Subject: put_files_in_trash --- trashsystem2.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'trashsystem2.cpp') 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 &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; -- cgit v1.2.3