@@ -384,6 +384,41 @@ static boolean isFileOpenSync(String canonicalPath, boolean runFinalization) {
384
384
}
385
385
}
386
386
387
+ /**
388
+ * Using an Android Context and an optional database name, as configured with {@link BoxStoreBuilder#name(String)},
389
+ * checks if the associated database files are in use by a BoxStore instance.
390
+ * <p>
391
+ * Use this to check that database files are not open before copying or deleting them.
392
+ */
393
+ public static boolean isDatabaseOpen (Object context , @ Nullable String dbNameOrNull ) throws IOException {
394
+ File dbDir = BoxStoreBuilder .getAndroidDbDir (context , dbNameOrNull );
395
+ return isFileOpen (dbDir .getCanonicalPath ());
396
+ }
397
+
398
+ /**
399
+ * Using an optional base directory, as configured with {@link BoxStoreBuilder#baseDirectory(File)},
400
+ * and an optional database name, as configured with {@link BoxStoreBuilder#name(String)},
401
+ * checks if the associated database files are in use by a BoxStore instance.
402
+ * <p>
403
+ * Use this to check that database files are not open before copying or deleting them.
404
+ */
405
+ public static boolean isDatabaseOpen (@ Nullable File baseDirectoryOrNull ,
406
+ @ Nullable String dbNameOrNull ) throws IOException {
407
+
408
+ File dbDir = BoxStoreBuilder .getDbDir (baseDirectoryOrNull , dbNameOrNull );
409
+ return isFileOpen (dbDir .getCanonicalPath ());
410
+ }
411
+
412
+ /**
413
+ * Using a directory, as configured with {@link BoxStoreBuilder#directory(File)},
414
+ * checks if the associated database files are in use by a BoxStore instance.
415
+ * <p>
416
+ * Use this to check that database files are not open before copying or deleting them.
417
+ */
418
+ public static boolean isDatabaseOpen (File directory ) throws IOException {
419
+ return isFileOpen (directory .getCanonicalPath ());
420
+ }
421
+
387
422
/**
388
423
* The size in bytes occupied by the data file on disk.
389
424
*
0 commit comments