Skip to content

Commit

Permalink
File upload exercises: Fix an issue with old file submissions not bei…
Browse files Browse the repository at this point in the history
…ng deleted (#7276)
  • Loading branch information
theblobinthesky authored Oct 3, 2023
1 parent 43ee4a5 commit 6346cfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tum.in.www1.artemis.domain;

import java.net.URI;
import java.nio.file.Path;

import javax.persistence.*;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/de/tum/in/www1/artemis/service/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,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) {
Expand Down

0 comments on commit 6346cfc

Please sign in to comment.