From 1dd8687e28f7f82f7dce01a9cc3adc911e233be2 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 23 Oct 2014 19:33:57 +0100 Subject: [PATCH] Fixed bad permissions on LOOT .git folders. They were being fixed when LOOT needed to delete them, but left with too restrictive permissions otherwise. Now the permissions are write access for all on successful operations too. --- src/backend/git.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/backend/git.cpp b/src/backend/git.cpp index 7f92b4b1..d35960cf 100644 --- a/src/backend/git.cpp +++ b/src/backend/git.cpp @@ -40,6 +40,16 @@ namespace fs = boost::filesystem; namespace lc = boost::locale; namespace loot { + + // Removes the read-only flag from some files in git repositories created by libgit2. + void FixRepoPermissions(const fs::path& path) { + BOOST_LOG_TRIVIAL(trace) << "Recursively setting write permission on directory: " << path; + for (fs::recursive_directory_iterator it(path); it != fs::recursive_directory_iterator(); ++it) { + BOOST_LOG_TRIVIAL(trace) << "Setting write permission for: " << it->path(); + fs::permissions(it->path(), fs::add_perms | fs::owner_write | fs::group_write | fs::others_write); + } + } + struct git_handler { public: git_handler() : @@ -58,7 +68,10 @@ namespace loot { buf({0}) {} ~git_handler() { + string path(git_repository_path(repo)); free(); + + FixRepoPermissions(path); } void free() { @@ -131,15 +144,6 @@ namespace loot { return git_repository_open_ext(NULL, path.string().c_str(), GIT_REPOSITORY_OPEN_NO_SEARCH, NULL) == 0; } - // Removes the read-only flag from some files in git repositories created by libgit2. - void FixRepoPermissions(const fs::path& path) { - BOOST_LOG_TRIVIAL(trace) << "Recursively setting write permission on directory: " << path; - for (fs::recursive_directory_iterator it(path); it != fs::recursive_directory_iterator(); ++it) { - BOOST_LOG_TRIVIAL(trace) << "Setting write permission for: " << it->path(); - fs::permissions(it->path(), fs::add_perms | fs::owner_write | fs::group_write | fs::others_write); - } - } - int diffFileCallback(const git_diff_delta *delta, float progress, void * payload) { BOOST_LOG_TRIVIAL(trace) << "Checking diff for: " << delta->old_file.path; if (strcmp(delta->old_file.path, "masterlist.yaml") == 0) {