Improve FilesystemSchemaSourceCache mkdirs handling 93/72793/1
authorTom Pantelis <tompantelis@gmail.com>
Fri, 8 Jun 2018 13:34:19 +0000 (09:34 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Fri, 8 Jun 2018 13:37:22 +0000 (09:37 -0400)
mkdirs returns false if the directory already exists. Although
it check exists prior to mkdirs, it's possible for the dir to be
created by another thread in between the calls so make it robust
by checking isDirectory (which also checks exists) if mkdirs returns
false.

Change-Id: If63a2d20400c3093f0aea4c22192fa0e01fde748
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java

index 315152b05c33475bfb5f66f775e3ee8d4fb59235..0e44a34cae4f70ddbec3669ed12987f59e1e7cf8 100644 (file)
@@ -71,11 +71,8 @@ public final class FilesystemSchemaSourceCache<T extends SchemaSourceRepresentat
 
         checkSupportedRepresentation(representation);
 
-        if (!storageDirectory.exists()) {
-            checkArgument(storageDirectory.mkdirs(), "Unable to create cache directory at %s", storageDirectory);
-        }
-        checkArgument(storageDirectory.exists());
-        checkArgument(storageDirectory.isDirectory());
+        checkArgument(storageDirectory.mkdirs() || storageDirectory.isDirectory(),
+                "Unable to create cache directory at %s", storageDirectory);
         checkArgument(storageDirectory.canWrite());
         checkArgument(storageDirectory.canRead());