From 115fa3151b122cff49c48dc226a594669d1860af Mon Sep 17 00:00:00 2001 From: Tim Geoghegan Date: Wed, 5 Apr 2023 08:48:54 -0700 Subject: [PATCH 1/2] Traverse symlinks when resolving migrations When enumerating the source directory seeking migration files, `sqlx` ignores entries that aren't files. This was previously reported as #614 and fixed in #985 but apparently regressed somewhere along the way. This commit reintroduces the fix from #985 to the current implementation: use `std::fs::metadata` instead of `std::fs::DirEntry::metadata`. The former is documented to traverse symlinks; the latter does not. --- sqlx-core/src/migrate/source.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sqlx-core/src/migrate/source.rs b/sqlx-core/src/migrate/source.rs index 609f4fdeaa..10a18b365b 100644 --- a/sqlx-core/src/migrate/source.rs +++ b/sqlx-core/src/migrate/source.rs @@ -24,7 +24,8 @@ impl<'s> MigrationSource<'s> for &'s Path { let mut migrations = Vec::new(); while let Some(entry) = s.next().await? { - if !entry.metadata.is_file() { + // std::fs::metadata traverses symlinks + if !std::fs::metadata(&entry.path)?.is_file() { // not a file; ignore continue; } From 1b706c4725efc97972baa8af424ef42cbb983235 Mon Sep 17 00:00:00 2001 From: Tim Geoghegan Date: Mon, 15 May 2023 11:16:59 -0700 Subject: [PATCH 2/2] add migrations_symlink test --- tests/migrate/macro.rs | 3 +++ tests/migrate/migrations_symlink | 1 + 2 files changed, 4 insertions(+) create mode 120000 tests/migrate/migrations_symlink diff --git a/tests/migrate/macro.rs b/tests/migrate/macro.rs index da7f901996..03cb578f7f 100644 --- a/tests/migrate/macro.rs +++ b/tests/migrate/macro.rs @@ -3,15 +3,18 @@ use std::path::Path; static EMBEDDED_SIMPLE: Migrator = sqlx::migrate!("tests/migrate/migrations_simple"); static EMBEDDED_REVERSIBLE: Migrator = sqlx::migrate!("tests/migrate/migrations_reversible"); +static EMBEDDED_SYMLINK: Migrator = sqlx::migrate!("tests/migrate/migrations_symlink"); #[sqlx_macros::test] async fn same_output() -> anyhow::Result<()> { let runtime_simple = Migrator::new(Path::new("tests/migrate/migrations_simple")).await?; let runtime_reversible = Migrator::new(Path::new("tests/migrate/migrations_reversible")).await?; + let runtime_symlink = Migrator::new(Path::new("tests/migrate/migrations_symlink")).await?; assert_same(&EMBEDDED_SIMPLE, &runtime_simple); assert_same(&EMBEDDED_REVERSIBLE, &runtime_reversible); + assert_same(&EMBEDDED_SYMLINK, &runtime_symlink); Ok(()) } diff --git a/tests/migrate/migrations_symlink b/tests/migrate/migrations_symlink new file mode 120000 index 0000000000..433d94398c --- /dev/null +++ b/tests/migrate/migrations_symlink @@ -0,0 +1 @@ +migrations_simple \ No newline at end of file