fix: can't create collection on empty directory (#3256)

This commit is contained in:
Sai K K 2024-10-28 02:28:11 +05:30 committed by GitHub
parent 4ea141fd73
commit 9aa84a259c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -65,14 +65,20 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
try { try {
const dirPath = path.join(collectionLocation, collectionFolderName); const dirPath = path.join(collectionLocation, collectionFolderName);
if (fs.existsSync(dirPath)) { 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)) { if (!isValidPathname(dirPath)) {
throw new Error(`collection: invalid pathname - ${dir}`); throw new Error(`collection: invalid pathname - ${dir}`);
} }
await createDirectory(dirPath); if (!fs.existsSync(dirPath)) {
await createDirectory(dirPath);
}
const uid = generateUidBasedOnHash(dirPath); const uid = generateUidBasedOnHash(dirPath);
const brunoConfig = { const brunoConfig = {