Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
Fixed #1691 - Database.getPath has return type as File which is diffe…
Browse files Browse the repository at this point in the history
…rent from other platforms (#1692)
  • Loading branch information
Hideki Itakura authored Apr 2, 2018
1 parent ad4a554 commit 8dd6674
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ private Database openDatabase(String dbName, boolean countCheck) throws Couchbas
config.setDirectory(getDir().getAbsolutePath());
Database db = new Database(dbName, config);
assertEquals(dbName, db.getName());
assertTrue(db.getPath().getAbsolutePath().endsWith(".cblite2"));
assertTrue(new File(db.getPath()).getAbsolutePath().endsWith(".cblite2"));
if (countCheck)
assertEquals(0, db.getCount());
return db;
}

// helper method to delete database
void deleteDatabase(Database db) throws CouchbaseLiteException {
File path = db.getPath();
File path = db.getPath() != null ? new File(db.getPath()) : null;
// if path is null, db is already closed
if (path != null)
assertTrue(path.exists());
Expand Down Expand Up @@ -193,7 +193,7 @@ public void testDatabaseConfigurationWithAndroidContect() throws CouchbaseLiteEx
Database db = new Database("db", config);
try {
String expectedPath = context.getFilesDir().getAbsolutePath();
assertTrue(db.getPath().getAbsolutePath().contains(expectedPath));
assertTrue(new File(db.getPath()).getAbsolutePath().contains(expectedPath));
} finally {
db.delete();
}
Expand Down Expand Up @@ -271,8 +271,8 @@ public void testCreateWithCustomDirectory() throws CouchbaseLiteException {
try {
assertNotNull(db);
assertEquals(dbName, db.getName());
assertTrue(db.getPath().getAbsolutePath().endsWith(".cblite2"));
assertTrue(db.getPath().getAbsolutePath().indexOf(dir.getPath()) != -1);
assertTrue(new File(db.getPath()).getAbsolutePath().endsWith(".cblite2"));
assertTrue(new File(db.getPath()).getAbsolutePath().indexOf(dir.getPath()) != -1);
assertTrue(Database.exists(dbName, dir));
assertEquals(0, db.getCount());
} finally {
Expand Down Expand Up @@ -941,7 +941,7 @@ public void testDelete() throws CouchbaseLiteException {
@Test
public void testDeleteTwice() throws CouchbaseLiteException {
// delete db twice
File path = db.getPath();
File path = new File(db.getPath());
assertTrue(path.exists());
db.delete();
try {
Expand Down Expand Up @@ -1051,7 +1051,7 @@ public void testDeleteWithDefaultDirDB() throws CouchbaseLiteException {
String dbName = "db";
try {
Database database = open(dbName);
File path = database.getPath();
File path = new File(database.getPath());
assertNotNull(path);
assertTrue(path.exists());
// close db before delete
Expand All @@ -1077,7 +1077,7 @@ public void testDeleteOpeningDBWithDefaultDir() throws CouchbaseLiteException {
// create db with custom directory
Database db = openDatabase(dbName);
try {
File path = db.getPath();
File path = new File(db.getPath());
assertNotNull(path);
assertTrue(path.exists());

Expand All @@ -1101,7 +1101,7 @@ public void testDeleteByStaticMethod() throws CouchbaseLiteException {

// create db with custom directory
Database db = openDatabase(dbName);
File path = db.getPath();
File path = new File(db.getPath());

// close db before delete
db.close();
Expand Down Expand Up @@ -1175,7 +1175,7 @@ public void testDatabaseExistsWithDir() throws CouchbaseLiteException {

// create db with custom directory
Database db = openDatabase("db");
File path = db.getPath();
File path = new File(db.getPath());

assertTrue(Database.exists("db", getDir()));

Expand Down Expand Up @@ -1322,7 +1322,7 @@ public void testCopy() throws CouchbaseLiteException {
Database.delete(dbName, dir);

// Copy:
Database.copy(db.getPath(), dbName, config);
Database.copy(new File(db.getPath()), dbName, config);

// Verify:
assertTrue(Database.exists(dbName, dir));
Expand Down
13 changes: 9 additions & 4 deletions shared/src/main/java/com/couchbase/lite/AbstractDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ public String getName() {
*
* @return the database's path.
*/
public File getPath() {
public String getPath() {
synchronized (lock) {
return c4db != null ? new File(getC4Database().getPath()) : null;
return c4db != null ? getC4Database().getPath() : null;
}
}

Expand Down Expand Up @@ -660,8 +660,8 @@ Object getLock() {

boolean equalsWithPath(Database other) {
if (other == null) return false;
File path = getPath();
File otherPath = other.getPath();
File path = getFilePath();
File otherPath = other.getFilePath();
if (path == null && otherPath == null)
return true;
else if ((path == null && otherPath != null) || (path != null && otherPath == null))
Expand Down Expand Up @@ -779,6 +779,11 @@ ScheduledExecutorService getQueryExecutor() {
return queryExecutor;
}

File getFilePath() {
String path = getPath();
return path != null ? new File(path) : null;
}

//---------------------------------------------
// Private (in class only)
//---------------------------------------------
Expand Down

0 comments on commit 8dd6674

Please sign in to comment.