fix: resolve path ownership problems when using sqlx_macros_unstable (#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
This commit is contained in:
Lílian 2024-05-31 01:46:14 +03:00 committed by GitHub
parent 0449ac5c1f
commit 6c1e3a4e61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -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<Vec<(Migration, PathBuf)>, ResolveError> {
let mut s = fs::read_dir(&path).map_err(|e| ResolveError {
pub fn resolve_blocking(path: &Path) -> Result<Vec<(Migration, PathBuf)>, ResolveError> {
let mut s = fs::read_dir(path).map_err(|e| ResolveError {
message: format!("error reading migration directory {}: {e}", path.display()),
source: Some(e),
})?;

View File

@ -103,7 +103,7 @@ pub(crate) fn expand_migrator(path: &Path) -> crate::Result<TokenStream> {
})?;
// 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 });