|
3 | 3 | //! IT IS NOT TO BE USED DIRECTLY BY THE USER! ITS API HAS NO STABILITY GUARANTEES!
|
4 | 4 |
|
5 | 5 | use std::fs::OpenOptions;
|
| 6 | +use std::os::unix::process::ExitStatusExt; |
| 7 | +use std::process::{Command, Stdio}; |
6 | 8 | use std::{
|
7 | 9 | fs::File,
|
8 | 10 | io::{self, Read, Seek, Write},
|
9 | 11 | };
|
10 | 12 |
|
11 | 13 | use aligned_vec::avec_rt;
|
12 | 14 | use interprocess::local_socket::{prelude::*, GenericFilePath};
|
13 |
| -use tracing::info; |
| 15 | +use tracing::{debug, info}; |
14 | 16 | use tracing_unwrap::ResultExt;
|
15 | 17 |
|
16 | 18 | use crate::childproc_common::child_init;
|
@@ -60,6 +62,36 @@ pub fn main() {
|
60 | 62 | }
|
61 | 63 |
|
62 | 64 | fn run(mut tx: impl FnMut(StatusMessage), args: &WriterProcessConfig) -> Result<(), ErrorType> {
|
| 65 | + if cfg!(target_os = "macos") { |
| 66 | + let mut command = Command::new("diskutil"); |
| 67 | + command |
| 68 | + .arg("unmountdisk") |
| 69 | + .arg(&args.dest) |
| 70 | + .stdin(Stdio::null()) |
| 71 | + .stdout(Stdio::piped()) |
| 72 | + .stderr(Stdio::piped()); |
| 73 | + |
| 74 | + info!(?command, "spawning process to unmount disk"); |
| 75 | + let mut child = command.spawn()?; |
| 76 | + debug!("successfully ran diskutil, waiting on child process"); |
| 77 | + |
| 78 | + let exit = child.wait()?; |
| 79 | + let mut stderr = String::new(); |
| 80 | + child.stderr.take().unwrap().read_to_string(&mut stderr)?; |
| 81 | + let mut stdout = String::new(); |
| 82 | + child.stdout.take().unwrap().read_to_string(&mut stdout)?; |
| 83 | + |
| 84 | + debug!(?exit, ?stderr, "child exited"); |
| 85 | + |
| 86 | + let exit_code = exit.into_raw(); |
| 87 | + if !exit.success() { |
| 88 | + return Err(ErrorType::FailedToUnmount { |
| 89 | + message: format!("stderr: {stderr}\nstdout: {stdout}"), |
| 90 | + exit_code, |
| 91 | + }); |
| 92 | + } |
| 93 | + } |
| 94 | + |
63 | 95 | info!("Opening file {}", args.src.to_string_lossy());
|
64 | 96 | let mut file = File::open(&args.src).unwrap_or_log();
|
65 | 97 | let size = file.seek(io::SeekFrom::End(0))?;
|
|
0 commit comments