Skip to content

Commit c9689f6

Browse files
authored
🐛 Fix detach error check (#190)
Added check for err.code Added 5 attempts with backoff.
1 parent e1394d2 commit c9689f6

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/hdiutil.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@ exports.attach = function (path, cb) {
6363
exports.detach = function (path, cb) {
6464
const args = ['detach', path]
6565

66-
util.sh('hdiutil', args, function (err) {
67-
if (err && err.exitCode === 16 && /Resource busy/.test(err.stderr)) {
66+
let attempts = 0
67+
function attemptDetach (err) {
68+
attempts += 1
69+
if (err && (err.exitCode === 16 || err.code === 16) && /Resource busy/.test(err.stderr) && attempts <= 5) {
6870
setTimeout(function () {
69-
util.sh('hdiutil', args, (err) => cb(err))
70-
}, 1000)
71+
util.sh('hdiutil', args, attemptDetach)
72+
}, 1000 * Math.pow(2, attempts - 1))
7173
} else {
7274
cb(err)
7375
}
74-
})
76+
}
77+
78+
util.sh('hdiutil', args, attemptDetach)
7579
}

0 commit comments

Comments
 (0)