google/jimfs

FileStore.getBlockSize() should return the configuration block size

ogregoire opened this issue · 1 comments

The following test case fails for some reason.

  @Test
  void test() throws IOException {
    var blockSize = 1 << 12;
    var configuration = Configuration.unix().toBuilder().setBlockSize(blockSize).build();
    var fs = Jimfs.newFileSystem(configuration);
    var path = fs.getPath("/home/test/test.txt");
    var store = Files.getFileStore(path);
    assertThat(store.getBlockSize()).isEqualTo(blockSize);
  }

I'm explicitly setting the block size, but I get an IOException when the test case is run:

java.lang.UnsupportedOperationException
        at java.base/java.nio.file.FileStore.getBlockSize(FileStore.java:158)
        ...

I would expect the store to return the block size instead.

I noticed that the method is new since Java 10. So I guess that a multi-release JAR must be created.

I worked a bit on it and found that it's possible to create such multi-release jar with the following changes:

  • Copy JimfsFileStore.java to jimfs/src/main/java10/com/google/common/jimfs/.
  • Add the following method at the end of the class:
      @Override
      public long getBlockSize() throws IOException {
        return disk.blockSize();
      }
    
  • Add the following configuration to jimfs/pom.xml:
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
              <execution>
                <id>compile-java-7</id>
                <goals>
                  <goal>compile</goal>
                </goals>
                <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
                </configuration>
              </execution>
              <execution>
                <id>compile-java-10</id>
                <phase>compile</phase>
                <goals>
                  <goal>compile</goal>
                </goals>
                <configuration>
                  <release>10</release>
                  <compileSourceRoots>
                    <compileSourceRoot>${project.basedir}/src/main/java10</compileSourceRoot>
                  </compileSourceRoots>
                  <multiReleaseOutput>true</multiReleaseOutput>
                </configuration>
              </execution>
            </executions>
          </plugin>
    
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
              <archive>
                <manifestEntries>
                  <Multi-Release>true</Multi-Release>
                </manifestEntries>
              </archive>
            </configuration>
          </plugin>
    

My only issue was with the tests, hence why I didn't provide a full-blown PR: I don't know how to make tests for a Multi-release project.