Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: clean repo func on windows (#2243)
Browse files Browse the repository at this point in the history
`rimraf.sync` does not retry when it encounters errors on windows. The async version retries a number of times before failing.

See isaacs/rimraf#72 for context on why rimraf on windows might error.

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
alanshaw committed Jul 12, 2019
1 parent 04aa63c commit 26b92a1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions test/http-api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('HTTP API', () => {
this.timeout(50 * 1000)

await http.api.stop()
clean(repoTests)
await clean(repoTests)
})

describe('## http-api spec tests for custom config', () => {
Expand All @@ -81,7 +81,7 @@ describe('HTTP API', () => {
this.timeout(50 * 1000)

await http.api.stop()
clean(repoTests)
await clean(repoTests)
})

describe('## http-api spec tests for default config', () => {
Expand Down
9 changes: 5 additions & 4 deletions test/utils/clean.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use strict'

const rimraf = require('rimraf')
const fs = require('fs')
const fs = require('fs').promises
const { promisify } = require('util')

module.exports = (dir) => {
module.exports = async dir => {
try {
fs.accessSync(dir)
await fs.access(dir)
} catch (err) {
// Does not exist so all good
return
}

rimraf.sync(dir)
return promisify(rimraf)(dir)
}
5 changes: 1 addition & 4 deletions test/utils/create-repo-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ function createTempRepo (repoPath) {
series([
// ignore err, might have been closed already
(cb) => repo.close(() => cb()),
(cb) => {
clean(repoPath)
cb()
}
(cb) => clean(repoPath).then(cb, cb)
], done)
}

Expand Down
5 changes: 2 additions & 3 deletions test/utils/on-and-off.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ function off (tests) {
return thing.ipfs('init')
})

after(function (done) {
after(function () {
this.timeout(20 * 1000)
clean(repoPath)
setImmediate(done)
return clean(repoPath)
})

tests(thing)
Expand Down

0 comments on commit 26b92a1

Please sign in to comment.