Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrator: Set migrations executable before running #561

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions workspaces/api/migration/migrator/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub(crate) enum Error {
#[snafu(display("Failed reading metadata of '{}': {}", path.display(), source))]
PathMetadata { path: PathBuf, source: io::Error },

#[snafu(display("Failed setting permissions of '{}': {}", path.display(), source))]
SetPermissions { path: PathBuf, source: io::Error },

#[snafu(display("Migration path '{}' contains invalid UTF-8", path.display()))]
MigrationNameNotUTF8 { path: PathBuf },

Expand Down
11 changes: 9 additions & 2 deletions workspaces/api/migration/migrator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use regex::Regex;
use simplelog::{Config as LogConfig, TermLogger, TerminalMode};
use snafu::{ensure, OptionExt, ResultExt};
use std::env;
use std::fs;
use std::os::unix::fs::symlink;
use std::fs::{self, Permissions};
use std::os::unix::fs::{symlink, PermissionsExt};
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use std::process::{self, Command};
Expand Down Expand Up @@ -310,6 +310,13 @@ where
P2: AsRef<Path>,
{
for migration in migrations {
// Ensure the migration is executable.
fs::set_permissions(migration.as_ref(), Permissions::from_mode(0o755)).context(
error::SetPermissions {
path: migration.as_ref(),
},
)?;

let mut command = Command::new(migration.as_ref());

// Point each migration in the right direction, and at the given data store.
Expand Down