diff --git a/pom.xml b/pom.xml index 3ddeb73..b39c6f6 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,6 @@ 1.2.0 0.5.1 - 31.1-jre 2.0.7 3.1.6 @@ -70,12 +69,7 @@ ${integrations-api.version} - - - com.google.guava - guava - ${guava.version} - + com.github.ben-manes.caffeine caffeine diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 50a84e8..a43ce98 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -9,9 +9,8 @@ requires org.cryptomator.jfuse; requires org.cryptomator.integrations.api; requires org.slf4j; - requires com.google.common; // TODO try to remove requires com.github.benmanes.caffeine; requires static org.jetbrains.annotations; provides MountService with LinuxFuseMountProvider, MacFuseMountProvider, FuseTMountProvider, WinFspMountProvider, WinFspNetworkMountProvider; -} \ No newline at end of file +} diff --git a/src/main/java/org/cryptomator/frontend/fuse/FileNameTranscoder.java b/src/main/java/org/cryptomator/frontend/fuse/FileNameTranscoder.java index de29d29..ab88e76 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/FileNameTranscoder.java +++ b/src/main/java/org/cryptomator/frontend/fuse/FileNameTranscoder.java @@ -1,11 +1,10 @@ package org.cryptomator.frontend.fuse; -import com.google.common.base.Preconditions; - import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.text.Normalizer; +import java.util.Objects; /** * Class to transcode filenames and path components from one encoding to another. @@ -25,10 +24,10 @@ public class FileNameTranscoder { private final boolean nioCharsetIsUnicode; FileNameTranscoder(Charset fuseCharset, Charset nioCharset, Normalizer.Form fuseNormalization, Normalizer.Form nioNormalization) { - this.fuseCharset = Preconditions.checkNotNull(fuseCharset); - this.nioCharset = Preconditions.checkNotNull(nioCharset); - this.fuseNormalization = Preconditions.checkNotNull(fuseNormalization); - this.nioNormalization = Preconditions.checkNotNull(nioNormalization); + this.fuseCharset = Objects.requireNonNull(fuseCharset); + this.nioCharset = Objects.requireNonNull(nioCharset); + this.fuseNormalization = Objects.requireNonNull(fuseNormalization); + this.nioNormalization = Objects.requireNonNull(nioNormalization); this.fuseCharsetIsUnicode = fuseCharset.name().startsWith("UTF"); this.nioCharsetIsUnicode = nioCharset.name().startsWith("UTF"); } diff --git a/src/main/java/org/cryptomator/frontend/fuse/OpenFile.java b/src/main/java/org/cryptomator/frontend/fuse/OpenFile.java index 381b7d6..b874228 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/OpenFile.java +++ b/src/main/java/org/cryptomator/frontend/fuse/OpenFile.java @@ -1,6 +1,5 @@ package org.cryptomator.frontend.fuse; -import com.google.common.base.MoreObjects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -97,10 +96,10 @@ public void truncate(long size) throws IOException { @Override public String toString() { - return MoreObjects.toStringHelper(OpenFile.class) // - .add("path", path) // - .add("channel", channel) // - .toString(); + return "OpenFile{" + + "path=" + path + ", " + + "channel=" + channel + + "}"; } } diff --git a/src/main/java/org/cryptomator/frontend/fuse/OpenFileFactory.java b/src/main/java/org/cryptomator/frontend/fuse/OpenFileFactory.java index c223fca..f1471cb 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/OpenFileFactory.java +++ b/src/main/java/org/cryptomator/frontend/fuse/OpenFileFactory.java @@ -1,6 +1,5 @@ package org.cryptomator.frontend.fuse; -import com.google.common.collect.Sets; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,8 +8,6 @@ import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.attribute.FileAttribute; -import java.util.Iterator; -import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -30,7 +27,7 @@ public class OpenFileFactory implements AutoCloseable { * @throws IOException */ public long open(Path path, OpenOption... options) throws IOException { - return this.open(path, Sets.newHashSet(options)); + return open(path, Set.of(options)); } /** diff --git a/src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java b/src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java index ad9713e..a4c8064 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java +++ b/src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java @@ -1,8 +1,5 @@ package org.cryptomator.frontend.fuse; -import com.google.common.base.CharMatcher; -import com.google.common.base.Strings; -import com.google.common.collect.Iterables; import org.cryptomator.frontend.fuse.locks.AlreadyLockedException; import org.cryptomator.frontend.fuse.locks.DataLock; import org.cryptomator.frontend.fuse.locks.LockManager; @@ -102,8 +99,16 @@ public Set supportedOperations() { Operation.STATFS); } + private String stripLeadingFrom(String string) { + StringBuilder sb = new StringBuilder(string); + while (!sb.isEmpty() && sb.charAt(0) == '/') { + sb.deleteCharAt(0); + } + return sb.toString(); + } + protected Path resolvePath(String absolutePath) { - String relativePath = CharMatcher.is('/').trimLeadingFrom(absolutePath); + String relativePath = stripLeadingFrom(absolutePath); return root.resolve(relativePath); } @@ -149,7 +154,7 @@ protected int checkAccess(Path path, Set requiredAccessModes, Set ds = Files.newDirectoryStream(path)) { - Iterator sameAndParent = Iterators.forArray(SAME_DIR, PARENT_DIR); - Iterator iter = Iterators.concat(sameAndParent, ds.iterator()); - while (iter.hasNext()) { - String fileName = iter.next().getFileName().toString(); + try (Stream ds = Files.list(path)) { + Stream sameAndParent = Stream.of(SAME_DIR, PARENT_DIR); + Stream iter = Stream.concat(sameAndParent, ds); + for (Path file : iter.toList()) { + String fileName = file.getFileName().toString(); filler.fill(fileNameTranscoder.nioToFuse(fileName)); } return 0; diff --git a/src/main/java/org/cryptomator/frontend/fuse/locks/FilePaths.java b/src/main/java/org/cryptomator/frontend/fuse/locks/FilePaths.java index 77b5ea0..ddaebb3 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/locks/FilePaths.java +++ b/src/main/java/org/cryptomator/frontend/fuse/locks/FilePaths.java @@ -1,35 +1,40 @@ package org.cryptomator.frontend.fuse.locks; -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; import org.jetbrains.annotations.Unmodifiable; import java.util.List; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import java.util.stream.Collectors; import java.util.stream.Stream; class FilePaths { - private static final char PATH_SEP = '/'; + private static final String PATH_SEP = "/"; private static final String ROOT = ""; - private static final Splitter PATH_SPLITTER = Splitter.on(PATH_SEP).omitEmptyStrings(); - private static final Joiner PATH_JOINER = Joiner.on(PATH_SEP); + private static final Pattern PATH_REGEX = Pattern.compile(PATH_SEP); @Unmodifiable public static List toComponents(String pathRelativeToRoot) { - return Stream.concat(Stream.of(ROOT), PATH_SPLITTER.splitToStream(pathRelativeToRoot)).toList(); + return Stream.concat(Stream.of(ROOT), PATH_REGEX + .splitAsStream(pathRelativeToRoot) + .filter(Predicate.not(String::isEmpty))).toList(); } public static String toPath(List pathComponents) { - return PATH_JOINER.join(pathComponents); + return String.join(PATH_SEP, pathComponents); } public static List parentPathComponents(List pathComponents) { - assert pathComponents.size() > 0; + assert !pathComponents.isEmpty(); return pathComponents.subList(0, pathComponents.size() - 1); } public static String normalizePath(String path) { - return ROOT + PATH_SEP + PATH_JOINER.join(PATH_SPLITTER.split(path)); + return ROOT + PATH_SEP + PATH_REGEX + .splitAsStream(path) + .filter(Predicate.not(String::isEmpty)) + .collect(Collectors.joining(PATH_SEP)); } } diff --git a/src/main/java/org/cryptomator/frontend/fuse/mount/FuseTMountProvider.java b/src/main/java/org/cryptomator/frontend/fuse/mount/FuseTMountProvider.java index 143eec1..acccf6a 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/mount/FuseTMountProvider.java +++ b/src/main/java/org/cryptomator/frontend/fuse/mount/FuseTMountProvider.java @@ -1,6 +1,5 @@ package org.cryptomator.frontend.fuse.mount; -import com.google.common.base.Preconditions; import org.cryptomator.frontend.fuse.FileNameTranscoder; import org.cryptomator.frontend.fuse.FuseNioAdapter; import org.cryptomator.frontend.fuse.ReadWriteAdapter; @@ -21,6 +20,7 @@ import java.nio.file.Paths; import java.text.Normalizer; import java.util.EnumSet; +import java.util.Objects; import java.util.Set; import static org.cryptomator.integrations.mount.MountCapability.MOUNT_FLAGS; @@ -114,8 +114,8 @@ protected Set combinedMountFlags() { @Override public Mount mount() throws MountFailedException { - Preconditions.checkNotNull(mountPoint); - Preconditions.checkNotNull(mountFlags); + Objects.requireNonNull(mountPoint); + Objects.requireNonNull(mountFlags); var builder = Fuse.builder(); builder.setLibraryPath(DYLIB_PATH); diff --git a/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxFuseMountProvider.java b/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxFuseMountProvider.java index 8bbb85c..db39096 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxFuseMountProvider.java +++ b/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxFuseMountProvider.java @@ -1,6 +1,5 @@ package org.cryptomator.frontend.fuse.mount; -import com.google.common.base.Preconditions; import org.cryptomator.frontend.fuse.FileNameTranscoder; import org.cryptomator.frontend.fuse.FuseNioAdapter; import org.cryptomator.frontend.fuse.ReadWriteAdapter; @@ -24,6 +23,7 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.EnumSet; +import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeoutException; @@ -42,7 +42,7 @@ public class LinuxFuseMountProvider implements MountService { private static final String[] LIB_PATHS = { "/usr/lib/libfuse3.so", // default "/lib/x86_64-linux-gnu/libfuse3.so.3", // debian amd64 - "/lib/aarch64-linux-gnu/libfuse3.so.3", // debiant aarch64 + "/lib/aarch64-linux-gnu/libfuse3.so.3", // debian aarch64 "/usr/lib64/libfuse3.so.3", // fedora "/app/lib/libfuse3.so" // flatpak }; @@ -98,8 +98,8 @@ public MountBuilder setMountpoint(Path mountPoint) { @Override public Mount mount() throws MountFailedException { - Preconditions.checkNotNull(mountPoint); - Preconditions.checkNotNull(mountFlags); + Objects.requireNonNull(mountPoint); + Objects.requireNonNull(mountFlags); var libPath = Arrays.stream(LIB_PATHS).map(Path::of).filter(Files::exists).map(Path::toString).findAny().orElseThrow(); var builder = Fuse.builder(); diff --git a/src/main/java/org/cryptomator/frontend/fuse/mount/MacFuseMountProvider.java b/src/main/java/org/cryptomator/frontend/fuse/mount/MacFuseMountProvider.java index 52feba8..e6ee4ef 100644 --- a/src/main/java/org/cryptomator/frontend/fuse/mount/MacFuseMountProvider.java +++ b/src/main/java/org/cryptomator/frontend/fuse/mount/MacFuseMountProvider.java @@ -1,6 +1,5 @@ package org.cryptomator.frontend.fuse.mount; -import com.google.common.base.Preconditions; import org.cryptomator.frontend.fuse.FileNameTranscoder; import org.cryptomator.frontend.fuse.FuseNioAdapter; import org.cryptomator.frontend.fuse.ReadWriteAdapter; @@ -21,6 +20,7 @@ import java.nio.file.Paths; import java.text.Normalizer; import java.util.EnumSet; +import java.util.Objects; import java.util.Set; import static org.cryptomator.integrations.mount.MountCapability.MOUNT_FLAGS; @@ -106,9 +106,9 @@ public MountBuilder setVolumeId(String volumeId) { @Override public Mount mount() throws MountFailedException { - Preconditions.checkNotNull(mountFlags); + Objects.requireNonNull(mountFlags); if (mountPoint == null) { - Preconditions.checkNotNull(volumeId); + Objects.requireNonNull(volumeId); mountPoint = Path.of("/Volumes/", volumeId); } diff --git a/suppression.xml b/suppression.xml index c0edcc0..75b1978 100644 --- a/suppression.xml +++ b/suppression.xml @@ -41,12 +41,4 @@ CVE-2018-10906 - - - ^pkg:maven/com\.google\.guava/guava@.*$ - CVE-2020-8908 - CVE-2020-8908 - - \ No newline at end of file +