Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload exercises: Fix an issue with old file submissions not being deleted #7276

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down