Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use realpath to resolve location #228

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void install(jsi::Runtime &rt,
return false;
#endif
});

auto is_ios_embedded = HOST_STATIC_FN("isIOSEmbedded") {
#ifdef OP_SQLITE_USE_PHONE_VERSION
return true;
Expand Down
11 changes: 6 additions & 5 deletions cpp/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ std::string opsqlite_get_db_path(std::string const &db_name,
if (location == ":memory:") {
return location;
}
char resolved_location[PATH_MAX];
realpath(location.c_str(), resolved_location);
std::string resolved_location_string = std::string(resolved_location);

// Will return false if the directory already exists, no need to check
std::filesystem::create_directories(resolved_location);
std::filesystem::create_directories(location);

return resolved_location_string + "/" + db_name;
if (!location.empty() && location.back() != '/') {
return location + "/" + db_name;
}

return location + db_name;
}

#ifdef OP_SQLITE_USE_SQLCIPHER
Expand Down
12 changes: 6 additions & 6 deletions cpp/libsql/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ std::string opsqlite_get_db_path(std::string const &db_name,
return location;
}

char resolved_location[PATH_MAX];
realpath(location.c_str(), resolved_location);
std::string resolved_location_string = std::string(resolved_location);

// Will return false if the directory already exists, no need to check
std::filesystem::create_directories(resolved_location);
std::filesystem::create_directories(location);

if (!location.empty() && location.back() != '/') {
return location + "/" + db_name;
}

return resolved_location_string + "/" + db_name;
return location + db_name;
}

DB opsqlite_libsql_open_sync(std::string const &name,
Expand Down
10 changes: 10 additions & 0 deletions example/src/tests/dbsetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ export function dbSetupTests() {
db.delete();
});

it('Should create db in custom folder', async () => {
let db = open({
name: 'customFolderTest.sqlite',
encryptionKey: 'test',
location: 'myFolder',
});

db.delete();
});

it('Moves assets database simple', async () => {
const copied = await moveAssetsDatabase({filename: 'sample.sqlite'});

Expand Down
Loading