Skip to content

Commit 53297d3

Browse files
committed
fix(tracker-core): build SQLite connection options from filesystem path
SqliteConnectOptions::from_str(&format!("sqlite://{db_path}")) reinterprets the leading segment of a relative path (e.g. ./storage/...) as the URL authority, which mangles the resolved file path. Build the options directly with SqliteConnectOptions::new().filename(db_path) so the path is preserved verbatim. Addresses Copilot review item #10 on PR #1718.
1 parent 61e4427 commit 53297d3

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

  • packages/tracker-core/src/databases/driver/sqlite

packages/tracker-core/src/databases/driver/sqlite/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! The `SQLite3` database driver.
22
use std::panic::Location;
3-
use std::str::FromStr;
43

54
use ::sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
65
use ::sqlx::{Row, SqlitePool};
@@ -25,10 +24,14 @@ pub(crate) struct Sqlite {
2524
impl Sqlite {
2625
/// Instantiates a new `SQLite3` database driver.
2726
///
27+
// Keep the `Result` return for API symmetry with the MySQL driver and
28+
// forward-compatibility (future option parsing may surface fallible cases).
29+
#[allow(clippy::unnecessary_wraps)]
2830
pub fn new(db_path: &str) -> Result<Self, Error> {
29-
let options = SqliteConnectOptions::from_str(&format!("sqlite://{db_path}"))
30-
.map_err(|e| (e, DRIVER))?
31-
.create_if_missing(true);
31+
// Build the connection options directly from the filesystem path so
32+
// relative paths (e.g. `./storage/...`) are preserved verbatim instead
33+
// of being parsed as the authority component of a `sqlite://` URL.
34+
let options = SqliteConnectOptions::new().filename(db_path).create_if_missing(true);
3235

3336
let pool = SqlitePoolOptions::new().connect_lazy_with(options);
3437

0 commit comments

Comments
 (0)