Skip to content

Commit

Permalink
🐛 Don't test "Resource busy" when detaching (#200)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pzhlkj6612 authored Jul 23, 2021
1 parent dd7b7f7 commit 29e0c5c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hdiutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 29e0c5c

Please sign in to comment.