Skip to content

Commit 8330f60

Browse files
ehusssyphar
authored andcommitted
Add option to mount the source directory read-write
This adds the `Command::source_dir_mount_kind` method to provide the ability to mount the source directory as read-write. This is needed for the testing that we want to do in crater to test `cargo fix` and edition migrations. This is needed because `cargo fix` inherently needs to modify the source directory.
1 parent 2ccfee3 commit 8330f60

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/cmd/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub struct Command<'w, 'pl> {
211211
no_output_timeout: Option<Duration>,
212212
log_command: bool,
213213
log_output: bool,
214+
source_dir_mount_kind: MountKind,
214215
}
215216

216217
impl<'w, 'pl> Command<'w, 'pl> {
@@ -261,6 +262,7 @@ impl<'w, 'pl> Command<'w, 'pl> {
261262
no_output_timeout,
262263
log_output: true,
263264
log_command: true,
265+
source_dir_mount_kind: MountKind::ReadOnly,
264266
}
265267
}
266268

@@ -352,6 +354,22 @@ impl<'w, 'pl> Command<'w, 'pl> {
352354
self
353355
}
354356

357+
/// Sets how the source directory is mounted.
358+
///
359+
/// The default mount kind is read-only.
360+
///
361+
/// ## Security
362+
///
363+
/// Be sure you understand the implications of setting this. If you set
364+
/// this to read-write, and the source directory may potentially be
365+
/// reused, then subsequent invocations may see those changes. Beware of
366+
/// trusting those previous invocations or the contents of the source
367+
/// directory.
368+
pub fn source_dir_mount_kind(mut self, mount_kind: MountKind) -> Self {
369+
self.source_dir_mount_kind = mount_kind;
370+
self
371+
}
372+
355373
/// Run the prepared command and return an error if it fails (for example with a non-zero exit
356374
/// code or a timeout).
357375
pub fn run(self) -> Result<(), CommandError> {
@@ -393,7 +411,11 @@ impl<'w, 'pl> Command<'w, 'pl> {
393411
};
394412

395413
builder = builder
396-
.mount(&source_dir, &container_dirs::WORK_DIR, MountKind::ReadOnly)
414+
.mount(
415+
&source_dir,
416+
&container_dirs::WORK_DIR,
417+
self.source_dir_mount_kind,
418+
)
397419
.env("SOURCE_DIR", container_dirs::WORK_DIR.to_str().unwrap())
398420
.workdir(container_dirs::WORK_DIR.to_str().unwrap())
399421
.cmd(cmd);

0 commit comments

Comments
 (0)