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
32 changes: 28 additions & 4 deletions src/main/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,25 @@ export default class ProjectsService {

const projects = await this.loadProjects();

// Check if project is already imported (by path)
if (projects.find((p) => p.path === projectPath)) {
throw new Error('This project is already imported.');
const resolvedProjectPath = (() => {
try {
return fs.realpathSync(projectPath);
} catch {
return projectPath;
}
})();
const alreadyImported = projects.find((p) => {
if (!p.path || !fs.existsSync(p.path)) return false;
try {
return fs.realpathSync(p.path) === resolvedProjectPath;
} catch {
return p.path === projectPath;
}
});
if (alreadyImported) {
throw new Error(
`This project is already imported as "${alreadyImported.name}". Remove it from Studio first before re-importing.`,
);
}

// Check if project name already exists and make it unique if needed
Expand Down Expand Up @@ -696,7 +712,15 @@ export default class ProjectsService {
if (!projectToDelete) return false;

if (projectToDelete.path) {
deleteDirectory(projectToDelete.path);
try {
deleteDirectory(projectToDelete.path);
} catch (error) {
// eslint-disable-next-line no-console
console.error(
'[ProjectsService] Failed to delete project directory:',
error,
);
}
}

// Both the list and the (possibly now-dangling) selection move together
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/screens/selectProject/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,10 @@ const SelectProject: React.FC = () => {
toast.error(
'Invalid dbt project structure. Please ensure the folder contains a valid dbt_project.yml file.',
);
} else if (error.message.includes('already exists')) {
} else if (
error.message.includes('already exists') ||
error.message.includes('already imported')
) {
toast.error(error.message);
} else {
toast.error(
Expand Down
Loading