diff --git a/.changeset/cli-migrate-module-cfg.md b/.changeset/cli-migrate-module-cfg.md new file mode 100644 index 00000000..74b6c721 --- /dev/null +++ b/.changeset/cli-migrate-module-cfg.md @@ -0,0 +1,4 @@ +--- +--- + +The migration module is gated by platform, so the CLI builds where the copy cannot run (#1121) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index d59da805..54598ac7 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -296,6 +296,8 @@ jobs: persist-credentials: false - name: Install Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1.17.0 + - name: Format, which covers the file Linux cannot reach + run: cargo fmt --all --check - name: CLI builds on Windows run: cargo build -p nostream-cli --no-default-features - name: CLI refuses the migration on Windows diff --git a/crates/nostream-cli/src/commands/migrate.rs b/crates/nostream-cli/src/commands/migrate.rs index 2fd5d685..30d8e3bd 100644 --- a/crates/nostream-cli/src/commands/migrate.rs +++ b/crates/nostream-cli/src/commands/migrate.rs @@ -112,16 +112,6 @@ pub fn run(options: MigrateOptions, out: &mut dyn Write) -> Result Result { - writeln!(out, "migrate pg-to-lmdb is unsupported on this platform") - .map_err(|e| CliError::Migrate(e.to_string()))?; - Ok(CommandOutput { - lines: Vec::new(), - exit_code: 1, - }) -} - /// The copy over an injected source, target and writer, which is how the whole run is tested /// without a process and without a database. /// diff --git a/crates/nostream-cli/src/commands/migrate_unsupported.rs b/crates/nostream-cli/src/commands/migrate_unsupported.rs new file mode 100644 index 00000000..6f22619c --- /dev/null +++ b/crates/nostream-cli/src/commands/migrate_unsupported.rs @@ -0,0 +1,38 @@ +//! `migrate pg-to-lmdb` where the copy cannot run. +//! +//! The copy reads and writes Unix file modes, refuses a target by its owner's uid and reads the +//! caller's from `/proc/self/status`, so the whole command lives in `migrate.rs` behind +//! `cfg(unix)`. The command still has to exist everywhere — a `main.rs` that cannot name it would +//! need its own `cfg` arm — so this module supplies the same `MigrateOptions` and a `run` that +//! refuses with the reason, which is what an operator on another platform needs to read. + +use std::io::Write; +use std::path::PathBuf; + +use crate::config::CommandOutput; +use crate::error::CliError; + +/// The options one run carries. Kept in step with `migrate::MigrateOptions`, which is the arm +/// that uses them. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct MigrateOptions { + /// The store root: the environment is `/lmdb`, the manifest `/migration-manifest.json`. + pub target: PathBuf, + /// Rows per batch, which is also the page size verify reads with. + pub batch_size: usize, + /// Verify the target against its manifest and copy nothing. + pub verify: bool, +} + +/// `migrate pg-to-lmdb`: refused, naming the platform as the reason and answering exit code 1. +/// +/// `migrate_cli_unsupported.rs` pins the line and the code, and the `windows-latest` job in +/// `checks.yml` runs it there. +pub fn run(_options: MigrateOptions, out: &mut dyn Write) -> Result { + writeln!(out, "migrate pg-to-lmdb is unsupported on this platform") + .map_err(|e| CliError::Migrate(e.to_string()))?; + Ok(CommandOutput { + lines: Vec::new(), + exit_code: 1, + }) +} diff --git a/crates/nostream-cli/src/commands/mod.rs b/crates/nostream-cli/src/commands/mod.rs index 645c0dc8..b463b262 100644 --- a/crates/nostream-cli/src/commands/mod.rs +++ b/crates/nostream-cli/src/commands/mod.rs @@ -7,6 +7,12 @@ pub mod export; pub mod import; pub mod info; pub mod invite; +/// The copy needs Unix file modes, so the whole command is Unix-only and the other platform +/// gets a refusal with the same option type, which is what keeps `main.rs` free of a `cfg` arm. +#[cfg(unix)] +pub mod migrate; +#[cfg(not(unix))] +#[path = "migrate_unsupported.rs"] pub mod migrate; pub mod seed; pub mod setup;