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

Development: Delete old files properly when updating file submissions #6849

Merged
merged 26 commits into from
Jul 26, 2023
Merged
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aeb93a0
attachment unit get
julian-christl Jun 28, 2023
d371dfd
file upload submission
julian-christl Jun 28, 2023
d46e890
file service
julian-christl Jun 28, 2023
d1118a5
template files
julian-christl Jun 28, 2023
2a71767
remove redundant method
julian-christl Jun 28, 2023
8a25e38
repository service
julian-christl Jun 28, 2023
790d9af
revert start import
julian-christl Jun 28, 2023
a5ae563
fix online editor
julian-christl Jun 28, 2023
cb6d88d
fixx file upload
julian-christl Jun 28, 2023
627147c
fix file resource
julian-christl Jun 28, 2023
a545811
revert accidental changes
julian-christl Jun 28, 2023
da95b4a
fis file response
julian-christl Jun 28, 2023
0fe692e
Update src/main/java/de/tum/in/www1/artemis/service/FileService.java
julian-christl Jun 29, 2023
7eb8196
Make Markus happy
julian-christl Jun 30, 2023
e9e2a6a
rework repo service
julian-christl Jun 30, 2023
b891eb4
fix tests
julian-christl Jun 30, 2023
8b0290f
fix renaminng
julian-christl Jun 30, 2023
e1aef59
fix renaming with collapsed packages
julian-christl Jun 30, 2023
f1ea5af
Utilise the participation parameter for getting the lastSubmission in…
Jul 7, 2023
b6fa1b2
Merge branch 'develop' into chore/utiliseStudentParticipation
Jul 9, 2023
704e937
Merge branch 'develop' into chore/utiliseStudentParticipation
Jul 13, 2023
80022be
Refactored FileUploadSubmissionService.storeFile(FileUploadSubmission…
Jul 16, 2023
1f9d740
Merge branch 'develop' into chore/utiliseStudentParticipation
Jul 17, 2023
48c9ab2
Rename evict method, fix spotless
julian-christl Jul 21, 2023
12b1458
Merge branch 'develop' into chore/utiliseStudentParticipation
julian-christl Jul 21, 2023
f27dabd
Rename the method 2.0
julian-christl Jul 21, 2023
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
Expand Up @@ -115,7 +115,7 @@ public Optional<FileUploadSubmission> getRandomFileUploadSubmissionEligibleForNe
public FileUploadSubmission save(FileUploadSubmission fileUploadSubmission, MultipartFile file, StudentParticipation participation, FileUploadExercise exercise)
throws IOException, EmptyFileException {

String newFilePath = storeFile(fileUploadSubmission, file, exercise);
String newFilePath = storeFile(fileUploadSubmission, participation, file, exercise);

// update submission properties
fileUploadSubmission.setSubmissionDate(ZonedDateTime.now());
Expand All @@ -139,13 +139,12 @@ public FileUploadSubmission save(FileUploadSubmission fileUploadSubmission, Mult
return fileUploadSubmission;
}

private String storeFile(FileUploadSubmission fileUploadSubmission, MultipartFile file, FileUploadExercise exercise) throws EmptyFileException, IOException {
private String storeFile(FileUploadSubmission fileUploadSubmission, StudentParticipation participation, MultipartFile file, FileUploadExercise exercise)
throws EmptyFileException, IOException {
if (file.isEmpty()) {
throw new EmptyFileException(file.getOriginalFilename());
}

final var oldFilePath = fileUploadSubmission.getFilePath();

final var multipartFileHash = DigestUtils.md5Hex(file.getInputStream());
// We need to set id for newly created submissions
if (fileUploadSubmission.getId() == null) {
Expand All @@ -161,11 +160,13 @@ private String storeFile(FileUploadSubmission fileUploadSubmission, MultipartFil
}

// Note: we can only delete the file, if the file name was changed (i.e. the new file name is different), otherwise this will cause issues
if (oldFilePath != null) {
Optional<FileUploadSubmission> lastSubmission = participation.findLatestSubmission();
if (lastSubmission.isPresent() && lastSubmission.get().getFilePath() != null) {
FileUploadSubmission submission = lastSubmission.get();
// check if we already had a file associated with this submission
if (!oldFilePath.equals(newFilePath)) { // different name
if (!submission.getFilePath().equals(newFilePath)) { // different name
// IMPORTANT: only delete the file when it has changed the name
fileUploadSubmission.onDelete();
submission.onDelete();
}
else { // same name
// IMPORTANT: invalidate the cache so that the new file with the same name will be downloaded (and not a potentially cached one)
Expand Down
Loading