Skip to content

Commit 85ef600

Browse files
authored
SetTmutilExclusion: ignore failures to add or remove exclusions caused by signal 9 (#1438)
This is probably maybe caused by a macOS policy disabling TimeMachine.
1 parent 334c53e commit 85ef600

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

src/action/macos/set_tmutil_exclusion.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::os::unix::process::ExitStatusExt as _;
12
use std::path::{Path, PathBuf};
23

34
use tokio::process::Command;
@@ -67,17 +68,28 @@ impl Action for SetTmutilExclusion {
6768

6869
#[tracing::instrument(level = "debug", skip_all)]
6970
async fn execute(&mut self) -> Result<(), ActionError> {
70-
execute_command(
71+
let tmutil_ret = execute_command(
7172
Command::new("tmutil")
7273
.process_group(0)
7374
.arg("addexclusion")
7475
.arg(&self.path)
7576
.stdin(std::process::Stdio::null()),
7677
)
77-
.await
78-
.map_err(Self::error)?;
79-
80-
Ok(())
78+
.await;
79+
80+
match tmutil_ret {
81+
Ok(_) => Ok(()),
82+
Err(err) => {
83+
if let crate::action::ActionErrorKind::CommandOutput { ref output, .. } = err {
84+
if output.status.signal() == Some(9) {
85+
tracing::debug!(%err, "tmutil failed because it was killed with signal 9; ignoring");
86+
return Ok(());
87+
}
88+
}
89+
90+
Err(Self::error(err))?
91+
},
92+
}
8193
}
8294

8395
fn revert_description(&self) -> Vec<ActionDescription> {
@@ -86,16 +98,27 @@ impl Action for SetTmutilExclusion {
8698

8799
#[tracing::instrument(level = "debug", skip_all)]
88100
async fn revert(&mut self) -> Result<(), ActionError> {
89-
execute_command(
101+
let tmutil_ret = execute_command(
90102
Command::new("tmutil")
91103
.process_group(0)
92104
.arg("removeexclusion")
93105
.arg(&self.path)
94106
.stdin(std::process::Stdio::null()),
95107
)
96-
.await
97-
.map_err(Self::error)?;
98-
99-
Ok(())
108+
.await;
109+
110+
match tmutil_ret {
111+
Ok(_) => Ok(()),
112+
Err(err) => {
113+
if let crate::action::ActionErrorKind::CommandOutput { ref output, .. } = err {
114+
if output.status.signal() == Some(9) {
115+
tracing::debug!(%err, "tmutil failed because it was killed with signal 9; ignoring");
116+
return Ok(());
117+
}
118+
}
119+
120+
Err(Self::error(err))?
121+
},
122+
}
100123
}
101124
}

0 commit comments

Comments
 (0)