Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Oct 31, 2018
2 parents 7eef2a2 + 30dea96 commit 085fe33
Show file tree
Hide file tree
Showing 22 changed files with 251 additions and 141 deletions.
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: java
sudo: false
jdk:
- oraclejdk9
- openjdk11
env:
global:
- secure: "SvqhJ7cFF4Uir0rvngiZAsxhgYAFCdw1bVHfKtA2MAV5taAuGsN0Uij+kLUP0oxHmrKwbSoOlHmTOG6m6GYOmX9ALAgfVRI41vnZxzhhR6zdHq4Kx84rhIxGHAXhxY8GPJiN+ClyeEr/qf6Jb60XyydU7w1wO8a1y+AYSW/CK0HZ4qORVgHOmfMmP7sCmgaPwCCcNoq/5mW873XHbJUbVh4d0wNn6Pej9oKRgsShWCqb/ihQ4IqNQjSQO+nF9FAuqMVzFJhnoNempuHG6R98QUlHXZ4IERlYfWfwjg6OtXk369QMAbQQ3k8bheozgM7R1mRq/cfIyIWzqY29UjqGVChy918QvXLDpLtVeU8ThF5cPgsle8K2NdaHZutfYXFo7qVosIAAMwkory5WN+RX7W2DqXAFwZjn5SfHvPMTz3tFgvAfVkV3qQg/bdOI6vA1cLghd/ZPRiCoJVJ/EdxwDor/FH5wRW2XFPIkqSWjlv4TnAd8YoAUZ44iO0DyUgyrB6oVdNYhW+0ei0M181rkSLdg5yfDykQF324lIwMwoalDMK4LcTxcgFVdyLSZr0xVtJr9vmr3w2xoJfB18hufHKkqMZQ+kDlhAmAjZApmrAIRR22gqhJJNctTEbX4O2s2BbD93TuKhBQMMDYzfoM8s62NCQ3qUbPtQUECW5HbF+k=" # CODACY_PROJECT_TOKEN
Expand All @@ -12,14 +12,11 @@ install:
script:
- mvn clean test jacoco:report verify -Dsurefire.useFile=false -Pcoverage
after_success:
- jdk_switcher use oraclejdk8
- curl -o ~/codacy-coverage-reporter-assembly-latest.jar https://oss.sonatype.org/service/local/repositories/releases/content/com/codacy/codacy-coverage-reporter/4.0.1/codacy-coverage-reporter-4.0.1-assembly.jar
- $JAVA_HOME/bin/java -jar ~/codacy-coverage-reporter-assembly-latest.jar report -l Java -r target/site/jacoco/jacoco.xml
- curl -o ~/codacy-coverage-reporter.jar https://oss.sonatype.org/service/local/repositories/releases/content/com/codacy/codacy-coverage-reporter/4.0.3/codacy-coverage-reporter-4.0.3-assembly.jar
- $JAVA_HOME/bin/java -jar ~/codacy-coverage-reporter.jar report -l Java -r target/site/jacoco/jacoco.xml
cache:
directories:
- $HOME/.m2
before_deploy:
- jdk_switcher use oraclejdk9
deploy:
- provider: script # RELEASES
script: mvn clean versions:set -DnewVersion=${TRAVIS_TAG} deploy -DskipTests -Prelease
Expand Down
37 changes: 14 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>fuse-nio-adapter</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<name>FUSE-NIO-Adapter</name>
<description>Access resources at a given NIO path via FUSE.</description>
<url>https://github.com/cryptomator/fuse-nio-adapter</url>
Expand All @@ -16,14 +16,11 @@

<properties>
<jnrfuse.version>0.5.2.1</jnrfuse.version>
<jnrconstants.version>0.9.9</jnrconstants.version>
<jnrposix.version>3.0.45</jnrposix.version>
<dagger.version>2.15</dagger.version>
<guava.version>25.0-jre</guava.version>
<dagger.version>2.19</dagger.version>
<guava.version>27.0-jre</guava.version>
<slf4j.version>1.7.25</slf4j.version>
<junit.jupiter.version>5.3.0</junit.jupiter.version>
<junit.platform.version>1.3.0</junit.platform.version>
<mockito.version>2.11.0</mockito.version>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
<mockito.version>2.23.0</mockito.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -67,6 +64,12 @@
<artifactId>dagger</artifactId>
<version>${dagger.version}</version>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>${dagger.version}</version>
<scope>provided</scope>
</dependency>

<!-- Guava -->
<dependency>
Expand Down Expand Up @@ -113,29 +116,17 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.0</version>
<configuration>
<source>9</source>
<target>9</target>
<release>9</release>
<showWarnings>true</showWarnings>
<annotationProcessorPaths>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>${dagger.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
Expand All @@ -148,7 +139,7 @@
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>3.2.1</version>
<version>3.3.4</version>
<configuration>
<cveValidForHours>24</cveValidForHours>
<failBuildOnCVSS>0</failBuildOnCVSS>
Expand Down Expand Up @@ -177,7 +168,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<version>0.8.2</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ public <E extends Enum & Constant> Set<E> bitMaskToSet(Class<E> clazz, long mask
return result;
}

public <E extends Enum & Constant> long setToBitMask(Set<E> set) {
long mask = 0;
for (E value : set) {
mask |= value.longValue();
}
return mask;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public void copyBasicFileAttributesFromNioToFuse(BasicFileAttributes attrs, File
stat.st_atim.tv_sec.set(attrs.lastAccessTime().toInstant().getEpochSecond());
stat.st_atim.tv_nsec.set(attrs.lastAccessTime().toInstant().getNano());
stat.st_size.set(attrs.size());
// make sure to nil certain fields known to contain garbage from uninitialized memory
// fixes alleged permission bugs, see https://github.com/cryptomator/fuse-nio-adapter/issues/19
if (Platform.IS_MAC) {
stat.st_flags.set(0);
stat.st_gen.set(0);
}
}

}
4 changes: 3 additions & 1 deletion src/main/java/org/cryptomator/frontend/fuse/OpenFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ public synchronized int read(Pointer buf, long num, long offset) throws IOExcept
ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
long pos = 0;
channel.position(offset);
LOG.trace("Attempting to read {}-{}:", offset, offset + num);
do {
long remaining = num - pos;
int read = readNext(bb, remaining);
if (read == -1) {
LOG.trace("Reached EOF");
return (int) pos; // reached EOF TODO: wtf cast
} else {
LOG.trace("Reading {}-{} ({}-{})", offset + pos, offset + pos + read, offset, offset + num);
LOG.trace("Reading {}-{}", offset + pos, offset + pos + read);
buf.put(pos, bb.array(), 0, read);
pos += read;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class OpenFileFactory implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(OpenFileFactory.class);

private final ConcurrentMap<Long, OpenFile> openFiles = new ConcurrentHashMap<>();
private final AtomicLong fileHandleGen = new AtomicLong();
private final AtomicLong fileHandleGen = new AtomicLong(1l);

@Inject
public OpenFileFactory() {
Expand All @@ -50,7 +50,9 @@ public long open(Path path, OpenOption... options) throws IOException {
*/
public long open(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
long fileHandle = fileHandleGen.getAndIncrement();
openFiles.put(fileHandle, new OpenFile(path, options, attrs));
OpenFile file = new OpenFile(path, options, attrs);
openFiles.put(fileHandle, file);
LOG.trace("Opening {} {}", fileHandle, file);
return fileHandle;
}

Expand All @@ -68,6 +70,7 @@ public OpenFile get(Long fileHandle) {
public void close(long fileHandle) throws ClosedChannelException, IOException {
OpenFile file = openFiles.remove(fileHandle);
if (file != null) {
LOG.trace("Releasing {} {}", fileHandle, file);
file.close();
} else {
throw new ClosedChannelException();
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/cryptomator/frontend/fuse/ReadOnlyAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public int statfs(String path, Statvfs stbuf) {
stbuf.f_blocks.set(tBlocks);
stbuf.f_bavail.set(aBlocks);
stbuf.f_bfree.set(aBlocks);
LOG.trace("statfs {} ({} / {})", path, avail, total);
return 0;
} catch (IOException | RuntimeException e) {
LOG.error("statfs failed.", e);
LOG.error("statfs " + path + " failed.", e);
return -ErrorCodes.EIO();
}
}
Expand Down Expand Up @@ -121,13 +122,15 @@ public int getattr(String path, FileStat stat) {
DataLock dataLock = pathLock.lockDataForReading()) {
Path node = resolvePath(path);
BasicFileAttributes attrs = Files.readAttributes(node, BasicFileAttributes.class);
LOG.trace("getattr {} (lastModifiedTime: {}, lastAccessTime: {}, creationTime: {}, isRegularFile: {}, isDirectory: {}, isSymbolicLink: {}, isOther: {}, size: {}, fileKey: {})", path, attrs.lastModifiedTime(), attrs.lastAccessTime(), attrs.creationTime(), attrs.isRegularFile(), attrs.isDirectory(), attrs.isSymbolicLink(), attrs.isOther(), attrs.size(), attrs.fileKey());
if (attrs.isDirectory()) {
return dirHandler.getattr(node, attrs, stat);
} else {
return fileHandler.getattr(node, attrs, stat);
}
} catch (NoSuchFileException e) {
// see Files.notExists
LOG.trace("getattr {} failed, node not found", path);
return -ErrorCodes.ENOENT();
} catch (IOException | RuntimeException e) {
LOG.error("getattr failed.", e);
Expand All @@ -140,8 +143,10 @@ public int readdir(String path, Pointer buf, FuseFillDir filler, @off_t long off
try (PathLock pathLock = lockManager.createPathLock(path).forReading();
DataLock dataLock = pathLock.lockDataForReading()) {
Path node = resolvePath(path);
LOG.trace("readdir {}", path);
return dirHandler.readdir(node, buf, filler, offset, fi);
} catch (NotDirectoryException e) {
LOG.error("readdir {} failed, node is not a directory.", path);
return -ErrorCodes.ENOENT();
} catch (IOException | RuntimeException e) {
LOG.error("readdir failed.", e);
Expand All @@ -156,10 +161,13 @@ public int open(String path, FuseFileInfo fi) {
Path node = resolvePath(path);
// TODO do we need to distinguish files vs. dirs? https://github.com/libfuse/libfuse/wiki/Invariants
if (Files.isDirectory(node)) {
LOG.error("open {} failed, node is a directory.", path);
return -ErrorCodes.EISDIR();
} else if (Files.exists(node)) {
LOG.trace("open {} ({})", path, fi.fh.get());
return fileHandler.open(node, fi);
} else {
LOG.error("open {} failed, file not found.", path);
return -ErrorCodes.ENOENT();
}
} catch (RuntimeException e) {
Expand All @@ -186,6 +194,7 @@ public int release(String path, FuseFileInfo fi) {
try (PathLock pathLock = lockManager.createPathLock(path).forReading();
DataLock dataLock = pathLock.lockDataForReading()) {
Path node = resolvePath(path);
LOG.trace("release {} ({})", path, fi.fh.get());
return fileHandler.release(node, fi);
} catch (RuntimeException e) {
LOG.error("release failed.", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package org.cryptomator.frontend.fuse;

import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import jnr.ffi.Pointer;
import ru.serce.jnrfuse.ErrorCodes;
import ru.serce.jnrfuse.FuseFillDir;
import ru.serce.jnrfuse.struct.FileStat;
import ru.serce.jnrfuse.struct.FuseFileInfo;

import javax.inject.Inject;
import java.io.IOException;
import java.nio.file.DirectoryIteratorException;
import java.nio.file.DirectoryStream;
Expand All @@ -9,22 +18,9 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Iterator;

import javax.inject.Inject;

import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import jnr.ffi.Pointer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.serce.jnrfuse.ErrorCodes;
import ru.serce.jnrfuse.FuseFillDir;
import ru.serce.jnrfuse.struct.FileStat;
import ru.serce.jnrfuse.struct.FuseFileInfo;

@PerAdapter
public class ReadOnlyDirectoryHandler {

private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyDirectoryHandler.class);
private static final Path SAME_DIR = Paths.get(".");
private static final Path PARENT_DIR = Paths.get("..");
private final FileAttributesUtil attrUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package org.cryptomator.frontend.fuse;

import jnr.ffi.Pointer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.serce.jnrfuse.ErrorCodes;
import ru.serce.jnrfuse.struct.FileStat;
import ru.serce.jnrfuse.struct.FuseFileInfo;

import javax.inject.Inject;
import java.io.Closeable;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
import java.nio.file.AccessDeniedException;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Set;

import javax.inject.Inject;

import jnr.ffi.Pointer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.serce.jnrfuse.ErrorCodes;
import ru.serce.jnrfuse.struct.FileStat;
import ru.serce.jnrfuse.struct.FuseFileInfo;

@PerAdapter
public class ReadOnlyFileHandler implements Closeable {

Expand Down
Loading

0 comments on commit 085fe33

Please sign in to comment.