From 9aa84a259c2ff6f57d5704cceaeb711d9be6aac4 Mon Sep 17 00:00:00 2001 From: Sai K K Date: Mon, 28 Oct 2024 02:28:11 +0530 Subject: [PATCH] fix: can't create collection on empty directory (#3256) --- packages/bruno-electron/src/ipc/collection.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 0421060dd..30a891015 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -65,14 +65,20 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection try { const dirPath = path.join(collectionLocation, collectionFolderName); if (fs.existsSync(dirPath)) { - throw new Error(`collection: ${dirPath} already exists`); + const files = fs.readdirSync(dirPath); + + if (files.length > 0) { + throw new Error(`collection: ${dirPath} already exists and is not empty`); + } } if (!isValidPathname(dirPath)) { throw new Error(`collection: invalid pathname - ${dir}`); } - await createDirectory(dirPath); + if (!fs.existsSync(dirPath)) { + await createDirectory(dirPath); + } const uid = generateUidBasedOnHash(dirPath); const brunoConfig = {