Merge pull request 'Add pure flag to upload command' (#24) from 22-upload-pure-flag into master

Reviewed-on: https://stupstech.de/dev/Mr_Steppy/multi-ssh/pulls/24
This commit is contained in:
Leonard Steppy 2025-02-03 15:37:14 +01:00
commit 93eed1dc7f

View File

@ -75,7 +75,7 @@ enum Command {
#[arg(short = 'a', long, default_value = "delete", default_missing_value = "archive", num_args = 0..=1)]
old_version_policy: OldVersionPolicy,
/// The directory where to upload to, relative to the server directory
#[arg(short = 'p', long, default_value = "plugins")]
#[arg(short = 'd', long, default_value = "plugins")]
upload_directory: PathBuf,
/// Skip the confirmation dialog
#[arg(long, default_value = "false")]
@ -83,6 +83,9 @@ enum Command {
/// The prefix of the name of older versions of the file, which should be replaced or deleted
#[arg(short, long)]
file_name: Option<String>,
/// Only upload files which are not present yet on the target server
#[arg(short, long, default_value = "false")]
pure: bool,
},
/// Execute a command on the servers
#[command(visible_short_flag_alias = 'c')]
@ -186,6 +189,7 @@ fn main() -> Result<(), String> {
mut upload_directory,
no_confirm,
file_name,
pure,
} => {
require_non_empty_servers(&servers)?;
require_non_empty(&files, "files to upload")?;
@ -304,13 +308,20 @@ fn main() -> Result<(), String> {
let add_action = FileAction::new(file, Action::Add).expect("path points to file");
let mut ls_lines = ls_output.lines();
if pure && ls_lines.clone().any(|file| file == file_name) {
log!(logger, debug, "file is already present: {}", file_name);
return vec![]; //ignore that file, since it is already present
}
match old_version_policy {
OldVersionPolicy::Ignore => {
vec![if ls_lines.any(|file| file == file_name) {
FileAction::new(&file_name, Action::Replace).expect("path points to file")
if !ls_lines.any(|file| file == file_name) {
vec![add_action] //file doesn't exist yet
} else {
add_action
}]
vec![FileAction::new(&file_name, Action::Replace)
.expect("path points to file")]
}
}
OldVersionPolicy::Archive => ls_lines
.filter(|file| file_matcher.matches(file))
@ -347,7 +358,15 @@ fn main() -> Result<(), String> {
working_directory,
})
})
.collect::<Result<Vec<_>, String>>()?;
.collect::<Result<Vec<_>, String>>()?
.into_iter()
.filter(|server_actions| !server_actions.actions.is_empty())
.collect::<Vec<_>>();
if actions.is_empty() {
log!(logger, "Nothing to be done, everything is up to date");
return Ok(())
}
log!(logger, "The following actions will be performed: ");
for server_actions in &actions {