From af33f2d6b57dd333f0805448d5b7e60b7ee33efa Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Fri, 29 Nov 2024 09:50:40 +0800 Subject: [PATCH] [73_37] Retry 5 times to create the dmg --- xmake/research.lua | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/xmake/research.lua b/xmake/research.lua index a660df8df..37b61ae1c 100644 --- a/xmake/research.lua +++ b/xmake/research.lua @@ -297,6 +297,25 @@ target("research") do end end +function execWithRetry(command, args, maxRetries, retryDelay) + local retries = 0 + local result + + while retries <= maxRetries do + result = os.execute(command .. " " .. table.concat(args, " ")) + if result then + return true, "Command executed successfully" + else + retries = retries + 1 + if retries > maxRetries then + return false, "Command failed after " .. maxRetries .. " retries" + else + -- os.execute("sleep " .. retryDelay) + end + end + end +end + target("research_packager") do set_enabled(is_plat("macosx") and is_mode("release")) set_kind("phony") @@ -322,6 +341,12 @@ target("research_packager") do local app_dir = target:installdir() .. "/../../" os.cp("$(buildir)/Info.plist", app_dir .. "/Contents") os.execv("codesign", {"--force", "--deep", "--sign", "-", app_dir}) - os.execv("/usr/bin/sudo /usr/bin/hdiutil create $(buildir)/" .. dmg_name .. " -fs HFS+ -srcfolder " .. app_dir) + hdiutil_command= "/usr/bin/sudo /usr/bin/hdiutil create $(buildir)/" .. dmg_name .. " -fs HFS+ -srcfolder " .. app_dir + local success, message= execWithRetry(hdiutil_command, {}, 5, 1) + if success then + print(message) + else + print("Error: " .. message) + end end) end