Skip to content

Commit

Permalink
Merge branch 'feature/xattr' into release/4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Sep 30, 2023
2 parents a7a2443 + baaeae3 commit 5ce3f13
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public sealed class ReadOnlyAdapter implements FuseNioAdapter permits ReadWriteA
protected final Path root;
private final int maxFileNameLength;
protected final FileStore fileStore;
protected final boolean enableXattr;
protected final LockManager lockManager;
protected final OpenFileFactory openFiles;
protected final FileNameTranscoder fileNameTranscoder;
Expand All @@ -53,12 +54,13 @@ public sealed class ReadOnlyAdapter implements FuseNioAdapter permits ReadWriteA
private final ReadOnlyLinkHandler linkHandler;
private final BooleanSupplier hasOpenFiles;

protected ReadOnlyAdapter(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, FileStore fileStore, OpenFileFactory openFiles, ReadOnlyDirectoryHandler dirHandler, ReadOnlyFileHandler fileHandler) {
protected ReadOnlyAdapter(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, FileStore fileStore, OpenFileFactory openFiles, ReadOnlyDirectoryHandler dirHandler, ReadOnlyFileHandler fileHandler, boolean enableXattr) {
this.errno = errno;
this.root = root;
this.maxFileNameLength = maxFileNameLength;
this.fileNameTranscoder = fileNameTranscoder;
this.fileStore = fileStore;
this.enableXattr = enableXattr;
this.lockManager = new LockManager();
this.openFiles = openFiles;
this.dirHandler = dirHandler;
Expand All @@ -67,13 +69,13 @@ protected ReadOnlyAdapter(Errno errno, Path root, int maxFileNameLength, FileNam
this.hasOpenFiles = () -> openFiles.getOpenFileCount() != 0;
}

public static ReadOnlyAdapter create(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder) {
public static ReadOnlyAdapter create(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, boolean enableXattr) {
try {
var fileStore = Files.getFileStore(root);
var openFiles = new OpenFileFactory();
var dirHandler = new ReadOnlyDirectoryHandler(fileNameTranscoder);
var fileHandler = new ReadOnlyFileHandler(openFiles);
return new ReadOnlyAdapter(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler);
return new ReadOnlyAdapter(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler, enableXattr);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -86,6 +88,7 @@ public Errno errno() {

@Override
public Set<Operation> supportedOperations() {
// FIXME: respect enableXattr
return Set.of(Operation.ACCESS,
Operation.CHMOD,
Operation.CREATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ public final class ReadWriteAdapter extends ReadOnlyAdapter {
private static final Logger LOG = LoggerFactory.getLogger(ReadWriteAdapter.class);
private final ReadWriteFileHandler fileHandler;

private ReadWriteAdapter(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, FileStore fileStore, OpenFileFactory openFiles, ReadWriteDirectoryHandler dirHandler, ReadWriteFileHandler fileHandler) {
super(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler);
private ReadWriteAdapter(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, FileStore fileStore, OpenFileFactory openFiles, ReadWriteDirectoryHandler dirHandler, ReadWriteFileHandler fileHandler, boolean enableXattr) {
super(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler, enableXattr);
this.fileHandler = fileHandler;
}

public static ReadWriteAdapter create(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder) {
public static ReadWriteAdapter create(Errno errno, Path root, int maxFileNameLength, FileNameTranscoder fileNameTranscoder, boolean enableXattr) {
try {
var fileStore = Files.getFileStore(root);
var openFiles = new OpenFileFactory();
var dirHandler = new ReadWriteDirectoryHandler(fileNameTranscoder);
var fileHandler = new ReadWriteFileHandler(openFiles);
return new ReadWriteAdapter(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler);
return new ReadWriteAdapter(errno, root, maxFileNameLength, fileNameTranscoder, fileStore, openFiles, dirHandler, fileHandler, enableXattr);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -64,15 +64,17 @@ public Set<Operation> supportedOperations() {
ops.add(Operation.CREATE);
//ops.add(Operation.FSYNC);
ops.add(Operation.MKDIR);
ops.add(Operation.REMOVE_XATTR);
ops.add(Operation.RENAME);
ops.add(Operation.RMDIR);
ops.add(Operation.SET_XATTR);
ops.add(Operation.SYMLINK);
ops.add(Operation.TRUNCATE);
ops.add(Operation.UNLINK);
ops.add(Operation.UTIMENS);
ops.add(Operation.WRITE);
if (enableXattr) {
ops.add(Operation.SET_XATTR);
ops.add(Operation.REMOVE_XATTR);
}
return ops;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public Mount mount() throws MountFailedException {
var builder = Fuse.builder();
builder.setLibraryPath(DYLIB_PATH);
var filenameTranscoder = FileNameTranscoder.transcoder().withFuseNormalization(Normalizer.Form.NFD);
var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, filenameTranscoder);
var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, filenameTranscoder, false);
var fuse = builder.build(fuseAdapter);
try {
fuse.mount("fuse-nio-adapter", mountPoint, combinedMountFlags().toArray(String[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Mount mount() throws MountFailedException {
if (mountFlags.contains("-oallow_other") || mountFlags.contains("-oallow_root")) {
LOG.warn("Mounting with flag -oallow_other or -oallow_root. Ensure that in /etc/fuse.conf option user_allow_other is enabled.");
}
var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder());
var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder(), true);
var fuse = builder.build(fuseAdapter);
try {
fuse.mount("fuse-nio-adapter", mountPoint, mountFlags.toArray(String[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Mount mount() throws MountFailedException {
var builder = Fuse.builder();
builder.setLibraryPath(DYLIB_PATH);
var filenameTranscoder = FileNameTranscoder.transcoder().withFuseNormalization(Normalizer.Form.NFD);
var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, filenameTranscoder);
var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, filenameTranscoder, true);
var fuse = builder.build(fuseAdapter);
try {
fuse.mount("fuse-nio-adapter", mountPoint, combinedMountFlags().toArray(String[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Mount mount() throws MountFailedException {
var builder = Fuse.builder();
var libPath = WinfspUtil.getWinFspInstallDir() + "bin\\" + (OS_ARCH.contains("aarch64") ? "winfsp-a64.dll" : "winfsp-x64.dll");
builder.setLibraryPath(libPath);
var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder());
var fuseAdapter = ReadWriteAdapter.create(builder.errno(), vfsRoot, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder(), true);
try {
var fuse = builder.build(fuseAdapter);
fuse.mount("fuse-nio-adapter", mountPoint, combinedMountFlags().toArray(String[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AccessPatternIntegrationTest {
@BeforeEach
void setup(@TempDir Path tmpDir) {
var builder = Fuse.builder();
adapter = ReadWriteAdapter.create(builder.errno(), tmpDir, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder());
adapter = ReadWriteAdapter.create(builder.errno(), tmpDir, FuseNioAdapter.DEFAULT_MAX_FILENAMELENGTH, FileNameTranscoder.transcoder(), true);
}

@Test
Expand Down

0 comments on commit 5ce3f13

Please sign in to comment.