Skip to content

Commit 6e3e277

Browse files
committed
Require write lock when creating directory id.
1 parent 1728153 commit 6e3e277

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/impl/CryptoDirectoryUVFProvider.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,15 @@ protected int loadRevision(final Session<?> session, final Path directory) throw
176176

177177
@Override
178178
public byte[] createDirectoryId(final Path directory) {
179-
final byte[] dirId = new byte[32];
180-
random.nextBytes(dirId);
181-
//TODO lock?
182-
cache.put(new SimplePathPredicate(directory), dirId);
183-
return dirId;
184-
179+
lock.writeLock().lock();
180+
try {
181+
final byte[] dirId = new byte[32];
182+
random.nextBytes(dirId);
183+
cache.put(new SimplePathPredicate(directory), dirId);
184+
return dirId;
185+
}
186+
finally {
187+
lock.writeLock().unlock();
188+
}
185189
}
186190
}

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/impl/CryptoDirectoryV6Provider.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class CryptoDirectoryV6Provider implements CryptoDirectory {
5454
private final RandomStringService random
5555
= new UUIDRandomStringService();
5656

57-
private final ReadWriteLock lock = new ReentrantReadWriteLock();
57+
protected final ReadWriteLock lock = new ReentrantReadWriteLock();
5858

5959
protected final LRUCache<CacheReference<Path>, byte[]> cache = LRUCache.build(
6060
PreferencesFactory.get().getInteger("cryptomator.cache.size"));
@@ -107,8 +107,8 @@ protected byte[] toDirectoryId(final Session<?> session, final Path directory) t
107107
if(new SimplePathPredicate(home).test(directory)) {
108108
return ROOT_DIR_ID;
109109
}
110+
lock.readLock().lock();
110111
try {
111-
lock.readLock().lock();
112112
if(cache.contains(new SimplePathPredicate(directory))) {
113113
return cache.get(new SimplePathPredicate(directory));
114114
}
@@ -145,8 +145,8 @@ protected byte[] load(final Session<?> session, final Path directory) throws Bac
145145
}
146146

147147
public void delete(final Path directory) {
148+
lock.writeLock().lock();
148149
try {
149-
lock.writeLock().lock();
150150
cache.remove(new SimplePathPredicate(directory));
151151
}
152152
finally {
@@ -156,8 +156,8 @@ public void delete(final Path directory) {
156156

157157
@Override
158158
public void destroy() {
159+
lock.writeLock().lock();
159160
try {
160-
lock.writeLock().lock();
161161
cache.clear();
162162
}
163163
finally {
@@ -176,9 +176,14 @@ public byte[] getOrCreateDirectoryId(final Session<?> session, final Path file)
176176

177177
@Override
178178
public byte[] createDirectoryId(final Path directory) {
179-
final byte[] directoryId = random.random().getBytes(StandardCharsets.US_ASCII);
180-
//TODO lock?
181-
cache.put(new SimplePathPredicate(directory), directoryId);
182-
return directoryId;
179+
lock.writeLock().lock();
180+
try {
181+
final byte[] directoryId = random.random().getBytes(StandardCharsets.US_ASCII);
182+
cache.put(new SimplePathPredicate(directory), directoryId);
183+
return directoryId;
184+
}
185+
finally {
186+
lock.writeLock().unlock();
187+
}
183188
}
184189
}

0 commit comments

Comments
 (0)