diff --git a/src/backends/Locked.ts b/src/backends/Locked.ts index 07c1b7dd3..009e588ea 100644 --- a/src/backends/Locked.ts +++ b/src/backends/Locked.ts @@ -153,20 +153,6 @@ export default class LockedFS implements FileSystem { return this.fs.existsSync(p, cred); } - public async realpath(p: string, cred: Cred): Promise { - await this._mu.lock(p); - const resolvedPath = await this.fs.realpath(p, cred); - this._mu.unlock(p); - return resolvedPath; - } - - public realpathSync(p: string, cred: Cred): string { - if (this._mu.isLocked(p)) { - throw new Error('invalid sync call'); - } - return this.fs.realpathSync(p, cred); - } - public async link(srcpath: string, dstpath: string, cred: Cred): Promise { await this._mu.lock(srcpath); await this.fs.link(srcpath, dstpath, cred); diff --git a/src/backends/SyncStore.ts b/src/backends/SyncStore.ts index 323889ff6..2b0fea8a9 100644 --- a/src/backends/SyncStore.ts +++ b/src/backends/SyncStore.ts @@ -213,7 +213,6 @@ export class SyncStoreFileSystem extends SyncFileSystem { return { name: this.store.name, readonly: false, - supportsLinks: false, supportsProperties: true, synchronous: true, freeSpace: 0, diff --git a/src/emulation/promises.ts b/src/emulation/promises.ts index 920180be2..2a25d042b 100644 --- a/src/emulation/promises.ts +++ b/src/emulation/promises.ts @@ -611,7 +611,7 @@ rmdir satisfies typeof Node.promises.rmdir; export async function mkdir(path: PathLike, mode?: Node.Mode | (Node.MakeDirectoryOptions & { recursive?: false })): Promise; export async function mkdir(path: PathLike, mode: Node.MakeDirectoryOptions & { recursive: true }): Promise; export async function mkdir(path: PathLike, mode?: Node.Mode | Node.MakeDirectoryOptions): Promise { - return doOp('mkdir', true, path, normalizeMode(typeof mode == 'object' ? mode?.mode : mode, 0o777), cred); + await doOp('mkdir', true, path, normalizeMode(typeof mode == 'object' ? mode?.mode : mode, 0o777), cred); } mkdir satisfies typeof Node.promises.mkdir; diff --git a/src/filesystem.ts b/src/filesystem.ts index 8e8e1171c..6bfed1922 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -38,11 +38,6 @@ export interface FileSystemMetadata { */ supportsProperties: boolean; - /** - * Does the FS support links - */ - supportsLinks: boolean; - /** * The total space */ @@ -75,7 +70,6 @@ export abstract class FileSystem { readonly: false, synchronous: false, supportsProperties: false, - supportsLinks: false, totalSpace: 0, freeSpace: 0, }; @@ -199,57 +193,6 @@ export abstract class FileSystem { } } - /** - * Asynchronous `realpath`. - * - * Note that the Node API will resolve `path` to an absolute path. - */ - public async realpath(path: string, cred: Cred): Promise { - if (this.metadata.supportsLinks) { - // The path could contain symlinks. Split up the path, - // resolve any symlinks, return the resolved string. - const splitPath = path.split(sep); - // TODO: Simpler to just pass through file, find sep and such. - for (let i = 0; i < splitPath.length; i++) { - const addPaths = splitPath.slice(0, i + 1); - splitPath[i] = join(...addPaths); - } - return splitPath.join(sep); - } else { - // No symlinks. We just need to verify that it exists. - if (!(await this.exists(path, cred))) { - throw ApiError.ENOENT(path); - } - return path; - } - } - - /** - * Synchronous `realpath`. - * - * Note that the Node API will resolve `path` to an absolute path. - */ - public realpathSync(path: string, cred: Cred): string { - if (this.metadata.supportsLinks) { - // The path could contain symlinks. Split up the path, - // resolve any symlinks, return the resolved string. - const splitPath = path.split(sep); - // TODO: Simpler to just pass through file, find sep and such. - for (let i = 0; i < splitPath.length; i++) { - const addPaths = splitPath.slice(0, i + 1); - splitPath[i] = join(...addPaths); - } - return splitPath.join(sep); - } else { - // No symlinks. We just need to verify that it exists. - if (this.existsSync(path, cred)) { - return path; - } else { - throw ApiError.ENOENT(path); - } - } - } - /** * Asynchronous `link`. */ diff --git a/test/tests/chmod.test.ts b/test/tests/chmod.test.ts index 5199026e8..83b2dbc42 100644 --- a/test/tests/chmod.test.ts +++ b/test/tests/chmod.test.ts @@ -1,4 +1,4 @@ -import { fs, createMockStats, backends, configure, tmpDir, fixturesDir } from '../common'; +import { fs, createMockStats, fixturesDir } from '../common'; import * as path from 'path'; import { jest } from '@jest/globals'; @@ -6,15 +6,9 @@ const isWindows = process.platform === 'win32'; const asyncMode = 0o777; const modeSync = 0o644; -describe.each(backends)('%s chmod tests', (name, options) => { - const configured = configure(options); - - afterEach(() => { - jest.restoreAllMocks(); - }); +describe('chmod tests', () => { it('should change file mode using chmod', async () => { - await configured; const file1 = path.join(fixturesDir, 'a.js'); jest.spyOn(fs, 'chmod').mockImplementation(async (path, mode) => { @@ -33,7 +27,6 @@ describe.each(backends)('%s chmod tests', (name, options) => { }); it('should change file mode using fchmod', async () => { - await configured; const file2 = path.join(fixturesDir, 'a1.js'); jest.spyOn(fs, 'open').mockImplementation(async (path, flags, mode) => { @@ -58,8 +51,7 @@ describe.each(backends)('%s chmod tests', (name, options) => { }); it('should change symbolic link mode using lchmod', async () => { - await configured; - const link = path.join(tmpDir, 'symbolic-link'); + const link = path.join('symbolic-link'); const file2 = path.join(fixturesDir, 'a1.js'); jest.spyOn(fs, 'unlinkSync').mockImplementation(path => { diff --git a/test/tests/error-messages.test.ts b/test/tests/error-messages.test.ts index 47882f180..eee3a50ed 100644 --- a/test/tests/error-messages.test.ts +++ b/test/tests/error-messages.test.ts @@ -48,20 +48,15 @@ describe.each(backends)('%s Error tests', (name, options) => { await expectError(fs.promises.open, fn, 'r'); await expectError(fs.promises.readdir, fn); await expectError(fs.promises.unlink, fn); - - if (fs.getMount('/').metadata.supportsLinks) { - await expectError(fs.promises.link, fn, 'foo'); - } + await expectError(fs.promises.link, fn, 'foo'); if (fs.getMount('/').metadata.supportsProperties) { await expectError(fs.promises.chmod, fn, 0o666); } } - if (fs.getMount('/').metadata.supportsLinks) { - await expectError(fs.promises.lstat, fn); - await expectError(fs.promises.readlink, fn); - } + await expectError(fs.promises.lstat, fn); + await expectError(fs.promises.readlink, fn); }); // Sync operations @@ -81,20 +76,15 @@ describe.each(backends)('%s Error tests', (name, options) => { expectSyncError(fs.openSync, fn, 'r'); expectSyncError(fs.readdirSync, fn); expectSyncError(fs.unlinkSync, fn); + expectSyncError(fs.linkSync, fn, 'foo'); if (fs.getMount('/').metadata.supportsProperties) { expectSyncError(fs.chmodSync, fn, 0o666); } - - if (fs.getMount('/').metadata.supportsLinks) { - expectSyncError(fs.linkSync, fn, 'foo'); - } } - if (fs.getMount('/').metadata.supportsLinks) { - expectSyncError(fs.lstatSync, fn); - expectSyncError(fs.readlinkSync, fn); - } + expectSyncError(fs.lstatSync, fn); + expectSyncError(fs.readlinkSync, fn); }); } }); diff --git a/test/tests/null-bytes.test.ts b/test/tests/null-bytes.test.ts index ef12b6123..49c3e8e1c 100644 --- a/test/tests/null-bytes.test.ts +++ b/test/tests/null-bytes.test.ts @@ -37,14 +37,11 @@ describe.each(backends)('%s fs path validation', (name, options) => { check(fs.promises.truncate, fs.truncateSync, 'foo\u0000bar'); check(fs.promises.unlink, fs.unlinkSync, 'foo\u0000bar'); check(fs.promises.writeFile, fs.writeFileSync, 'foo\u0000bar'); - - if (fs.getMount('/').metadata.supportsLinks) { - check(fs.promises.link, fs.linkSync, 'foo\u0000bar', 'foobar'); - check(fs.promises.link, fs.linkSync, 'foobar', 'foo\u0000bar'); - check(fs.promises.readlink, fs.readlinkSync, 'foo\u0000bar'); - check(fs.promises.symlink, fs.symlinkSync, 'foo\u0000bar', 'foobar'); - check(fs.promises.symlink, fs.symlinkSync, 'foobar', 'foo\u0000bar'); - } + check(fs.promises.link, fs.linkSync, 'foo\u0000bar', 'foobar'); + check(fs.promises.link, fs.linkSync, 'foobar', 'foo\u0000bar'); + check(fs.promises.readlink, fs.readlinkSync, 'foo\u0000bar'); + check(fs.promises.symlink, fs.symlinkSync, 'foo\u0000bar', 'foobar'); + check(fs.promises.symlink, fs.symlinkSync, 'foobar', 'foo\u0000bar'); if (fs.getMount('/').metadata.supportsProperties) { check(fs.promises.chmod, fs.chmodSync, 'foo\u0000bar', '0644'); diff --git a/test/tests/symlink.test.ts b/test/tests/symlink.test.ts index e536caf11..7515e4572 100644 --- a/test/tests/symlink.test.ts +++ b/test/tests/symlink.test.ts @@ -1,59 +1,48 @@ -import { backends, fs, configure, tmpDir, fixturesDir } from '../common'; +import { backends, fs, fixturesDir } from '../common'; import * as path from 'path'; describe.each(backends)('%s Link and Symlink Test', (name, options) => { - const configured = configure(options); it('should create and read symbolic link', async () => { - await configured; - if (fs.getMount('/').metadata.supportsLinks) { - const linkData = path.join(fixturesDir, '/cycles/root.js'); - const linkPath = path.join(tmpDir, 'symlink1.js'); + const linkData = path.join(fixturesDir, '/cycles/root.js'); + const linkPath = 'symlink1.js'; - // Delete previously created link - try { - await fs.promises.unlink(linkPath); - } catch (e) {} + // Delete previously created link + try { + await fs.promises.unlink(linkPath); + } catch (e) {} - await fs.promises.symlink(linkData, linkPath); - console.log('symlink done'); + await fs.promises.symlink(linkData, linkPath); + console.log('symlink done'); - const destination = await fs.promises.readlink(linkPath); - expect(destination).toBe(linkData); - } + const destination = await fs.promises.readlink(linkPath); + expect(destination).toBe(linkData); }); it('should create and read hard link', async () => { - await configured; - if (fs.getMount('/').metadata.supportsLinks) { - const srcPath = path.join(fixturesDir, 'cycles', 'root.js'); - const dstPath = path.join(tmpDir, 'link1.js'); - - // Delete previously created link - try { - await fs.promises.unlink(dstPath); - } catch (e) {} - - await fs.promises.link(srcPath, dstPath); - console.log('hard link done'); - - const srcContent = await fs.promises.readFile(srcPath, 'utf8'); - const dstContent = await fs.promises.readFile(dstPath, 'utf8'); - expect(srcContent).toBe(dstContent); - } + const srcPath = path.join(fixturesDir, 'cycles', 'root.js'); + const dstPath = 'link1.js'; + + // Delete previously created link + try { + await fs.promises.unlink(dstPath); + } catch (e) {} + + await fs.promises.link(srcPath, dstPath); + console.log('hard link done'); + + const srcContent = await fs.promises.readFile(srcPath, 'utf8'); + const dstContent = await fs.promises.readFile(dstPath, 'utf8'); + expect(srcContent).toBe(dstContent); }); }); describe.each(backends)('%s Symbolic Link Test', (name, options) => { - const configured = configure(options); - // test creating and reading symbolic link const linkData = path.join(fixturesDir, 'cycles/'); - const linkPath = path.join(tmpDir, 'cycles_link'); + const linkPath = 'cycles_link'; beforeAll(async () => { - await configured; - // Delete previously created link await fs.promises.unlink(linkPath); @@ -65,8 +54,7 @@ describe.each(backends)('%s Symbolic Link Test', (name, options) => { }); it('should lstat symbolic link', async () => { - await configured; - if (fs.getMount('/').metadata.readonly || !fs.getMount('/').metadata.supportsLinks) { + if (fs.getMount('/').metadata.readonly) { return; } @@ -75,8 +63,7 @@ describe.each(backends)('%s Symbolic Link Test', (name, options) => { }); it('should readlink symbolic link', async () => { - await configured; - if (fs.getMount('/').metadata.readonly || !fs.getMount('/').metadata.supportsLinks) { + if (fs.getMount('/').metadata.readonly) { return; } const destination = await fs.promises.readlink(linkPath); @@ -84,8 +71,7 @@ describe.each(backends)('%s Symbolic Link Test', (name, options) => { }); it('should unlink symbolic link', async () => { - await configured; - if (fs.getMount('/').metadata.readonly || !fs.getMount('/').metadata.supportsLinks) { + if (fs.getMount('/').metadata.readonly) { return; } await fs.promises.unlink(linkPath);