-
-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
windows: only fall back to move-remove when absolutely necessary
- Loading branch information
Showing
17 changed files
with
1,058 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const { | ||
promises: { chmod }, | ||
chmodSync, | ||
} = require('./fs.js') | ||
|
||
const fixEPERM = fn => async path => { | ||
try { | ||
return await fn(path) | ||
} catch (er) { | ||
if (er.code === 'ENOENT') { | ||
return | ||
} | ||
if (er.code === 'EPERM') { | ||
try { | ||
await chmod(path, 0o666) | ||
} catch (er2) { | ||
if (er2.code === 'ENOENT') { | ||
return | ||
} | ||
throw er | ||
} | ||
return await fn(path) | ||
} | ||
throw er | ||
} | ||
} | ||
|
||
const fixEPERMSync = fn => path => { | ||
try { | ||
return fn(path) | ||
} catch (er) { | ||
if (er.code === 'ENOENT') { | ||
return | ||
} | ||
if (er.code === 'EPERM') { | ||
try { | ||
chmodSync(path, 0o666) | ||
} catch (er2) { | ||
if (er2.code === 'ENOENT') { | ||
return | ||
} | ||
throw er | ||
} | ||
return fn(path) | ||
} | ||
throw er | ||
} | ||
} | ||
|
||
module.exports = { | ||
fixEPERM, | ||
fixEPERMSync, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const MAXBACKOFF = 100 | ||
const RATE = 1.2 | ||
const MAXRETRIES = 10 | ||
|
||
const codes = new Set(['EMFILE', 'ENFILE', 'EBUSY']) | ||
const retryBusy = fn => { | ||
const method = async (path, opt, backoff = 1) => { | ||
const mbo = opt.maxBackoff || MAXBACKOFF | ||
const rate = Math.max(opt.backoff || RATE, RATE) | ||
const max = opt.retries || MAXRETRIES | ||
let retries = 0 | ||
while (true) { | ||
try { | ||
return await fn(path) | ||
} catch (er) { | ||
if (codes.has(er.code)) { | ||
backoff = Math.ceil(backoff * rate) | ||
if (backoff < mbo) { | ||
return new Promise((res, rej) => { | ||
setTimeout(() => { | ||
method(path, opt, backoff).then(res, rej) | ||
}, backoff) | ||
}) | ||
} | ||
if (retries < max) { | ||
retries++ | ||
continue | ||
} | ||
} | ||
throw er | ||
} | ||
} | ||
} | ||
|
||
return method | ||
} | ||
|
||
// just retries, no async so no backoff | ||
const retryBusySync = fn => { | ||
const method = (path, opt) => { | ||
const max = opt.retries || MAXRETRIES | ||
let retries = 0 | ||
while (true) { | ||
try { | ||
return fn(path) | ||
} catch (er) { | ||
if (codes.has(er.code) && retries < max) { | ||
retries++ | ||
continue | ||
} | ||
throw er | ||
} | ||
} | ||
} | ||
return method | ||
} | ||
|
||
module.exports = { | ||
retryBusy, | ||
retryBusySync, | ||
} |
Oops, something went wrong.