Zip file system provider only works with default file system

Philippe Marschall philippe.marschall at gmail.com
Sat Dec 8 05:41:28 PST 2012


On Sat, Dec 8, 2012 at 11:52 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 07/12/2012 23:05, Philippe Marschall wrote:
>>
>> Hi
>>
>> First, I hope I got the right mailing list. I'm in the process of
>> writing my own file system provider. As a test I wanted to create a
>> zip file on it using the zip file system provider. That's when I
>> discovered that it only works with the default file system.
>>
> Thanks for the bug report, It's possible that zip provider has been tested
> with other providers. Is your provider interposing on the system-default or
> is a distinct provider? I'm curious how you ran into this.

To give a bit more context my code looks something like this:

public class ZipFileSystemInteropabilityTest {

  @Rule
  public final FileSystemRule rule = new FileSystemRule();

  @Test
  public void createZipFileSystem() throws IOException {
    FileSystem memoryFileSystem = this.rule.getFileSystem();
    Map<String, String> env = Collections.singletonMap("create", "true");
    URI uri = URI.create("jar:" +
memoryFileSystem.getPath("/file.zip").toUri());
    try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
      try (BufferedWriter writer =
Files.newBufferedWriter(zipfs.getPath("hello.txt"),
StandardCharsets.US_ASCII, CREATE_NEW, WRITE)) {
        writer.write("world");
      }
    }
  }

}

where memoryFileSystem would be an instance of my custom memory file
system and the rule would be a JUnit rule that create a file system
before the test and removes it afterward.

The exception I get is:

java.io.IOException: Permission denied
	at java.io.UnixFileSystem.createFileExclusively(Native Method)
	at java.io.File.createTempFile(File.java:1879)
	at com.sun.nio.zipfs.ZipFileSystem.createTempFileInSameDirectoryAs(ZipFileSystem.java:1087)
	at com.sun.nio.zipfs.ZipFileSystem.sync(ZipFileSystem.java:1190)
	at com.sun.nio.zipfs.ZipFileSystem.close(ZipFileSystem.java:277)
	at com.acme.memoryfilesystem.ZipFileSystemInteropabilityTest.createZipFileSystem(ZipFileSystemInteropabilityTest.java:34)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at com.acme.memoryfilesystem.FileSystemRule$1.evaluate(FileSystemRule.java:28)
	at ..

The problem is that the zip file system provider tries to create a
temp file like /zipfstmp5062712090450520532.tmp in the default file
system instead of the file system it's running on. And on Unix you
generally don't have the permission to create files in the root.

Cheers
Philippe


More information about the nio-dev mailing list