diff --git a/src/main/java/org/qortal/arbitrary/patch/UnifiedDiffPatch.java b/src/main/java/org/qortal/arbitrary/patch/UnifiedDiffPatch.java index d35d9f4a..2a6ad89b 100644 --- a/src/main/java/org/qortal/arbitrary/patch/UnifiedDiffPatch.java +++ b/src/main/java/org/qortal/arbitrary/patch/UnifiedDiffPatch.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger; import org.qortal.crypto.Crypto; import org.qortal.repository.DataException; import org.qortal.settings.Settings; +import org.qortal.utils.FilesystemUtils; import java.io.BufferedWriter; import java.io.File; @@ -72,6 +73,9 @@ public class UnifiedDiffPatch { List original = FileUtils.readLines(before.toFile(), StandardCharsets.UTF_8); List revised = FileUtils.readLines(after.toFile(), StandardCharsets.UTF_8); + // Check if the original file ends with a newline + boolean endsWithNewline = FilesystemUtils.fileEndsWithNewline(before); + // Generate diff information Patch diff = DiffUtils.diff(original, revised); @@ -83,9 +87,13 @@ public class UnifiedDiffPatch { // Write the diff to the destination directory FileWriter fileWriter = new FileWriter(destination.toString(), true); BufferedWriter writer = new BufferedWriter(fileWriter); - for (String line : unifiedDiff) { + for (int i=0; i originalContents = FileUtils.readLines(originalPath.toFile(), StandardCharsets.UTF_8); List patchContents = FileUtils.readLines(patchPath.toFile(), StandardCharsets.UTF_8); + // Check if the patch file (and therefore the original file) ends with a newline + boolean endsWithNewline = FilesystemUtils.fileEndsWithNewline(patchPath); + // At first, parse the unified diff file and get the patch Patch patch = UnifiedDiffUtils.parseUnifiedDiff(patchContents); @@ -183,9 +194,15 @@ public class UnifiedDiffPatch { // Write the patched file to the merge directory FileWriter fileWriter = new FileWriter(mergePath.toString(), true); BufferedWriter writer = new BufferedWriter(fileWriter); - for (String line : patchedContents) { + for (int i=0; i