Recent Java 9 commit (e5b66323ae45) breaks fsync on directory

Alan Bateman Alan.Bateman at oracle.com
Fri Jan 9 16:10:41 UTC 2015


On 09/01/2015 15:46, Uwe Schindler wrote:
> :
>
> We really would like to keep the possibility to fsync a directory on supported operating systems. We hope that the above commit will not be backported into 8u40 and 7u80 releases! In Java 9 we can discuss about other solutions how to handle this:
> - Keep current semantics as of Java 7 and Java 8 and just fail if you really want to READ/WRITE from this FileChannel? This is how the underlying operatinmg system and libc handles this. You can open a file descriptor on anything, file/directory/device/..., but not all operations work on this descriptor, some of them throw exception/return error.
> - Add a new API for fsyncing a directory (maybe for any file type). Like Files.fsync(Path)? On Windows this could just be a no-op for directories? Basically something like our IOUtils.fsync() from the link above.
>
> What's you opinion and how should we proceed?
>
This use-case may need a new API, one possibility is a new OpenOption 
(like NOFOLLOW_LINKS) for opening directories. This would allow opening 
a FileChannel to a directory and also provides somewhere to specify that 
many of the operations may fail. Implementation-wise it also means you 
should be able to open directories on Windows.

Sorry the original change broken what you are doing but I'm sure you 
understand that the unspecified behavior to allow directories be opened 
on some platforms and have subsequent attempts to do common operations 
(like read) fail wasn't ideal either. There are no plans to back-port 
this change.

-Alan


More information about the nio-dev mailing list