winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 5c21dec74547d3d70e46c1aabd9df2ef087f9d96
parent 14ee740909cb64abda8f1962f2d6333081b147a3
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Thu, 17 Jun 2021 13:49:08 -0700

Retry on rename (#1178)


Diffstat:
Msrc/AppInstallerCLICore/Workflows/ShellExecuteInstallerHandler.cpp | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/AppInstallerCLICore/Workflows/ShellExecuteInstallerHandler.cpp b/src/AppInstallerCLICore/Workflows/ShellExecuteInstallerHandler.cpp @@ -257,8 +257,23 @@ namespace AppInstaller::CLI::Workflow break; } - // std::filesystem::rename() handles motw correctly if applicable. - std::filesystem::rename(installerPath, renamedDownloadedInstaller); + // If rename fails, don't give up quite yet. + bool retry = true; + + try + { + // std::filesystem::rename() handles motw correctly if applicable. + std::filesystem::rename(installerPath, renamedDownloadedInstaller); + retry = false; + } + CATCH_LOG(); + + if (retry) + { + std::this_thread::sleep_for(250ms); + // If it fails again, let that one throw + std::filesystem::rename(installerPath, renamedDownloadedInstaller); + } installerPath.assign(renamedDownloadedInstaller); AICLI_LOG(CLI, Info, << "Successfully renamed downloaded installer. Path: " << installerPath);