From ef739edd2078be23761f6e9b2c9dff7a20493cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Garramu=C3=B1o?= Date: Fri, 15 Aug 2025 09:44:38 -0300 Subject: [PATCH] CPack/DragNDrop: Prevent hdiutil "resource is busy" failures Run `sync` to finish pending filesystem operations before running `hdiutil`. Fixes: #27136 --- Source/CPack/cmCPackDragNDropGenerator.cxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index 05489d054d..f0c3439c49 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -76,6 +76,14 @@ int cmCPackDragNDropGenerator::InitializeInternal() paths.emplace_back("/Applications/Xcode.app/Contents/Developer/Tools"); paths.emplace_back("/Developer/Tools"); + std::string const sync_path = cmSystemTools::FindProgram("sync"); + if (sync_path.empty()) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Cannot locate sync command" << std::endl); + return 0; + } + this->SetOptionIfNotSet("CPACK_COMMAND_SYNC", sync_path); + std::string const hdiutil_path = cmSystemTools::FindProgram("hdiutil"); if (hdiutil_path.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -415,6 +423,16 @@ int cmCPackDragNDropGenerator::CreateDMG(std::string const& src_dir, std::string temp_image = cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/temp.dmg"); + // Finish filesystem operations before writing disk image. + std::string sync_command = this->GetOption("CPACK_COMMAND_SYNC"); + std::string sync_error; + if (!this->RunCommand(sync_command, &sync_error)) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error running sync command." << std::endl + << sync_error << std::endl); + return 0; + } + std::string create_error; auto temp_image_command = cmStrCat(this->GetOption("CPACK_COMMAND_HDIUTIL"),