From 680df43ebc8f219515eae60703fdf61c4cc889f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <git@minelli.swiss>
Date: Tue, 25 Feb 2025 17:25:08 +0100
Subject: [PATCH] ExercisesRoutes => Rename exercise before moving it for
 prevent names conflict

---
 ExpressAPI/src/routes/ExerciseRoutes.ts | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ExpressAPI/src/routes/ExerciseRoutes.ts b/ExpressAPI/src/routes/ExerciseRoutes.ts
index 5137daa..022c916 100644
--- a/ExpressAPI/src/routes/ExerciseRoutes.ts
+++ b/ExpressAPI/src/routes/ExerciseRoutes.ts
@@ -24,6 +24,7 @@ import GlobalHelper                from '../helpers/GlobalHelper.js';
 import { IFileDirStat }            from '../shared/helpers/recursiveFilesStats/RecursiveFilesStats.js';
 import ExerciseManager             from '../managers/ExerciseManager.js';
 import * as Gitlab                 from '@gitbeaker/rest';
+import { ProjectSchema }           from '@gitbeaker/rest';
 import GitlabTreeFileType          from '../shared/types/Gitlab/GitlabTreeFileType.js';
 import { GitbeakerRequestError }   from '@gitbeaker/requester-utils';
 
@@ -110,7 +111,10 @@ class ExerciseRoutes implements RoutesManager {
             }
         }
 
-        await GitlabManager.moveRepository(repoId, Config.gitlab.group.deletedExercises);
+        // We rename (with unique str added) the repository before moving it because of potential name conflicts
+        const newName: string = `${ req.boundParams.exercise!.name }_${ uuidv4() }`;
+        await GitlabManager.renameRepository(repoId, newName);
+        const repository: ProjectSchema = await GitlabManager.moveRepository(repoId, Config.gitlab.group.deletedExercises);
 
         await db.exercise.update({
                                      where: { id: req.boundParams.exercise!.id },
-- 
GitLab