Skip to content
Closed
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
8 changes: 7 additions & 1 deletion lib/internal/vfs/file_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ class VirtualFileSystem {
this[kMounted] = true;
debug('mount %s', this[kMountPoint]);
loadVfsSetup();
registerVFS(this);
try {
registerVFS(this);
} catch (err) {
this[kMountPoint] = null;
this[kMounted] = false;
throw err;
}
return this;
}

Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-vfs-mount-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const { vfsState } = require('internal/fs/utils');
const baseMountPoint = path.resolve('/tmp/vfs-mount-errors-' + process.pid);
let mountCounter = 0;
const nextMount = () => baseMountPoint + '-' + (mountCounter++);
function assertUnmounted(instance, mountPoint) {
assert.strictEqual(instance.mounted, false);
assert.strictEqual(instance.mountPoint, null);
assert.strictEqual(instance.shouldHandle(mountPoint), false);
}

// EXDEV: rename across two different VFS instances
{
Expand Down Expand Up @@ -130,13 +135,15 @@ const nextMount = () => baseMountPoint + '-' + (mountCounter++);
const b = vfs.create();
a.mount(parent);
assert.throws(() => b.mount(child), { code: 'ERR_INVALID_STATE' });
assertUnmounted(b, child);
a.unmount();

// Reverse direction: child first, then parent rejected
const c = vfs.create();
const d = vfs.create();
c.mount(child);
assert.throws(() => d.mount(parent), { code: 'ERR_INVALID_STATE' });
assertUnmounted(d, parent);
c.unmount();
}

Expand All @@ -147,6 +154,7 @@ const nextMount = () => baseMountPoint + '-' + (mountCounter++);
const b = vfs.create();
a.mount(m);
assert.throws(() => b.mount(m), { code: 'ERR_INVALID_STATE' });
assertUnmounted(b, m);
a.unmount();
}

Expand Down
Loading