Browse Source

Manager: Rename files to paths

master
Riyyi 3 years ago
parent
commit
c14db5bd46
  1. 16
      src/dotfile.cpp
  2. 2
      src/dotfile.h

16
src/dotfile.cpp

@ -134,14 +134,14 @@ void Dotfile::pull(const std::vector<std::string>& targets)
// ----------------------------------------- // -----------------------------------------
void Dotfile::sync(const std::vector<std::string>& files, const std::vector<size_t>& homeIndices, const std::vector<size_t>& systemIndices, void Dotfile::sync(const std::vector<std::string>& paths, const std::vector<size_t>& homeIndices, const std::vector<size_t>& systemIndices,
const std::function<void(std::string*, const std::string&, const std::string&)>& generateHomePaths, const std::function<void(std::string*, const std::string&, const std::string&)>& generateHomePaths,
const std::function<void(std::string*, const std::string&)>& generateSystemPaths) const std::function<void(std::string*, const std::string&)>& generateSystemPaths)
{ {
bool root = !geteuid() ? true : false; bool root = !geteuid() ? true : false;
if (!systemIndices.empty() && !root) { if (!systemIndices.empty() && !root) {
for (size_t i : systemIndices) { for (size_t i : systemIndices) {
fprintf(stderr, "\033[31;1mDotfile:\033[0m you cannot copy system file '%s' unless you are root\n", files.at(i).c_str()); fprintf(stderr, "\033[31;1mDotfile:\033[0m you cannot copy system file '%s' unless you are root\n", paths.at(i).c_str());
} }
return; return;
} }
@ -196,15 +196,15 @@ void Dotfile::sync(const std::vector<std::string>& files, const std::vector<size
// /home/<user>/ // /home/<user>/
std::string homeDirectory = "/home/" + std::string(user->pw_name); std::string homeDirectory = "/home/" + std::string(user->pw_name);
for (size_t i : homeIndices) { for (size_t i : homeIndices) {
std::string paths[2]; std::string homePaths[2];
generateHomePaths(paths, files.at(i), homeDirectory); generateHomePaths(homePaths, paths.at(i), homeDirectory);
copy(paths[0], paths[1], true); copy(homePaths[0], homePaths[1], true);
} }
// / // /
for (size_t i : systemIndices) { for (size_t i : systemIndices) {
std::string paths[2]; std::string systemPaths[2];
generateSystemPaths(paths, files.at(i)); generateSystemPaths(systemPaths, paths.at(i));
copy(paths[0], paths[1], false); copy(systemPaths[0], systemPaths[1], false);
} }
} }

2
src/dotfile.h

@ -40,7 +40,7 @@ public:
static void setExcludePaths(const std::vector<ExcludePath>& excludePaths) { s_excludePaths = excludePaths; } static void setExcludePaths(const std::vector<ExcludePath>& excludePaths) { s_excludePaths = excludePaths; }
private: private:
void sync(const std::vector<std::string>& files, const std::vector<size_t>& homeIndices, const std::vector<size_t>& systemIndices, void sync(const std::vector<std::string>& paths, const std::vector<size_t>& homeIndices, const std::vector<size_t>& systemIndices,
const std::function<void(std::string*, const std::string&, const std::string&)>& generateHomePaths, const std::function<void(std::string*, const std::string&, const std::string&)>& generateHomePaths,
const std::function<void(std::string*, const std::string&)>& generateSystemPaths); const std::function<void(std::string*, const std::string&)>& generateSystemPaths);
void forEachDotfile(const std::vector<std::string>& targets, const std::function<void(const std::filesystem::directory_entry&, size_t, size_t)>& callback); void forEachDotfile(const std::vector<std::string>& targets, const std::function<void(const std::filesystem::directory_entry&, size_t, size_t)>& callback);

Loading…
Cancel
Save