Skip to content
Merged
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
24 changes: 0 additions & 24 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,3 @@ export async function writeSecureFile<T extends PathLike>(
await fs.writeFile(outputPath, data, opts);
return outputPath;
}

/**
* removeFile removes the file at the given path. If the file does not exist, it
* does nothing.
*
* @param filePath Path of the file on disk to delete.
*
* @returns A boolean, true if the file was deleted, false otherwise.
*
* @deprecated Use #forceRemove instead.
*/
export async function removeFile(filePath: PathLike): Promise<boolean> {
try {
await fs.unlink(filePath);
return true;
} catch (err) {
if (isNotFoundError(err)) {
return false;
}

const msg = errorMessage(err);
throw new Error(`Failed to remove "${filePath}": ${msg}`);
}
}
21 changes: 1 addition & 20 deletions tests/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { promises as fs } from 'fs';
import { constants as fsconstants } from 'fs';
import { randomFilepath } from '../src/random';

import { isEmptyDir, forceRemove, removeFile, writeSecureFile } from '../src/fs';
import { isEmptyDir, forceRemove, writeSecureFile } from '../src/fs';

describe('fs', { concurrency: true }, async () => {
test('#forceRemove', async (suite) => {
Expand Down Expand Up @@ -74,25 +74,6 @@ describe('fs', { concurrency: true }, async () => {
}
});

test('#removeFile', async (suite) => {
await suite.test('deletes the file', async () => {
const filepath = randomFilepath();
await fs.writeFile(filepath, 'my data');
const deleted = await removeFile(filepath);
assert.deepStrictEqual(deleted, true);

await assert.rejects(async () => {
await fs.access(filepath, fsconstants.F_OK);
}, /ENOENT/);
});

await suite.test('does nothing when the file does not exist', async () => {
const filepath = '/not/a/file';
const deleted = await removeFile(filepath);
assert.deepStrictEqual(deleted, false);
});
});

test('#writeSecureFile', async (suite) => {
await suite.test('writes a file', async () => {
const filepath = randomFilepath();
Expand Down
Loading