Skip to content

Commit

Permalink
fix(core.runtime): getDatabasePath支持传绝对路径
Browse files Browse the repository at this point in the history
  • Loading branch information
shifujun committed Apr 22, 2024
1 parent 4880701 commit ee7ab99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ public boolean deleteDatabase(String name) {

@Override
public File getDatabasePath(String name) {
if (getSubDirName() == null) {
if (getSubDirName() == null
|| name.charAt(0) == File.separatorChar) {
return super.getDatabasePath(name);
} else {
return super.getDatabasePath(makeSubName(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ public void testGetDatabasePath() {
"TAG_GET_DATABASE_PATH_BAR",
hostDatabasePath + "/" + EXPECT_NAME + "_bar"
);
matchTextWithViewTag(
"TAG_GET_DATABASE_ABSOLUTE_PATH_FOO_BAR",
"/foo/bar"
);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ protected void fillTestValues(Context testContext) {
testContext.getDatabasePath("bar").getAbsolutePath()
);

// 传绝对路径给getDatabasePath应该返回路径不变的文件
makeItem("getDatabasePath(\"/foo/bar\")", "TAG_GET_DATABASE_ABSOLUTE_PATH_FOO_BAR",
testContext.getDatabasePath("/foo/bar").getAbsolutePath()
);


Context hostContext = getApplication().getBaseContext();
hostContext.openOrCreateDatabase("foo", MODE_PRIVATE, null);
Expand Down

0 comments on commit ee7ab99

Please sign in to comment.