diff --git a/src/main/java/de/tum/in/www1/artemis/domain/FileUploadSubmission.java b/src/main/java/de/tum/in/www1/artemis/domain/FileUploadSubmission.java index 29bafff4bcb4..66f24f5ec12e 100644 --- a/src/main/java/de/tum/in/www1/artemis/domain/FileUploadSubmission.java +++ b/src/main/java/de/tum/in/www1/artemis/domain/FileUploadSubmission.java @@ -1,5 +1,6 @@ package de.tum.in.www1.artemis.domain; +import java.net.URI; import java.nio.file.Path; import javax.persistence.*; @@ -34,7 +35,8 @@ public String getSubmissionExerciseType() { @PostRemove public void onDelete() { if (filePath != null) { - fileService.schedulePathForDeletion(Path.of(filePath), 0); + Path actualPath = FilePathService.actualPathForPublicPath(URI.create(filePath)); + fileService.schedulePathForDeletion(actualPath, 0); } } diff --git a/src/main/java/de/tum/in/www1/artemis/service/FilePathService.java b/src/main/java/de/tum/in/www1/artemis/service/FilePathService.java index 8281338bb1ee..191c8f9037ba 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/FilePathService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/FilePathService.java @@ -90,7 +90,7 @@ public Path actualPathForPublicPathOrThrow(URI publicPath) { * @param publicPath the public file url to convert * @return the actual path to that file in the local filesystem */ - public Path actualPathForPublicPath(URI publicPath) { + public static Path actualPathForPublicPath(URI publicPath) { // first extract the filename from the url String uriPath = publicPath.getPath(); Path path = Path.of(uriPath); @@ -129,7 +129,7 @@ public Path actualPathForPublicPath(URI publicPath) { return null; } - private Path actualPathForPublicAttachmentUnitFilePath(URI publicPath, String filename) { + private static Path actualPathForPublicAttachmentUnitFilePath(URI publicPath, String filename) { Path path = Path.of(publicPath.getPath()); if (!publicPath.toString().contains("/slide")) { String attachmentUnitId = path.getName(4).toString(); @@ -148,7 +148,7 @@ private Path actualPathForPublicAttachmentUnitFilePath(URI publicPath, String fi } } - private Path actualPathForPublicFileUploadExercisesFilePath(URI publicPath, String filename) { + private static Path actualPathForPublicFileUploadExercisesFilePath(URI publicPath, String filename) { Path path = Path.of(publicPath.getPath()); try { String expectedExerciseId = path.getName(3).toString(); diff --git a/src/main/java/de/tum/in/www1/artemis/service/FileService.java b/src/main/java/de/tum/in/www1/artemis/service/FileService.java index ac239e2b645d..d9208a6f57ee 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/FileService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/FileService.java @@ -768,6 +768,10 @@ public void schedulePathForDeletion(@Nullable Path path, long delayInMinutes) { log.info("Delete file {}", path); Files.delete(path); } + else { + log.error("Deleting the file {} did not work because it does not exist", path); + } + futures.remove(path); } catch (IOException e) {