Skip to content

Preserve download destination until decryption and decompression succeed - #56

Merged
uwemaurer merged 2 commits into
ebics-java:masterfrom
CooperBigFoot:fix/preserve-download-destination
Nov 15, 2026
Merged

uwemaurer merged 2 commits into
ebics-java:masterfrom
CooperBigFoot:fix/preserve-download-destination

Conversation

@CooperBigFoot

@CooperBigFoot CooperBigFoot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

FileTransfer.fetchFile now writes decoded downloads to a sibling temporary file, then atomically replaces the destination after the stream closes.

  • Preserve the destination on decoding, write, close, or move failure and clean up the temporary file before sending any receipt.
  • Require Files.move(..., REPLACE_EXISTING, ATOMIC_MOVE) with no non-atomic fallback.
  • Write directly from Joiner without another in-memory payload buffer; keep public signatures and EBICS messages unchanged.
  • Cover decoding failures, partial writes, close failures, unsupported atomic moves, successful replacement, temporary-file cleanup, and bare relative filenames.

Validation: Java 17, ./mvnw -Dtest=FileTransferTest test (8 tests) and ./mvnw verify (49 tests). The new atomic-move regression fails before this revision and passes after it.

Prepared with AI assistance, with human review before publication. I have six months of top-tier Google model access for research and am investing that opportunity in verified open-source contributions. Related to #54.

@uwemaurer

Copy link
Copy Markdown
Collaborator

Thank you for your help. I think it would be better to write to a temp file in the same directory and then use Files.move(..., REPLACE_EXISTING, ATOMIC_MOVE) to rename to the destination file. This has two advantages: It protects against the case where the disk is full and the file is only partially written. Also Joiner has an internal copy of the data already so we don't need an extra one if we writeTo a temp file.

@CooperBigFoot

Copy link
Copy Markdown
Contributor Author

Thanks @uwemaurer — updated to write directly from Joiner into a sibling temporary file, close the stream, then replace the destination with Files.move(..., REPLACE_EXISTING, ATOMIC_MOVE). There is no non-atomic fallback. Failures clean up the temporary file before any receipt is sent, preserving the original error if cleanup also fails.

Files.createTempFile creates 0600 files on Unix, so replacement uses those permissions rather than retaining the destination’s previous permissions.

Java 17: all 8 focused tests and the full 49-test ./mvnw verify build pass, including partial-write, close, atomic-move failure, cleanup, and relative-path coverage.

@uwemaurer
uwemaurer merged commit af9e148 into ebics-java:master Nov 15, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants