Skip to content

Commit

Permalink
Merge pull request #32 from Tyderion/more-file-checks-on-move
Browse files Browse the repository at this point in the history
Add more checks if file exists before deleting
  • Loading branch information
Tyderion authored Aug 11, 2024
2 parents 5598ed4 + 629558d commit e87532c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "ch.tyderion"
version = "4.0.2"
version = "4.0.3"

java {
targetCompatibility = JavaVersion.VERSION_21
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/processing/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public boolean renameFile(@NotNull Path from, @NotNull Path to) {
log.fine(STR."Copying file from \{from.toAbsolutePath()} to \{to.toAbsolutePath()}");
try {
Files.copy(from, to, StandardCopyOption.COPY_ATTRIBUTES);
Files.delete(from);
// Even though Files.copy should throw an exception if it fails, we still check if the file was copied correctly
if (Files.exists(to) && Files.size(to) == Files.size(from)) {
log.fine(STR."Successfully copied file from \{from.toAbsolutePath()} to \{to.toAbsolutePath()}. Deleting original file.");
Files.delete(from);
}
return true;
} catch (IOException e) {
log.severe(STR."Could not move file from \{from.toAbsolutePath()} to \{to.toAbsolutePath()}: \{e.getMessage()}.");
Expand Down

0 comments on commit e87532c

Please sign in to comment.