Add retry mechanism to rename
MODIFY
include/vcpkg/base/files.h
include/vcpkg/base/files.h
@@ -191,6 +191,7 @@ namespace vcpkg::Files
const std::string& data,
std::error_code& ec) = 0;
void rename(const fs::path& oldpath, const fs::path& newpath, LineInfo linfo);
+ void rename_with_retry(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec);
virtual void rename(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) = 0;
virtual void rename_or_copy(const fs::path& oldpath,
const fs::path& newpath,

MODIFY
src/vcpkg/base/files.cpp
src/vcpkg/base/files.cpp
@@ -517,6 +517,21 @@ namespace vcpkg::Files
linfo, "error renaming file: %s: %s: %s", fs::u8string(oldpath), fs::u8string(newpath), ec.message());
}
}
+ void Filesystem::rename_with_retry(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec)
+ {
+ this->rename(oldpath, newpath, ec);
+ using namespace std::chrono_literals;
+ for (const auto& delay : {10ms, 100ms, 1000ms})
+ {
+ if (!ec)
+ {
+ return;
+ }
+
+ std::this_thread::sleep_for(delay);
+ this->rename(oldpath, newpath, ec);
+ }
+ }
bool Filesystem::remove(const fs::path& path, LineInfo linfo)
{

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -836,7 +836,7 @@ namespace vcpkg
Strings::concat(PRELUDE, "Error: while removing ", fs::u8string(destination_tar), ": ", ec.message()),
expected_right_tag};
}
- fs.rename(destination_tmp, destination, ec);
+ fs.rename_with_retry(destination_tmp, destination, ec);
if (ec)
{
return {Strings::concat(PRELUDE,

Add retry mechanism to rename (#84)