Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 23d52d9

Browse files
lily-mosquitoesjrasanen
authored andcommittedOct 14, 2024
fix: resolve path ownership problems when using sqlx_macros_unstable (launchbadge#3236)
* 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. * fix: change &PathBuf to &Path in resolve_blocking
1 parent 1faef65 commit 23d52d9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
 

‎sqlx-core/src/migrate/source.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'s> MigrationSource<'s> for &'s Path {
3131
Box::pin(async move {
3232
let canonical = self.canonicalize()?;
3333
let migrations_with_paths =
34-
crate::rt::spawn_blocking(move || resolve_blocking(canonical)).await?;
34+
crate::rt::spawn_blocking(move || resolve_blocking(&canonical)).await?;
3535

3636
Ok(migrations_with_paths.into_iter().map(|(m, _p)| m).collect())
3737
})
@@ -54,8 +54,8 @@ pub struct ResolveError {
5454

5555
// FIXME: paths should just be part of `Migration` but we can't add a field backwards compatibly
5656
// since it's `#[non_exhaustive]`.
57-
pub fn resolve_blocking(path: PathBuf) -> Result<Vec<(Migration, PathBuf)>, ResolveError> {
58-
let mut s = fs::read_dir(&path).map_err(|e| ResolveError {
57+
pub fn resolve_blocking(path: &Path) -> Result<Vec<(Migration, PathBuf)>, ResolveError> {
58+
let mut s = fs::read_dir(path).map_err(|e| ResolveError {
5959
message: format!("error reading migration directory {}: {e}", path.display()),
6060
source: Some(e),
6161
})?;

‎sqlx-macros-core/src/migrate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub(crate) fn expand_migrator(path: &Path) -> crate::Result<TokenStream> {
103103
})?;
104104

105105
// Use the same code path to resolve migrations at compile time and runtime.
106-
let migrations = sqlx_core::migrate::resolve_blocking(path)?
106+
let migrations = sqlx_core::migrate::resolve_blocking(&path)?
107107
.into_iter()
108108
.map(|(migration, path)| QuoteMigration { migration, path });
109109

0 commit comments

Comments
 (0)