Skip to content

Commit

Permalink
Merge pull request #561 from amazonlinux/migrator-chmod
Browse files Browse the repository at this point in the history
migrator: Set migrations executable before running
  • Loading branch information
etungsten authored Nov 22, 2019
2 parents 585d001 + 19fbc30 commit af524a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit af524a1

Please sign in to comment.