From e7d1515fca18bda75a36da1cf88ccf016d0b1a98 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 23 Sep 2021 15:57:38 +0200 Subject: [PATCH] Manager: Add index to dotfile iteration loop --- src/dotfile.cpp | 8 +++++--- src/dotfile.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dotfile.cpp b/src/dotfile.cpp index baaa643..94067af 100644 --- a/src/dotfile.cpp +++ b/src/dotfile.cpp @@ -161,16 +161,18 @@ void Dotfile::list(const std::vector& targets) return; } - forEachDotfile(targets, [](std::filesystem::directory_entry path, size_t workingDirectory) { + forEachDotfile(targets, [](std::filesystem::directory_entry path, size_t, size_t workingDirectory) { printf("%s\n", path.path().c_str() + workingDirectory + 1); }); } // ----------------------------------------- -void Dotfile::forEachDotfile(const std::vector& targets, const std::function& callback) +void Dotfile::forEachDotfile(const std::vector& targets, const std::function& callback) { size_t workingDirectory = s_workingDirectory.string().size(); + + size_t index = 0; for (const auto& path : std::filesystem::recursive_directory_iterator { s_workingDirectory }) { if (path.is_directory() || filter(path)) { continue; @@ -178,7 +180,7 @@ void Dotfile::forEachDotfile(const std::vector& targets, const std: if (!targets.empty() && !include(path.path().string(), targets)) { continue; } - callback(path, workingDirectory); + callback(path, index++, workingDirectory); } } diff --git a/src/dotfile.h b/src/dotfile.h index da766bb..3e26fc2 100644 --- a/src/dotfile.h +++ b/src/dotfile.h @@ -39,7 +39,7 @@ public: static void setExcludePaths(const std::vector& excludePaths) { s_excludePaths = excludePaths; } private: - void forEachDotfile(const std::vector& targets, const std::function& callback); + void forEachDotfile(const std::vector& targets, const std::function& callback); bool filter(const std::filesystem::path& path); bool include(const std::filesystem::path& path, const std::vector& targets);