Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.nio.file.Files.isWriteable doesn't agree with java.io.File.canWrite()

I have Java code doing the following:

  1. Create a temporary empty file with ZIP extension using File.createTempFile()
  2. Delete it with File.delete() (we only really wanted it to generate a temp file name)
  3. Copy a "template" ZIP file to the same path with com.google.commons.io.ByteStreams.copy() using a new OutputSupplier given the same filename
  4. Modify the ZIP archive (remove a directory) using TrueZIP 7.4.3

On a specific system, step 4 fails consistently with FsReadOnlyArchiveFileSystemException - "This is a read-only archive file system!" (see http://java.net/projects/truezip/lists/users/archive/2011-05/message/9)

Debugging the TrueZIP code, I noticed the following:

  • There is no open file handle on this file between any of the steps above, and specifically not before step 4
  • Checking the same file with File.canWrite() rather than NIO returns at the exact same timing (using a debugger), it shows that it is writable

Here is what you see in the debugger expressions list:

fn => "C:/myworkdir/temp/myfile4088293380313057223tmp.zip"
java.nio.file.Files.isWritable(java.nio.file.Paths.get(fn)) => false
new java.io.File(fn).canWrite() => true

Using JDK 1.7.04

Any ideas?

like image 611
user1414274 Avatar asked Oct 02 '12 10:10

user1414274


1 Answers

There is a bug in java.nio.file.Files.isWritable under windows: it won't take implicit permissions into consideration. java bug #7190897

like image 73
xophos Avatar answered Sep 21 '22 10:09

xophos