From 3f38127361dae6258b965e5490fad6e1be4b6573 Mon Sep 17 00:00:00 2001 From: Simon Entholzer <33342534+SimonEntholzer@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:45:19 +0100 Subject: [PATCH] Programming exercises: Only replace existing files when populating build plan repositories (#9968) --- .../buildagent/service/BuildJobContainerService.java | 11 +++-------- src/main/webapp/i18n/de/programmingExercise.json | 2 +- src/main/webapp/i18n/en/programmingExercise.json | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobContainerService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobContainerService.java index 3c7ff12881cd..f4d1eae004e5 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobContainerService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobContainerService.java @@ -342,16 +342,11 @@ private void createScriptFile(String buildJobContainerId) { private void addAndPrepareDirectoryAndReplaceContent(String containerId, Path repositoryPath, String newDirectoryName) { copyToContainer(repositoryPath.toString(), containerId); addDirectory(containerId, newDirectoryName, true); - removeDirectoryAndFiles(containerId, newDirectoryName); - renameDirectoryOrFile(containerId, LOCALCI_WORKING_DIRECTORY + "/" + repositoryPath.getFileName().toString(), newDirectoryName); + insertRepositoryFiles(containerId, LOCALCI_WORKING_DIRECTORY + "/" + repositoryPath.getFileName().toString(), newDirectoryName); } - private void removeDirectoryAndFiles(String containerId, String newName) { - executeDockerCommand(containerId, null, false, false, true, "rm", "-rf", newName); - } - - private void renameDirectoryOrFile(String containerId, String oldName, String newName) { - executeDockerCommand(containerId, null, false, false, true, "mv", oldName, newName); + private void insertRepositoryFiles(String containerId, String oldName, String newName) { + executeDockerCommand(containerId, null, false, false, true, "cp", "-r", oldName + (oldName.endsWith("/") ? "." : "/."), newName); } private void addDirectory(String containerId, String directoryName, boolean createParentsIfNecessary) { diff --git a/src/main/webapp/i18n/de/programmingExercise.json b/src/main/webapp/i18n/de/programmingExercise.json index 109036a5f9d6..850fc2330e0d 100644 --- a/src/main/webapp/i18n/de/programmingExercise.json +++ b/src/main/webapp/i18n/de/programmingExercise.json @@ -578,7 +578,7 @@ "auxiliaryRepository": { "error": "Es gibt ein Problem mit den Hilfs-Repositories!", "addAuxiliaryRepository": "Hilfs-Repository anlegen", - "usageDescription": "Du kannst Hilfsrepositorien verwenden, um zusätzlichen Code bereitzustellen, den die Studierenden nicht sehen oder ändern können. Der zusätzliche Code wird im angegebenen Checkout-Verzeichnis eingefügt, bevor der Build erstellt wird. Der eingefügte Code überschreibt alles, was sich an der durch das Checkout-Verzeichnis angegebenen Stelle befindet. Wenn du die Dateien der Studierenden nur teilweise überschreiben willst, muss das Build-Skript angepasst werden.", + "usageDescription": "Du kannst Hilfsrepositorien verwenden, um zusätzlichen Code bereitzustellen, den die Studierenden nicht sehen oder ändern können. Der zusätzliche Code wird im angegebenen Checkout-Verzeichnis eingefügt, bevor der Build erstellt wird. Die eingefügten Dateien überschreiben alle Dateien im Checkout-Verzeichnis, die den gleichen Namen haben. Dateien, die nicht überschrieben werden, bleiben erhalten.", "repositoryName": "Name des Repositorys", "checkoutDirectory": "Checkout-Verzeichnis", "description": "Beschreibung", diff --git a/src/main/webapp/i18n/en/programmingExercise.json b/src/main/webapp/i18n/en/programmingExercise.json index 4835223da235..182a28afc520 100644 --- a/src/main/webapp/i18n/en/programmingExercise.json +++ b/src/main/webapp/i18n/en/programmingExercise.json @@ -578,7 +578,7 @@ "auxiliaryRepository": { "error": "There is a problem with the auxiliary repository.", "addAuxiliaryRepository": "Add Auxiliary Repository", - "usageDescription": "You can use auxiliary repositories to provide additional code that students cannot see or modify. The additional code is inserted into the specified checkout directory before the submission is built. The inserted code overwrites everything which lies at the location specified by the checkout directory. If you only need to overwrite student files partially, you need to adapt the build script.", + "usageDescription": "You can use auxiliary repositories to provide additional code that students cannot see or modify. The additional code is inserted into the specified checkout directory before the submission is built. The additional code is inserted in the specified checkout directory before the build is created. The inserted files overwrite all files in the checkout directory which have the same name. Files that are not overwritten are retained.", "repositoryName": "Repository Name", "checkoutDirectory": "Checkout Directory", "description": "Description",