update deleteFolder api

This commit is contained in:
Abhinav 2023-05-05 12:34:04 +05:30
parent c6183f8134
commit 241cbc7c3e

View file

@ -250,7 +250,6 @@ export async function moveFile(
throw new Error('File does not exist'); throw new Error('File does not exist');
} }
if (existsSync(destinationPath)) { if (existsSync(destinationPath)) {
// TODO: should we overwrite or ignore as no-op or throw error?
throw new Error('Destination file already exists'); throw new Error('Destination file already exists');
} }
// check if destination folder exists // check if destination folder exists
@ -265,5 +264,10 @@ export async function deleteFolder(folderPath: string): Promise<void> {
if (!existsSync(folderPath)) { if (!existsSync(folderPath)) {
return; return;
} }
fs.rmSync(folderPath, { force: true, recursive: true }); // check if folder is empty
const files = await fs.readdir(folderPath);
if (files.length > 0) {
throw new Error('Folder is not empty');
}
await fs.rmdir(folderPath);
} }