Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions src/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,24 +634,22 @@ impl Rclone {
Ok(())
}

pub fn sync(
fn sync_args(
&self,
local: &StrictPath,
remote_path: &str,
direction: SyncDirection,
finality: Finality,
game_dirs: &[String],
) -> Result<RcloneProcess, CommandError> {
if direction == SyncDirection::Upload && !local.exists() {
// Rclone will fail with exit code 3 if the local folder does not exist.
_ = local.create_dirs();
}

) -> Vec<String> {
let mut args = vec![
"sync".to_string(),
"-v".to_string(),
"--use-json-log".to_string(),
"--stats=100ms".to_string(),
// Terminal progress output is incompatible with the JSON log parser.
// A command-line value also overrides RCLONE_PROGRESS.
"--progress=false".to_string(),
];

if finality.preview() {
Expand All @@ -674,10 +672,60 @@ impl Rclone {
}
}

args
}

pub fn sync(
&self,
local: &StrictPath,
remote_path: &str,
direction: SyncDirection,
finality: Finality,
game_dirs: &[String],
) -> Result<RcloneProcess, CommandError> {
if direction == SyncDirection::Upload && !local.exists() {
// Rclone will fail with exit code 3 if the local folder does not exist.
_ = local.create_dirs();
}

let args = self.sync_args(local, remote_path, direction, finality, game_dirs);
RcloneProcess::launch(self.app.path.raw().into(), self.args(&args))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn sync_disables_terminal_progress_after_custom_arguments() {
let rclone = Rclone::new(
App {
path: StrictPath::new("rclone".to_string()),
arguments: "--progress".to_string(),
},
Remote::Custom {
id: "cloud".to_string(),
},
);

let sync_args = rclone.sync_args(
&StrictPath::new("local".to_string()),
"backups",
SyncDirection::Upload,
Finality::Final,
&[],
);
let args = rclone.args(&sync_args);

assert!(args.contains(&"--use-json-log".to_string()));
assert!(args.contains(&"--stats=100ms".to_string()));
let progress = args.iter().position(|x| x == "--progress").unwrap();
let no_progress = args.iter().position(|x| x == "--progress=false").unwrap();
assert!(progress < no_progress);
}
}

#[cfg(feature = "app")]
pub mod rclone_monitor {
use iced::{
Expand Down
Loading