Setting FILE_DISPOSITION_POSIX_SEMANTICS when deleting files on Windows (original) (raw)
Luke Hutchison luke.hutch at gmail.com
Mon May 6 23:57:29 UTC 2019
- Previous message: JEP proposed to target JDK 13: 350: Dynamic CDS Archives
- Next message: Call for feedback -- switch expressions in JDK 12
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Recent Windows 10 builds support POSIX-style file deletion semantics:
Setting this bit before deleting files using File::delete, Files::delete, Files::deleteIfExists etc. will work around the common problem on Windows where an attempt to delete an open file silently fails. This is a very common problem, experienced by developers when they forget to close not just any open OutputStream on a file before attempting to delete it, but also any open InputStream.
This problem is exacerbated by the fact that a file cannot be deleted if it is mmap'd, and a file cannot be safely forcibly unmapped until it is garbage collected:
https://bugs.openjdk.java.net/browse/JDK-4724038
Since file locking and deletion semantics are different on Windows than Linux and Mac OS X, and since the silent failure of file deletion when a file is open is almost always a source of surprise to developers coming from the Linux or Mac OS X world, the lack of default POSIX file deletion semantics on Windows presents a portability issue.
I propose the FILE_DISPOSITION_POSIX_SEMANTICS bit be set for all delete operations in the Windows build of Java, to unify file deletion semantics across operating systems.
- Previous message: JEP proposed to target JDK 13: 350: Dynamic CDS Archives
- Next message: Call for feedback -- switch expressions in JDK 12
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]