Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion workspaces/arborist/lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ module.exports = cls => class Reifier extends cls {
if (er.code === 'ENOENT') {
return didMkdirp ? null : mkdir(dirname(to), { recursive: true }).then(() =>
this[_renamePath](from, to, true))
} else if (er.code === 'EEXIST') {
} else if (er.code === 'EEXIST' || er.code === 'ENOTEMPTY') {
return rm(to, { recursive: true, force: true }).then(() => moveFile(from, to))
} else {
throw er
Expand Down
66 changes: 66 additions & 0 deletions workspaces/arborist/test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,72 @@ t.test('rollbacks', { buffered: false }, t => {
return printTree(tree)
})

t.test('fail retiring nodes because rm fails after enotempty', t => {
const path = fixture(t, 'testing-bundledeps-3')
createRegistry(t, true)
const a = newArb({ path, installStrategy: 'nested' })
const enotempty = new Error('rename fail')
enotempty.code = 'ENOTEMPTY'
const kRenamePath = Symbol.for('renamePath')
const renamePath = a[kRenamePath]
a[kRenamePath] = (from, to) => {
a[kRenamePath] = renamePath
failRename = enotempty
failRm = true
return a[kRenamePath](from, to)
}
const kRollback = Symbol.for('rollbackRetireShallowNodes')
const rollbackRetireShallowNodes = a[kRollback]
let rolledBack = false
a[kRollback] = er => {
rolledBack = true
failRename = new Error('some other error')
failRm = false
t.match(er, new Error('rm fail'))
a[kRollback] = rollbackRetireShallowNodes
return a[kRollback](er).then(er => {
failRename = null
return er
}, er => {
failRename = null
throw er
})
}

return t.rejects(a.reify({
update: ['@isaacs/testing-bundledeps-parent'],
}), new Error('rm fail'))
.then(() => t.equal(rolledBack, true, 'rolled back'))
})

t.test('fail retiring node with enotempty, but then rm fixes it', async t => {
const path = fixture(t, 'testing-bundledeps-3')
createRegistry(t, true)
const a = newArb({ path, installStrategy: 'nested' })
const enotempty = new Error('rename fail')
enotempty.code = 'ENOTEMPTY'
const kRenamePath = Symbol.for('renamePath')
const renamePath = a[kRenamePath]
a[kRenamePath] = (from, to) => {
a[kRenamePath] = renamePath
failRenameOnce = enotempty
return a[kRenamePath](from, to)
}
const kRollback = Symbol.for('rollbackRetireShallowNodes')
const rollbackRetireShallowNodes = a[kRollback]
a[kRollback] = er => {
t.fail('should not roll back!')
a[kRollback] = rollbackRetireShallowNodes
return a[kRollback](er)
}

const tree = await a.reify({
update: ['@isaacs/testing-bundledeps-parent'],
save: false,
})
return printTree(tree)
})

t.test('fail creating sparse tree', t => {
t.teardown(() => failMkdir = null)
const path = fixture(t, 'testing-bundledeps-3')
Expand Down