From 9cb882cdb61c9613bc73d8e6042959fb18765c9a Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 14 Oct 2024 11:27:58 +0200 Subject: first commit, not much done yet. source file and header file. Same scripts used as version 1 trash system. Will probably make better test scripts eventually. --- .gitignore | 6 +++ LICENSE | 21 +++++++++ Makefile | 22 +++++++++ README | 6 +++ trashsystem2.cpp | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ trashsystem2.hpp | 31 +++++++++++++ 6 files changed, 225 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100644 trashsystem2.cpp create mode 100644 trashsystem2.hpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20883c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +tsr +tsr-TESTING +test/ +TODO +rockyou.txt +testdir/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f66c023 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 734j + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..52e9f35 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +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 +CFLAGS=-O3 -flto -march=native -DNDEBUG -fomit-frame-pointer -s -static -std=c++20 +TARGET=tsr +TESTTARGET=tsr-TESTING +INSTALL_DIRECTORY=/usr/local/bin +MAKEFLAGS += +SRCS=trashsystem2.cpp + +all: release +clean: + rm -f $(TARGET) + rm -f test/$(TESTTARGET) + +tests: + $(CC) $(CFLAGS_TESTBIN) $(SRCS) -o test/$(TESTTARGET) + +install: + cp $(TARGET) $(INSTALL_DIRECTORY) + +release: + $(CC) $(CFLAGS) $(SRCS) -o $(TARGET) diff --git a/README b/README new file mode 100644 index 0000000..d2f2453 --- /dev/null +++ b/README @@ -0,0 +1,6 @@ +Trashing system. + +Main core functionality is done. Use at your own risk! + +Feel free to create bug reports. +Feel free to discuss improvements to code structure. diff --git a/trashsystem2.cpp b/trashsystem2.cpp new file mode 100644 index 0000000..123ce9e --- /dev/null +++ b/trashsystem2.cpp @@ -0,0 +1,139 @@ +#include +#include "trashsystem2.hpp" +#include + +/* + * + * Trashing System (Version 2) + * + * A hopefully improved take on the previous trash + * system that i made in C. By reimplementing this + * in C++ i hope to avoid the bugs and code smell + * that eventually cropped up in the last project. + * + * While i am optimistic at this point my pessimism + * will probably prove me wrong because i will most + * likely encounter other problems that will give + * my code that nice funky smell. + * + */ + +char *g_argv = nullptr; + +inline void usage_out(std::ostream &out) { + + out << USAGE; +} + +inline void usage_out_long(std::ostream &out) { + + out << LONG_USAGE; +} + +int main (int argc, char **argv) { + + g_argv = argv[0]; + if (argc == 1) { + usage_out(std::cerr); + return EXIT_FAILURE; + } + + int R_mut = 0; + int C_mut = 0; + int c_mut = 0; + int L_mut = 0; + int l_mut = 0; + int y_mut = 0; + int n_mut = 0; + int f_mut = 0; + int h_mut = 0; + bool y_used = false; + bool n_used = false; + bool v_used = false; + bool f_used = false; + bool t_used = false; + bool l_used = false; + bool L_used = false; + bool c_used = false; + bool C_used = false; + bool R_used = false; + bool h_used = false; + int opt; + unsigned long long optarg_converted; + bool R_failed = false; + while ((opt = getopt(argc, argv, "ynvfatlLcCR:h")) != -1) { + switch (opt) { + case 'y': + + y_mut = 1; + y_used = true; // YES on enter + + break; + case 'n': + + n_mut = 1; + n_used = true; // NO on enter + + break; + case 'v': + + v_used = true; // Verbose debug mode + + break; + case 'f': + + f_mut = 1; + f_used = true; // choice will not ask, it will just say yes by default thus basically "forcing" it + + break; + case 't': + + t_used = true; + + break; + case 'l': + + l_mut = 1; + l_used = true; + + break; + case 'L': + + L_mut = 1; + L_used = true; + + break; + case 'c': + + c_mut = 1; + c_used = true; + + break; + case 'C': + + C_mut = 1; + C_used = true; + + break; + case 'R': { + + R_mut = 1; + R_used = true; + + } + break; + case 'h': + + h_mut = 1; + h_used = true; + + break; + } + } + + std::cout << "Smoketest" << std::endl; + std::cout << argc << std::endl; + std::cout << argv[0] << std::endl; + std::cout << BUF_SIZE_1MIB << std::endl; + return 0; +} diff --git a/trashsystem2.hpp b/trashsystem2.hpp new file mode 100644 index 0000000..2dba99f --- /dev/null +++ b/trashsystem2.hpp @@ -0,0 +1,31 @@ +#define BUF_SIZE_2 2048 +#define BUF_SIZE_4 4096 +#define BUF_SIZE_1MIB 1048576 +#define USAGE std::string(g_argv) + " [-vt] [-y][-n][-f][-l][-L][-c][-C][-h][-R id] [FILE(s)]\n" +#define LONG_USAGE std::string(g_argv) + " [options] filename(s)\n" \ + "\n"\ + "OPTIONS:\n"\ + " -t /tmp mode. tsr will use /tmp instead of the user's $HOME.\n"\ + " -y Answer 'yes' when pressing return on all [Y / N] prompts.\n"\ + " -n Answer 'no' when pressing return on all [Y / N] prompts.\n"\ + " -f Force answer 'yes' on all [Y / N] prompts. Prompt will not show.\n"\ + " -l List all trashed files.\n"\ + " -L List all trashed files with more details.\n"\ + " -c Clear all trashed files that are older than the configured time limit.\n"\ + " -C Clear all trashed files regardless of age. Will prompt with a [Y / N] prompt.\n"\ + " -h Display this help message.\n"\ + " -R id path(optional) Restore a file by ID. Use -l or -L to find the ID associated with the file.\n"\ + " -v Verbose mode, not recommended unless you are a developer.\n"\ + " -i Check for inconsistencies in the logs and trashed files (maybe implement)\n"\ + "\n" +#define MODE_NORMAL -1 +#define MODE_YES 0 +#define MODE_NO 1 +#define MODE_FORCE 2 +#define FUNCTION_FAILURE -1 // redesign +#define FUNCTION_SUCCESS 0 // redesign +#ifdef DEBUG_S // Stream for debugging, pass -DDEBUG_S and then compile to turn on +#define DEBUG_STREAM(x) std::cerr x +#else +#define DEBUG_STREAM(x) +#endif -- cgit v1.2.3