Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileStore.getBlockSize() should return the configuration block size #183

Open
ogregoire opened this issue Feb 11, 2022 · 1 comment
Open
Labels
P4 type=defect Bug, not working as expected

Comments

@ogregoire
Copy link

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.

@nick-someone nick-someone added P4 type=defect Bug, not working as expected labels Feb 22, 2022
@ogregoire
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 type=defect Bug, not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants