From e4ce28aaa8d42d16635b3c6d01f611f06754495a Mon Sep 17 00:00:00 2001 From: Markus Pettersson Date: Fri, 13 Dec 2024 08:49:04 +0100 Subject: [PATCH] WIP Add better APIs for making shh:ed files executable --- test/test-manager/src/vm/provision.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/test-manager/src/vm/provision.rs b/test/test-manager/src/vm/provision.rs index 60d10b36463d..0e32c9528584 100644 --- a/test/test-manager/src/vm/provision.rs +++ b/test/test-manager/src/vm/provision.rs @@ -187,6 +187,18 @@ fn ssh_send_file + Copy>( session: &Session, source: P, dest_dir: &Path, +) -> Result { + 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 + Copy>( + session: &Session, + source: P, + dest_dir: &Path, + opts: FileOpts, ) -> Result { let dest = dest_dir.join( source @@ -205,7 +217,10 @@ fn ssh_send_file + 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) } @@ -221,6 +236,14 @@ fn ssh_write>(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 { // Make sure that the script is executable! let mut file_stat = file.stat()?;