summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--trashsystem2.cpp64
-rw-r--r--trashsystem2.hpp29
2 files changed, 86 insertions, 7 deletions
diff --git a/trashsystem2.cpp b/trashsystem2.cpp
index c308f48..1a2f79d 100644
--- a/trashsystem2.cpp
+++ b/trashsystem2.cpp
@@ -2,6 +2,7 @@
#include "trashsystem2.hpp"
#include <unistd.h>
#include <cstdio>
+#include <cstdlib>
/*
*
@@ -126,12 +127,62 @@ TS_FUNCTION_RESULT create_ts_dirs(const 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
+std::vector<directory_entry> get_files_in_directory(const std::filesystem::path path) {
- if(path.empty()) {}
- return FUNCTION_SUCCESS;
+ std::vector<directory_entry> v_directory_entry;
+ for(auto &dir_entry : std::filesystem::directory_iterator{path}) {
+ bool isother = false;
+ if(!dir_entry.is_directory() && !dir_entry.is_regular_file()) {
+ DEBUG_STREAM( << "determine_new_id: " << dir_entry.path() << " is other." << std::endl);
+ isother = true;
+ }
+
+ directory_entry current(dir_entry.path(), dir_entry.is_directory(), dir_entry.is_regular_file(), isother);
+ v_directory_entry.push_back(current);
+ }
+
+ return v_directory_entry;
+}
+
+int64_t determine_highest_id(const initial_path_info &ipi) {
+
+ int64_t highest_id = 0;
+ auto dirs = get_files_in_directory(ipi.rget_log());
+ for(auto &a : dirs) {
+ std::string path_str = a.rget_path().filename();
+ const char *path_cstr = path_str.c_str();
+ char *endptr = nullptr;
+ auto strtoll_result = std::strtoll(path_cstr, &endptr, 10);
+ if(path_cstr == endptr) {
+ DEBUG_STREAM( << "determine_highest_id: path_cstr == endptr" << std::endl);
+ continue;
+ }
+
+ if(*endptr != ':') {
+ DEBUG_STREAM( << "':' not found for file: " << path_cstr << std::endl);
+ continue;
+ }
+
+ if(strtoll_result > highest_id) {
+ highest_id = strtoll_result;
+ DEBUG_STREAM( << "ID: " << strtoll_result << ", is higher than highest_id." << std::endl);
+ }
+ }
+
+ return highest_id;
}
+/*
+TS_FUNCTION_RESULT get_file_info(const std::filesystem::path &path,
+ std::vector<trashsys_log_info> &vtli,
+ const initial_path_info &ipi) {
+
+
+ trashsys_log_info tli(1,1,1,"/","/",1);
+ vtli.push_back(tli);
+ return FUNCTION_SUCCESS;
+}
+*/
TS_FUNCTION_RESULT write_log_entry(const initial_path_info &ipi) { // function that writes logs
if(ipi.is_fail()) {}
@@ -312,11 +363,12 @@ int main (int argc, char **argv) {
}
int index = 0;
+ std::vector<trashsys_log_info> vtli;
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;
+ //get_file_info(file_to_trash, vtli);
}
-
+
+ determine_highest_id(ipi);
return 0;
}
diff --git a/trashsystem2.hpp b/trashsystem2.hpp
index ca41f8b..6647ec6 100644
--- a/trashsystem2.hpp
+++ b/trashsystem2.hpp
@@ -36,7 +36,34 @@ const TS_FUNCTION_RESULT FUNCTION_SUCCESS = 0;
#include <vector>
#include <cstdlib>
-struct trashsys_log_info {
+class directory_entry {
+public:
+ directory_entry(std::filesystem::path dep, bool isd, bool isr, bool iso):
+ de_path(dep), is_dir(isd), is_reg(isr), is_other(iso) {}
+ const bool &ris_reg() const { return is_reg; }
+ const bool &ris_dir() const { return is_dir; }
+ const bool &ris_other() const { return is_other; }
+ const std::filesystem::path &rget_path() const { return de_path; }
+private:
+ std::filesystem::path de_path;
+ bool is_dir = false;
+ bool is_reg = false;
+ bool is_other = false;
+};
+
+class trashsys_log_info {
+public:
+ trashsys_log_info(int64_t log_id, size_t log_filesize, time_t log_trashtime,
+ std::filesystem::path log_filename, std::filesystem::path log_originalpath, bool is_dir):
+ ts_log_id(log_id), ts_log_filesize(log_filesize), ts_log_trashtime(log_trashtime),
+ ts_log_filename(log_filename), ts_log_originalpath(log_originalpath), ts_is_dir(is_dir) { }
+ const int64_t &rget_logid() const { return ts_log_id; }
+ const size_t &rget_logfsz() const { return ts_log_filesize; }
+ const time_t &rget_logtt() const { return ts_log_trashtime; }
+ const std::filesystem::path &rget_logfn() const { return ts_log_filename; }
+ const std::filesystem::path &rget_logop() const { return ts_log_originalpath; }
+ const bool &rget_isdir() const { return ts_is_dir; }
+private:
int64_t ts_log_id;
size_t ts_log_filesize;
time_t ts_log_trashtime;