From 8663b42dfe8b5f1c27fa37591903d23f447e7d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=ADlian=20Ferreira=20de=20Freitas?= Date: Mon, 20 May 2024 01:20:48 +0300 Subject: [PATCH 1/2] fix: make resolve_blocking not take ownership of path When using sqlx_macros_unstable the codepath taken further uses the path variable and it is more convenient to not take ownership but instead pass references to needed functions. --- sqlx-core/src/migrate/source.rs | 6 +++--- sqlx-macros-core/src/migrate.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sqlx-core/src/migrate/source.rs b/sqlx-core/src/migrate/source.rs index a4727aed7c..6064f26cd8 100644 --- a/sqlx-core/src/migrate/source.rs +++ b/sqlx-core/src/migrate/source.rs @@ -31,7 +31,7 @@ impl<'s> MigrationSource<'s> for &'s Path { Box::pin(async move { let canonical = self.canonicalize()?; let migrations_with_paths = - crate::rt::spawn_blocking(move || resolve_blocking(canonical)).await?; + crate::rt::spawn_blocking(move || resolve_blocking(&canonical)).await?; Ok(migrations_with_paths.into_iter().map(|(m, _p)| m).collect()) }) @@ -54,8 +54,8 @@ pub struct ResolveError { // FIXME: paths should just be part of `Migration` but we can't add a field backwards compatibly // since it's `#[non_exhaustive]`. -pub fn resolve_blocking(path: PathBuf) -> Result, ResolveError> { - let mut s = fs::read_dir(&path).map_err(|e| ResolveError { +pub fn resolve_blocking(path: &PathBuf) -> Result, ResolveError> { + let mut s = fs::read_dir(path).map_err(|e| ResolveError { message: format!("error reading migration directory {}: {e}", path.display()), source: Some(e), })?; diff --git a/sqlx-macros-core/src/migrate.rs b/sqlx-macros-core/src/migrate.rs index a554dfe1cd..0836e6f1dd 100644 --- a/sqlx-macros-core/src/migrate.rs +++ b/sqlx-macros-core/src/migrate.rs @@ -103,7 +103,7 @@ pub(crate) fn expand_migrator(path: &Path) -> crate::Result { })?; // Use the same code path to resolve migrations at compile time and runtime. - let migrations = sqlx_core::migrate::resolve_blocking(path)? + let migrations = sqlx_core::migrate::resolve_blocking(&path)? .into_iter() .map(|(migration, path)| QuoteMigration { migration, path }); From c3682a41acb99e4f61aafdfe20f750923d82a245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=ADlian=20Ferreira=20de=20Freitas?= Date: Tue, 21 May 2024 17:00:18 +0300 Subject: [PATCH 2/2] fix: change &PathBuf to &Path in resolve_blocking --- sqlx-core/src/migrate/source.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-core/src/migrate/source.rs b/sqlx-core/src/migrate/source.rs index 6064f26cd8..660b3cfea4 100644 --- a/sqlx-core/src/migrate/source.rs +++ b/sqlx-core/src/migrate/source.rs @@ -54,7 +54,7 @@ pub struct ResolveError { // FIXME: paths should just be part of `Migration` but we can't add a field backwards compatibly // since it's `#[non_exhaustive]`. -pub fn resolve_blocking(path: &PathBuf) -> Result, ResolveError> { +pub fn resolve_blocking(path: &Path) -> Result, ResolveError> { let mut s = fs::read_dir(path).map_err(|e| ResolveError { message: format!("error reading migration directory {}: {e}", path.display()), source: Some(e),