@Test public void testReadLinkLongNameIsTruncated() throws Exception { Path fooBar = mockPath("foo.bar"); Path target = mockPath("ThisIsALongName"); when(fileSystem.provider().readSymbolicLink(fooBar)).thenReturn(target); int result = fs.readLink("foo.bar", (name) -> assertThat(name).isEqualTo("ThisI"), 5); assertThat(result).isEqualTo(SUCCESS); }
@Override public int readLink(String path, Consumer<String> buf, int size) { logger.debug(path); Path real = real(path); return tryCatch.apply(() -> { Path target = Files.readSymbolicLink(real); return getFileName(target).map(name -> { buf.accept(truncateIfNeeded(name, size)); return SUCCESS; }).orElse(-ErrorCodes.EINVAL()); }); }
MirrorFs implements se.tfiskgul.mux2fs.fs.base.FileSystem { @Override public int readLink(String path, Consumer<String> buf, int size) { logger.debug(path); Path real = real(path); return tryCatch.apply(() -> { Path target = Files.readSymbolicLink(real); return getFileName(target).map(name -> { buf.accept(truncateIfNeeded(name, size)); return SUCCESS; }).orElse(-ErrorCodes.EINVAL()); }); } }
MirrorFs implements se.tfiskgul.mux2fs.fs.base.FileSystem { @Override public int readLink(String path, Consumer<String> buf, int size) { logger.debug(path); Path real = real(path); return tryCatch.apply(() -> { Path target = Files.readSymbolicLink(real); return getFileName(target).map(name -> { buf.accept(truncateIfNeeded(name, size)); return SUCCESS; }).orElse(-ErrorCodes.EINVAL()); }); } MirrorFs(Path mirroredPath); @VisibleForTesting protected  MirrorFs(Path mirroredPath, FileChannelCloser fileChannelCloser); }
MirrorFs implements se.tfiskgul.mux2fs.fs.base.FileSystem { @Override public int readLink(String path, Consumer<String> buf, int size) { logger.debug(path); Path real = real(path); return tryCatch.apply(() -> { Path target = Files.readSymbolicLink(real); return getFileName(target).map(name -> { buf.accept(truncateIfNeeded(name, size)); return SUCCESS; }).orElse(-ErrorCodes.EINVAL()); }); } MirrorFs(Path mirroredPath); @VisibleForTesting protected  MirrorFs(Path mirroredPath, FileChannelCloser fileChannelCloser); @Override String getFSName(); @Override int getattr(String path, StatFiller stat); @Override int readdir(String path, DirectoryFiller filler); @Override int readLink(String path, Consumer<String> buf, int size); @Override int open(String path, FileHandleFiller filler); @Override int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle); @Override int release(String path, int fileHandle); @Override void destroy(); }
MirrorFs implements se.tfiskgul.mux2fs.fs.base.FileSystem { @Override public int readLink(String path, Consumer<String> buf, int size) { logger.debug(path); Path real = real(path); return tryCatch.apply(() -> { Path target = Files.readSymbolicLink(real); return getFileName(target).map(name -> { buf.accept(truncateIfNeeded(name, size)); return SUCCESS; }).orElse(-ErrorCodes.EINVAL()); }); } MirrorFs(Path mirroredPath); @VisibleForTesting protected  MirrorFs(Path mirroredPath, FileChannelCloser fileChannelCloser); @Override String getFSName(); @Override int getattr(String path, StatFiller stat); @Override int readdir(String path, DirectoryFiller filler); @Override int readLink(String path, Consumer<String> buf, int size); @Override int open(String path, FileHandleFiller filler); @Override int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle); @Override int release(String path, int fileHandle); @Override void destroy();  }