cryptomator / cryptofs

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

Setting lastModifiedDate while file is open fails on Windows #56

Closed overheadhunter closed 5 years ago

overheadhunter commented 5 years ago

If the underlying file system is a Windows-based file system, force() will set the last modification date to the date of the last byte written.

force() is called by close(), i.e. setting the last modified date in between of opening and closing a file will not have any effect, because force() overwrites any previous changes:

https://github.com/cryptomator/cryptofs/blob/2e57c6fd8bca5aeedcabd9cbc68bb594d7115acd/src/main/java/org/cryptomator/cryptofs/ch/CleartextFileChannel.java#L211-L213

try (FileChannel ch = FileChannel.open(file, CREATE_NEW, WRITE)) {
    Files.setLastModifiedTime(file, time); // set lastModifiedTime to time
} // during close: set lastModifiedTime to time at which last byte was written to ciphertext channel