@@ -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