Skip to content

Commit b3e65c0

Browse files
Merge branch 'release/0.1.5'
# Conflicts: # pom.xml
2 parents e190a9a + 108ed2b commit b3e65c0

14 files changed

+167
-29
lines changed

pom.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.cryptomator</groupId>
44
<artifactId>cryptofs</artifactId>
5-
<version>0.1.4</version>
5+
<version>0.1.5</version>
66
<name>Cryptomator Crypto Filesystem</name>
77
<description>This library provides the Java filesystem provider used by Cryptomator.</description>
88
<url>https://github.com/cryptomator/cryptofs</url>
@@ -61,7 +61,7 @@
6161
<dependency>
6262
<groupId>org.cryptomator</groupId>
6363
<artifactId>cryptolib</artifactId>
64-
<version>1.0.4</version>
64+
<version>1.0.8</version>
6565
</dependency>
6666
<dependency>
6767
<groupId>org.apache.commons</groupId>
@@ -73,11 +73,6 @@
7373
<artifactId>guava</artifactId>
7474
<version>20.0</version>
7575
</dependency>
76-
<dependency>
77-
<groupId>commons-codec</groupId>
78-
<artifactId>commons-codec</artifactId>
79-
<version>1.10</version>
80-
</dependency>
8176

8277
<!-- Logging -->
8378
<dependency>

src/main/java/org/cryptomator/cryptofs/AbstractCryptoFileAttributeView.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ abstract class AbstractCryptoFileAttributeView<S extends BasicFileAttributes, T
2222
protected final T delegate;
2323
private final Class<S> attributesType;
2424

25-
public AbstractCryptoFileAttributeView(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider, Class<S> attributesType, Class<T> delegateType) {
25+
public AbstractCryptoFileAttributeView(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider, Class<S> attributesType, Class<T> delegateType) throws UnsupportedFileAttributeViewException {
2626
this.ciphertextPath = ciphertextPath;
2727
this.fileAttributeProvider = fileAttributeProvider;
2828
this.attributesType = attributesType;
2929
this.delegate = Files.getFileAttributeView(ciphertextPath, delegateType);
30+
if (delegate == null) {
31+
throw new UnsupportedFileAttributeViewException();
32+
}
3033
}
3134

3235
@Override

src/main/java/org/cryptomator/cryptofs/CryptoBasicFileAttributeView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class CryptoBasicFileAttributeView extends AbstractCryptoFileAttributeView<BasicFileAttributes, BasicFileAttributeView> implements BasicFileAttributeView {
1616

17-
public CryptoBasicFileAttributeView(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider) {
17+
public CryptoBasicFileAttributeView(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider) throws UnsupportedFileAttributeViewException {
1818
super(ciphertextPath, fileAttributeProvider, BasicFileAttributes.class, BasicFileAttributeView.class);
1919
}
2020

src/main/java/org/cryptomator/cryptofs/CryptoDosFileAttributeView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class CryptoDosFileAttributeView extends AbstractCryptoFileAttributeView<DosFileAttributes, DosFileAttributeView> implements DosFileAttributeView {
1717

18-
public CryptoDosFileAttributeView(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider) {
18+
public CryptoDosFileAttributeView(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider) throws UnsupportedFileAttributeViewException {
1919
super(ciphertextPath, fileAttributeProvider, DosFileAttributes.class, DosFileAttributeView.class);
2020
}
2121

src/main/java/org/cryptomator/cryptofs/CryptoFileAttributeViewProvider.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.nio.file.attribute.BasicFileAttributeView;
1414
import java.nio.file.attribute.DosFileAttributeView;
1515
import java.nio.file.attribute.FileAttributeView;
16+
import java.nio.file.attribute.FileOwnerAttributeView;
1617
import java.nio.file.attribute.PosixFileAttributeView;
1718
import java.util.Collections;
1819
import java.util.HashMap;
@@ -31,6 +32,7 @@ class CryptoFileAttributeViewProvider {
3132
public CryptoFileAttributeViewProvider(CryptoFileAttributeProvider fileAttributeProvider) {
3233
fileAttributeViewProviders.put(BasicFileAttributeView.class, CryptoBasicFileAttributeView::new);
3334
fileAttributeViewProviders.put(PosixFileAttributeView.class, CryptoPosixFileAttributeView::new);
35+
fileAttributeViewProviders.put(FileOwnerAttributeView.class, (ciphertextPath, ignored) -> new CryptoFileOwnerAttributeView(ciphertextPath));
3436
fileAttributeViewProviders.put(DosFileAttributeView.class, CryptoDosFileAttributeView::new);
3537
this.fileAttributeProvider = fileAttributeProvider;
3638
}
@@ -39,10 +41,14 @@ public CryptoFileAttributeViewProvider(CryptoFileAttributeProvider fileAttribute
3941
public <A extends FileAttributeView> A getAttributeView(Path ciphertextPath, Class<A> type) throws IOException {
4042
if (fileAttributeViewProviders.containsKey(type)) {
4143
FileAttributeViewProvider<A> provider = (FileAttributeViewProvider<A>) fileAttributeViewProviders.get(type);
42-
return provider.provide(ciphertextPath, fileAttributeProvider);
43-
} else {
44-
throw new UnsupportedOperationException("Unsupported file attribute type: " + type);
44+
try {
45+
return provider.provide(ciphertextPath, fileAttributeProvider);
46+
} catch (UnsupportedFileAttributeViewException e) {
47+
return null;
48+
}
4549
}
50+
// requested file attribute view is unsupported / unknown
51+
return null;
4652
}
4753

4854
Set<Class<? extends FileAttributeView>> knownFileAttributeViewTypes() {
@@ -51,7 +57,7 @@ Set<Class<? extends FileAttributeView>> knownFileAttributeViewTypes() {
5157

5258
@FunctionalInterface
5359
private static interface FileAttributeViewProvider<A extends FileAttributeView> {
54-
A provide(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider);
60+
A provide(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider) throws UnsupportedFileAttributeViewException;
5561
}
5662

5763
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2016 Sebastian Stenzel and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the accompanying LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Sebastian Stenzel - initial API and implementation
8+
*******************************************************************************/
9+
package org.cryptomator.cryptofs;
10+
11+
import java.io.IOException;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.nio.file.attribute.FileOwnerAttributeView;
15+
import java.nio.file.attribute.UserPrincipal;
16+
17+
class CryptoFileOwnerAttributeView implements FileOwnerAttributeView {
18+
19+
private final FileOwnerAttributeView delegate;
20+
21+
public CryptoFileOwnerAttributeView(Path ciphertextPath) throws UnsupportedFileAttributeViewException {
22+
this.delegate = Files.getFileAttributeView(ciphertextPath, FileOwnerAttributeView.class);
23+
if (delegate == null) {
24+
throw new UnsupportedFileAttributeViewException();
25+
}
26+
}
27+
28+
@Override
29+
public UserPrincipal getOwner() throws IOException {
30+
return delegate.getOwner();
31+
}
32+
33+
@Override
34+
public void setOwner(UserPrincipal owner) throws IOException {
35+
delegate.setOwner(owner);
36+
}
37+
38+
@Override
39+
public String name() {
40+
return "owner";
41+
}
42+
43+
}

src/main/java/org/cryptomator/cryptofs/CryptoFileSystem.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ public CryptoFileSystem(@PathToVault Path pathToVault, CryptoFileSystemPropertie
114114
rootDirectoryInitializer.initialize(rootPath);
115115
}
116116

117+
/**
118+
* @return The path to the directory containing the encrypted files. This path does not belong to this file system.
119+
*/
120+
public Path getPathToVault() {
121+
return pathToVault;
122+
}
123+
124+
/**
125+
* @return Live monitor for file system performance statistics.
126+
*/
127+
public CryptoFileSystemStats getStats() {
128+
return stats;
129+
}
130+
117131
/* java.nio.file.FileSystem API */
118132

119133
@Override
@@ -468,14 +482,6 @@ CryptoPath getEmptyPath() {
468482
return emptyPath;
469483
}
470484

471-
Path getPathToVault() {
472-
return pathToVault;
473-
}
474-
475-
CryptoFileSystemStats getStats() {
476-
return stats;
477-
}
478-
479485
void assertOpen() {
480486
if (!open) {
481487
throw new ClosedFileSystemException();

src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public String getScheme() {
128128
}
129129

130130
@Override
131-
public FileSystem newFileSystem(URI uri, Map<String, ?> rawProperties) throws IOException {
131+
public CryptoFileSystem newFileSystem(URI uri, Map<String, ?> rawProperties) throws IOException {
132132
ParsedUri parsedUri = CryptoFileSystemUris.parseUri(uri);
133133
CryptoFileSystemProperties properties = CryptoFileSystemProperties.wrap(rawProperties);
134134
return fileSystems.create(parsedUri.pathToVault(), properties);

src/main/java/org/cryptomator/cryptofs/CryptoFileSystemStats.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import javax.inject.Inject;
66

7+
/**
8+
* Provides access to file system performance metrics.
9+
* The available metrics are constantly updated in a thread-safe manner and can be polled at any time.
10+
*/
711
@PerFileSystem
812
public class CryptoFileSystemStats {
913

src/main/java/org/cryptomator/cryptofs/CryptoPosixFileAttributeView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class CryptoPosixFileAttributeView extends AbstractCryptoFileAttributeView<PosixFileAttributes, PosixFileAttributeView> implements PosixFileAttributeView {
2121

22-
public CryptoPosixFileAttributeView(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider) {
22+
public CryptoPosixFileAttributeView(Path ciphertextPath, CryptoFileAttributeProvider fileAttributeProvider) throws UnsupportedFileAttributeViewException {
2323
super(ciphertextPath, fileAttributeProvider, PosixFileAttributes.class, PosixFileAttributeView.class);
2424
}
2525

0 commit comments

Comments
 (0)