cryptomator / cryptofs

Java Filesystem Provider with integrated encryption
GNU Affero General Public License v3.0
93 stars 35 forks source link

should opening a second channel with `TRUNCATE_EXISTING` use a new file header? #160

Closed overheadhunter closed 1 year ago

overheadhunter commented 1 year ago

On CI (not reproducible on all setups, though) testTruncateExistingWhileStillOpen fails.

Due to TRUNCATE_EXISTING flag being passed through to the ciphertext file channel, the ciphertext file size is reset to zero as soon as the method is invoked, which causes a new header to be created:

https://github.com/cryptomator/cryptofs/blob/e1704e8b11f6471cc847f0c854ee41dfaaa2db2c/src/main/java/org/cryptomator/cryptofs/fh/OpenCryptoFile.java#L68-L87

I'm currently unsure, if this is desirable behaviour (and the test is broken) or the existing header should really be kept.

overheadhunter commented 1 year ago

As already specified in #48: Yes TRUNCATE_EXISTING should generate a new header. However FileHeaderHolder will only generate a header once due to this atomic CAS operation:

https://github.com/cryptomator/cryptofs/blob/e1704e8b11f6471cc847f0c854ee41dfaaa2db2c/src/main/java/org/cryptomator/cryptofs/fh/FileHeaderHolder.java#L39-L47