Skip to content

Commit

Permalink
Add file store name to the FileSystemProps interface (#4886)
Browse files Browse the repository at this point in the history
The file store name is part of the `java.nio.file.FileStore` object which is used to build the
`io.vertx.core.file.impl.FileSystemPropsImpl` object. However, the name is not defined as part
of the `io.vertx.core.file.FileSystemProps` interface.

This piece of information is important including when logging information about the
`io.vertx.core.file.FileSystemProps` concrete object when consuming it through
`vertx.fileSystem().fsProps()` calls.
  • Loading branch information
frankgh authored Oct 9, 2023
1 parent ccb1e62 commit c46f74b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/java/io/vertx/core/file/FileSystemProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
@VertxGen
public interface FileSystemProps {

/**
* @return The name of this file store
*/
String name();

/**
* @return The total space on the file system, in bytes
*/
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/io/vertx/core/file/impl/FileSystemImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
package io.vertx.core.file.impl;

import io.vertx.codegen.annotations.Nullable;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.file.AsyncFile;
import io.vertx.core.file.CopyOptions;
Expand Down Expand Up @@ -959,7 +956,7 @@ public FileSystemProps perform() {
try {
Path target = vertx.resolveFile(path).toPath();
FileStore fs = Files.getFileStore(target);
return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace());
return new FileSystemPropsImpl(fs.name(), fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace());
} catch (IOException e) {
throw new FileSystemException(getFileAccessErrorMessage("analyse", path), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@

public class FileSystemPropsImpl implements FileSystemProps {

private final String name;
private final long totalSpace;
private final long unallocatedSpace;
private final long usableSpace;

public FileSystemPropsImpl(long totalSpace, long unallocatedSpace, long usableSpace) {
public FileSystemPropsImpl(String name, long totalSpace, long unallocatedSpace, long usableSpace) {
this.name = name;
this.totalSpace = totalSpace;
this.unallocatedSpace = unallocatedSpace;
this.usableSpace = usableSpace;
}

@Override
public String name() {
return name;
}

@Override
public long totalSpace() {
return totalSpace;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/io/vertx/core/file/FileSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ public void testFSProps() throws Exception {
String fileName = "some-file.txt";
createFileWithJunk(fileName, 1234);
testFSProps(fileName, props -> {
assertNotNull(props.name());
assertTrue(props.totalSpace() > 0);
assertTrue(props.unallocatedSpace() > 0);
assertTrue(props.usableSpace() > 0);
Expand Down

0 comments on commit c46f74b

Please sign in to comment.