summaryrefslogtreecommitdiff
path: root/trashsystem2.cpp
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-10-23 22:59:25 +0200
committerOskar <[email protected]>2024-10-23 22:59:25 +0200
commit9b49201b8f9aa16d1f13eda4d715d10c1f3d178f (patch)
tree5d59af132a67f79dcc75f0be644f2091f991c2bb /trashsystem2.cpp
parent70e1270b211aa33f2131ee254b05dfca0eb4721a (diff)
put_files_in_trash
Diffstat (limited to 'trashsystem2.cpp')
-rw-r--r--trashsystem2.cpp23
1 files changed, 17 insertions, 6 deletions
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;