Manager: Add verbose flag and store it in new Config class

Check the verbosity in the Dotfile class when printing file operations.
This commit is contained in:
Riyyi
2022-01-24 01:03:30 +01:00
parent 5ec1272172
commit c032373940
3 changed files with 37 additions and 2 deletions
+7 -2
View File
@@ -15,6 +15,7 @@
#include <unistd.h> // geteuid, getlogin, setegid, seteuid
#include <vector>
#include "config.h"
#include "dotfile.h"
#include "machine.h"
#include "util/file.h"
@@ -199,14 +200,18 @@ void Dotfile::sync(SyncType type,
if (std::filesystem::is_regular_file(from)) {
auto directory = to.parent_path();
if (!directory.empty() && !std::filesystem::exists(directory)) {
printf("Created directory: '%s'\n", directory.c_str());
if (Config::the().verbose()) {
printf("Created directory: '%s'\n", directory.c_str());
}
std::filesystem::create_directories(directory, error);
printError(to.relative_path().parent_path(), error);
}
}
// Copy the file or directory
printf("'%s' -> '%s'\n", from.c_str(), to.c_str());
if (Config::the().verbose()) {
printf("'%s' -> '%s'\n", from.c_str(), to.c_str());
}
std::filesystem::copy(from, to, copyOptions, error);
printError(to, error);