Skip to content

Commit

Permalink
WIP Add better APIs for making shh:ed files executable
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Dec 13, 2024
1 parent b31b711 commit e4ce28a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion test/test-manager/src/vm/provision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ fn ssh_send_file<P: AsRef<Path> + Copy>(
session: &Session,
source: P,
dest_dir: &Path,
) -> Result<PathBuf> {
ssh_send_file_with_opts(session, source, dest_dir, FileOpts::default())
}

/// Copy a `source` file to `dest_dir` in the test runner with opts.
///
/// Returns the absolute path in the test runner where the file is stored.
fn ssh_send_file_with_opts<P: AsRef<Path> + Copy>(
session: &Session,
source: P,
dest_dir: &Path,
opts: FileOpts,
) -> Result<PathBuf> {
let dest = dest_dir.join(
source
Expand All @@ -205,7 +217,10 @@ fn ssh_send_file<P: AsRef<Path> + Copy>(
.with_context(|| format!("Failed to open file at {}", source.as_ref().display()))?;

let remote_file = ssh_write(session, &dest, &source[..])?;
make_executable(remote_file)?;

if opts.executable {
make_executable(remote_file)?;
}

Ok(dest)
}
Expand All @@ -221,6 +236,14 @@ fn ssh_write<P: AsRef<Path>>(session: &Session, dest: P, mut source: impl Read)
Ok(remote_file)
}

/// Extra options that may be necessary to configure for files written to the test runner VM.
/// Used in conjunction with the `ssh_*_with_opts` functions.
#[derive(Clone, Copy, Debug, Default)]
struct FileOpts {
/// If file should be executable.
executable: bool,
}

fn make_executable(mut file: File) -> Result<File> {
// Make sure that the script is executable!
let mut file_stat = file.stat()?;
Expand Down

0 comments on commit e4ce28a

Please sign in to comment.