Skip to content

Commit 84f4c1e

Browse files
committed
Prevent to execute run and reset if time machine backups.
1 parent 26d13b5 commit 84f4c1e

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod legacy_cache;
1010
mod legacy_config;
1111
mod timemachine;
1212

13+
use anyhow::anyhow;
1314
use clap::{Parser, Subcommand};
1415
use log::{error, info};
1516
use std::{backtrace::BacktraceStatus, path::Path};
@@ -104,6 +105,8 @@ fn program(cli: Cli, redirect_log_to_console: bool) -> anyhow::Result<()> {
104105
import_legacy_cache_file(&cli.legacy_cache, &cli.cache)?;
105106
match cli.command {
106107
Commands::Run { dry_run, details } => {
108+
check_for_ongoing_time_machine_backup(dry_run)?;
109+
107110
let mut cache = Cache::open_or_create(&cli.cache)?;
108111
let config = Config::load_or_create_file(&cli.config)?;
109112

@@ -116,6 +119,8 @@ fn program(cli: Cli, redirect_log_to_console: bool) -> anyhow::Result<()> {
116119
commands::list::execute(&cache, &mut std::io::stdout(), separator)
117120
}
118121
Commands::Reset { dry_run, details } => {
122+
check_for_ongoing_time_machine_backup(dry_run)?;
123+
119124
let mut cache = Cache::open_or_create(&cli.cache)?;
120125

121126
commands::reset::execute(&mut cache, dry_run, details);
@@ -145,6 +150,14 @@ fn program(cli: Cli, redirect_log_to_console: bool) -> anyhow::Result<()> {
145150
Ok(())
146151
}
147152

153+
fn check_for_ongoing_time_machine_backup(dry_run: bool) -> anyhow::Result<()> {
154+
if !dry_run && crate::timemachine::is_time_machine_running() {
155+
return Err(anyhow!("Time Machine is currently doing a backup."));
156+
}
157+
158+
Ok(())
159+
}
160+
148161
fn expand_paths(cli: &mut Cli) {
149162
cli.config = shellexpand::tilde(&cli.config).to_string();
150163
cli.cache = shellexpand::tilde(&cli.cache).to_string();

0 commit comments

Comments
 (0)