Skip to content

Commit b78875a

Browse files
authored
Merge pull request #228 from OP-Engineering/oscar/fix-location-in-android
2 parents caf91de + e471c19 commit b78875a

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

cpp/bindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void install(jsi::Runtime &rt,
9090
return false;
9191
#endif
9292
});
93-
93+
9494
auto is_ios_embedded = HOST_STATIC_FN("isIOSEmbedded") {
9595
#ifdef OP_SQLITE_USE_PHONE_VERSION
9696
return true;

cpp/bridge.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ std::string opsqlite_get_db_path(std::string const &db_name,
6767
if (location == ":memory:") {
6868
return location;
6969
}
70-
char resolved_location[PATH_MAX];
71-
realpath(location.c_str(), resolved_location);
72-
std::string resolved_location_string = std::string(resolved_location);
7370

7471
// Will return false if the directory already exists, no need to check
75-
std::filesystem::create_directories(resolved_location);
72+
std::filesystem::create_directories(location);
7673

77-
return resolved_location_string + "/" + db_name;
74+
if (!location.empty() && location.back() != '/') {
75+
return location + "/" + db_name;
76+
}
77+
78+
return location + db_name;
7879
}
7980

8081
#ifdef OP_SQLITE_USE_SQLCIPHER

cpp/libsql/bridge.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ std::string opsqlite_get_db_path(std::string const &db_name,
2626
return location;
2727
}
2828

29-
char resolved_location[PATH_MAX];
30-
realpath(location.c_str(), resolved_location);
31-
std::string resolved_location_string = std::string(resolved_location);
32-
3329
// Will return false if the directory already exists, no need to check
34-
std::filesystem::create_directories(resolved_location);
30+
std::filesystem::create_directories(location);
31+
32+
if (!location.empty() && location.back() != '/') {
33+
return location + "/" + db_name;
34+
}
3535

36-
return resolved_location_string + "/" + db_name;
36+
return location + db_name;
3737
}
3838

3939
DB opsqlite_libsql_open_sync(std::string const &name,

example/src/tests/dbsetup.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ export function dbSetupTests() {
122122
db.delete();
123123
});
124124

125+
it('Should create db in custom folder', async () => {
126+
let db = open({
127+
name: 'customFolderTest.sqlite',
128+
encryptionKey: 'test',
129+
location: 'myFolder',
130+
});
131+
132+
db.delete();
133+
});
134+
125135
it('Moves assets database simple', async () => {
126136
const copied = await moveAssetsDatabase({filename: 'sample.sqlite'});
127137

0 commit comments

Comments
 (0)