Skip to content

Commit 4a4d21c

Browse files
authored
No error when unlinking nonexistent file (#34)
* No error when unlinking nonexistent file * Style + comment
1 parent 4d5b441 commit 4a4d21c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ module.exports = class RandomAccessFile extends RandomAccessStorage {
226226
fs.unlink(this.filename, onunlink)
227227

228228
function onunlink (err) {
229+
// if the file isn't there, its already unlinked, ignore
230+
if (err && err.code === 'ENOENT') err = null
231+
229232
if (!self._rmdir || !root || dir === root) return req.callback(err)
230233
fs.rmdir(dir, onrmdir)
231234
}

test/basic.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,20 @@ test('unlink', async function (t) {
439439
}
440440
})
441441

442+
test('unlink on uncreated file does not reject', async function (t) {
443+
t.plan(2)
444+
const name = gen()
445+
446+
const file = new RAF(name)
447+
t.is(fs.existsSync(file.filename), false) // Not yet created, since no write
448+
449+
file.unlink(onunlink)
450+
451+
function onunlink (err) {
452+
t.absent(err, 'no error')
453+
}
454+
})
455+
442456
test('pool', function (t) {
443457
t.plan(8)
444458

0 commit comments

Comments
 (0)