|
8 | 8 | *******************************************************************************/ |
9 | 9 | package org.cryptomator.cryptofs; |
10 | 10 |
|
11 | | -import com.google.common.base.Throwables; |
12 | | -import com.google.common.cache.Cache; |
13 | | -import com.google.common.cache.CacheBuilder; |
14 | | -import com.google.common.cache.CacheLoader; |
15 | | -import com.google.common.cache.LoadingCache; |
| 11 | +import com.github.benmanes.caffeine.cache.Cache; |
| 12 | +import com.github.benmanes.caffeine.cache.Caffeine; |
| 13 | +import com.github.benmanes.caffeine.cache.LoadingCache; |
16 | 14 | import com.google.common.io.BaseEncoding; |
17 | 15 | import org.cryptomator.cryptofs.common.CiphertextFileType; |
18 | 16 | import org.cryptomator.cryptofs.common.Constants; |
|
22 | 20 |
|
23 | 21 | import javax.inject.Inject; |
24 | 22 | import java.io.IOException; |
| 23 | +import java.io.UncheckedIOException; |
25 | 24 | import java.nio.charset.StandardCharsets; |
26 | 25 | import java.nio.file.FileAlreadyExistsException; |
27 | 26 | import java.nio.file.Files; |
|
32 | 31 | import java.time.Duration; |
33 | 32 | import java.util.Objects; |
34 | 33 | import java.util.Optional; |
35 | | -import java.util.concurrent.ExecutionException; |
36 | 34 |
|
37 | 35 | import static org.cryptomator.cryptofs.common.Constants.DATA_DIR_NAME; |
38 | 36 |
|
@@ -61,8 +59,8 @@ public class CryptoPathMapper { |
61 | 59 | this.dirIdProvider = dirIdProvider; |
62 | 60 | this.longFileNameProvider = longFileNameProvider; |
63 | 61 | this.vaultConfig = vaultConfig; |
64 | | - this.ciphertextNames = CacheBuilder.newBuilder().maximumSize(MAX_CACHED_CIPHERTEXT_NAMES).build(CacheLoader.from(this::getCiphertextFileName)); |
65 | | - this.ciphertextDirectories = CacheBuilder.newBuilder().maximumSize(MAX_CACHED_DIR_PATHS).expireAfterWrite(MAX_CACHE_AGE).build(); |
| 62 | + this.ciphertextNames = Caffeine.newBuilder().maximumSize(MAX_CACHED_CIPHERTEXT_NAMES).build(this::getCiphertextFileName); |
| 63 | + this.ciphertextDirectories = Caffeine.newBuilder().maximumSize(MAX_CACHED_DIR_PATHS).expireAfterWrite(MAX_CACHE_AGE).build(); |
66 | 64 | this.rootDirectory = resolveDirectory(Constants.ROOT_DIR_ID); |
67 | 65 | } |
68 | 66 |
|
@@ -127,7 +125,7 @@ public CiphertextFilePath getCiphertextFilePath(CryptoPath cleartextPath) throws |
127 | 125 | } |
128 | 126 |
|
129 | 127 | public CiphertextFilePath getCiphertextFilePath(Path parentCiphertextDir, String parentDirId, String cleartextName) { |
130 | | - String ciphertextName = ciphertextNames.getUnchecked(new DirIdAndName(parentDirId, cleartextName)); |
| 128 | + String ciphertextName = ciphertextNames.get(new DirIdAndName(parentDirId, cleartextName)); |
131 | 129 | Path c9rPath = parentCiphertextDir.resolve(ciphertextName); |
132 | 130 | if (ciphertextName.length() > vaultConfig.getShorteningThreshold()) { |
133 | 131 | LongFileNameProvider.DeflatedFileName deflatedFileName = longFileNameProvider.deflate(c9rPath); |
@@ -160,13 +158,16 @@ public CiphertextDirectory getCiphertextDir(CryptoPath cleartextPath) throws IOE |
160 | 158 | return rootDirectory; |
161 | 159 | } else { |
162 | 160 | try { |
163 | | - return ciphertextDirectories.get(cleartextPath, () -> { |
164 | | - Path dirFile = getCiphertextFilePath(cleartextPath).getDirFilePath(); |
165 | | - return resolveDirectory(dirFile); |
| 161 | + return ciphertextDirectories.get(cleartextPath, p -> { |
| 162 | + try { |
| 163 | + Path dirFile = getCiphertextFilePath(p).getDirFilePath(); |
| 164 | + return resolveDirectory(dirFile); |
| 165 | + } catch (IOException e) { |
| 166 | + throw new UncheckedIOException(e); |
| 167 | + } |
166 | 168 | }); |
167 | | - } catch (ExecutionException e) { |
168 | | - Throwables.throwIfInstanceOf(e.getCause(), IOException.class); |
169 | | - throw new IOException("Unexpected exception", e); |
| 169 | + } catch (UncheckedIOException e) { |
| 170 | + throw new IOException(e); |
170 | 171 | } |
171 | 172 | } |
172 | 173 | } |
|
0 commit comments