From 29e0c5ced92dcde41aaee43668174733e8dd9e74 Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Sat, 24 Jul 2021 00:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Don't=20test=20"Resource=20busy"?= =?UTF-8?q?=20when=20detaching=20(#200)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. We have EBUSY (code 16) https://ss64.com/osx/hdiutil.html said: > [EBUSY] Resource busy. Used if necessary exclusive access cannot be obtained. This error often appears when a volume can't be unmounted. "EBUSY" can be found in /sys/errno.h of the BSD kernel: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/errno.h#L108 : > #define EBUSY 16 /* Device / Resource busy */ https://github.com/freebsd/freebsd-src/blob/1e0a518d65488caafff89a4ecba9cfb2be233379/sys/sys/errno.h#L69 : > #define EBUSY 16 /* Device busy */ 2. Error messages will be localized For example: | Language | "Resource busy" | -------- | --------------- | Chinese | 资源忙 | Chinese | 資源忙碌中 | Japanese | リソースが使用中です | Russian | Ресурс занят 3. Conculsion We should not test the content of the error message. Just testing the exit code "16" is sufficient and reliable. --- lib/hdiutil.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hdiutil.js b/lib/hdiutil.js index 2ff90ee..1efd05d 100644 --- a/lib/hdiutil.js +++ b/lib/hdiutil.js @@ -66,7 +66,7 @@ exports.detach = function (path, cb) { let attempts = 0 function attemptDetach (err) { attempts += 1 - if (err && (err.exitCode === 16 || err.code === 16) && /Resource busy/.test(err.stderr) && attempts <= 5) { + if (err && (err.exitCode === 16 || err.code === 16) && attempts <= 5) { setTimeout(function () { util.sh('hdiutil', args, attemptDetach) }, 1000 * Math.pow(2, attempts - 1))