From 5cca59144834a47af83b03a7db49125cf6a2ee52 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 10 Jan 2022 16:33:11 +0100 Subject: [PATCH] Manager: Rename paths -> indices where applicable --- src/dotfile.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/dotfile.cpp b/src/dotfile.cpp index b0860ec..3a7b22a 100644 --- a/src/dotfile.cpp +++ b/src/dotfile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Riyyi + * Copyright (C) 2021-2022 Riyyi * * SPDX-License-Identifier: MIT */ @@ -39,37 +39,37 @@ void Dotfile::add(const std::vector& targets) return; } - std::vector noExistPaths; - std::vector homePaths; - std::vector systemPaths; + std::vector noExistIndices; + std::vector homeIndices; + std::vector systemIndices; // Separate home and system targets for (size_t i = 0; i < targets.size(); ++i) { if (!std::filesystem::is_regular_file(targets.at(i)) && !std::filesystem::is_directory(targets.at(i)) && !std::filesystem::is_symlink(targets.at(i))) { - noExistPaths.push_back(i); + noExistIndices.push_back(i); continue; } if (isSystemTarget(targets.at(i))) { - systemPaths.push_back(i); + systemIndices.push_back(i); } else { - homePaths.push_back(i); + homeIndices.push_back(i); } } // Print non-existing targets and exit - if (!noExistPaths.empty()) { - for (size_t i : noExistPaths) { + if (!noExistIndices.empty()) { + for (size_t i : noExistIndices) { fprintf(stderr, "\033[31;1mDotfile:\033[0m '%s': no such file or directory\n", targets.at(i).c_str()); } return; } sync( - targets, homePaths, systemPaths, + targets, homeIndices, systemIndices, [](std::string* paths, const std::string& homePath, const std::string& homeDirectory) { paths[0] = homePath; paths[1] = homePath.substr(homeDirectory.size() + 1); @@ -101,23 +101,23 @@ void Dotfile::list(const std::vector& targets) void Dotfile::pull(const std::vector& targets) { std::vector dotfiles; - std::vector homeFiles; - std::vector systemFiles; + std::vector homeIndices; + std::vector systemIndices; // Separate home and system targets forEachDotfile(targets, [&](const std::filesystem::directory_entry& path, size_t index) { dotfiles.push_back(path.path().string()); if (isSystemTarget(path.path().string())) { - systemFiles.push_back(index); + systemIndices.push_back(index); } else { - homeFiles.push_back(index); + homeIndices.push_back(index); } }); size_t workingDirectory = s_workingDirectory.string().size(); sync( - dotfiles, homeFiles, systemFiles, + dotfiles, homeIndices, systemIndices, [&workingDirectory](std::string* paths, const std::string& homeFile, const std::string& homeDirectory) { // homeFile = /home//dotfiles/ // copy: /home// -> /home//dotfiles/ @@ -135,23 +135,23 @@ void Dotfile::pull(const std::vector& targets) void Dotfile::push(const std::vector& targets) { std::vector dotfiles; - std::vector homeFiles; - std::vector systemFiles; + std::vector homeIndices; + std::vector systemIndices; // Separate home and system targets forEachDotfile(targets, [&](const std::filesystem::directory_entry& path, size_t index) { dotfiles.push_back(path.path().string()); if (isSystemTarget(path.path().string())) { - systemFiles.push_back(index); + systemIndices.push_back(index); } else { - homeFiles.push_back(index); + homeIndices.push_back(index); } }); size_t workingDirectory = s_workingDirectory.string().size(); sync( - dotfiles, homeFiles, systemFiles, + dotfiles, homeIndices, systemIndices, [&workingDirectory](std::string* paths, const std::string& homeFile, const std::string& homeDirectory) { // homeFile = /home//dotfiles/ // copy: /home//dotfiles/ -> /home// @@ -175,7 +175,7 @@ void Dotfile::sync(const std::vector& paths, const std::vector& paths, const std::vector