From 0bd12ed9a209e78d8bafbb1221c0f3162dbd4ccc Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 20 Oct 2018 11:51:47 +0100 Subject: [PATCH] Defer deleting temporary repository files Also don't propagate the error if deleting fails, just log it. If deleting fails, it doesn't break LOOT, it just uses up a little extra space until the next time the user runs disk cleanup or a similar utility, and temp dir clones are infrequent. --- src/api/helpers/git_helper.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/api/helpers/git_helper.cpp b/src/api/helpers/git_helper.cpp index 71349078..fcd0a066 100644 --- a/src/api/helpers/git_helper.cpp +++ b/src/api/helpers/git_helper.cpp @@ -235,10 +235,18 @@ void GitHelper::Clone(const std::filesystem::path& path, } for (const auto& filename : filenamesToMove) { - fs::rename(repoPath / filename, path / filename); + fs::copy(repoPath / filename, path / filename, std::filesystem::copy_options::recursive); } - fs::remove_all(repoPath); + try { + fs::remove_all(repoPath); + } catch (std::exception& e) { + if (logger_) { + logger_->error( + "Could not delete temporary repository path \"{}\": {}", + repoPath.u8string(), e.what()); + } + } // Open the repo again. Open(path);