mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Tweak masterlist cloning to avoid undefined behaviour
According to Boost's docs, it's undefined behaviour to add or remove entries in a directory that is being iterated over.
This commit is contained in:
@@ -258,6 +258,7 @@ void GitHelper::Clone(const boost::filesystem::path& path,
|
||||
GrantWritePermissions(path);
|
||||
GrantWritePermissions(repoPath);
|
||||
|
||||
std::vector<boost::filesystem::path> filenamesToMove;
|
||||
for (fs::directory_iterator it(repoPath);
|
||||
it != fs::directory_iterator();
|
||||
++it) {
|
||||
@@ -265,7 +266,11 @@ void GitHelper::Clone(const boost::filesystem::path& path,
|
||||
if (fs::exists(targetPath)) {
|
||||
fs::remove_all(targetPath);
|
||||
}
|
||||
fs::rename(it->path(), targetPath);
|
||||
filenamesToMove.push_back(it->path().filename());
|
||||
}
|
||||
|
||||
for (const auto& filename : filenamesToMove) {
|
||||
fs::rename(repoPath / filename, path / filename);
|
||||
}
|
||||
|
||||
fs::remove_all(repoPath);
|
||||
|
||||
Reference in New Issue
Block a user