parent
80d53e78ca
commit
ebb78c3628
@ -6,12 +6,13 @@ use std::path::PathBuf;
|
||||
#[derive(Debug)]
|
||||
pub struct ServerActions<'a> {
|
||||
pub server: &'a Server,
|
||||
pub actions: Vec<FileAction>
|
||||
pub working_directory: PathBuf,
|
||||
pub actions: Vec<FileAction>,
|
||||
}
|
||||
|
||||
impl Display for ServerActions<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}: ", self.server.ssh_name)?;
|
||||
write!(f, "{}: ({})", self.server.ssh_name, self.working_directory.to_string_lossy())?;
|
||||
for action in &self.actions {
|
||||
write!(f, "\n{}", action)?;
|
||||
}
|
||||
@ -31,7 +32,12 @@ impl Display for FileAction {
|
||||
Action::Add => write!(f, "+ adding {}", self.file.to_string_lossy()),
|
||||
Action::Replace => write!(f, "~ replacing {}", self.file.to_string_lossy()),
|
||||
Action::Delete => write!(f, "- deleting {}", self.file.to_string_lossy()),
|
||||
Action::Rename { new_name } => write!(f, "* renaming {} -> {}", self.file.to_string_lossy(), new_name.to_string_lossy()),
|
||||
Action::Rename { new_name } => write!(
|
||||
f,
|
||||
"* renaming {} -> {}",
|
||||
self.file.to_string_lossy(),
|
||||
new_name.to_string_lossy()
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,8 +47,5 @@ pub enum Action {
|
||||
Add,
|
||||
Replace,
|
||||
Delete,
|
||||
Rename {
|
||||
new_name: OsString,
|
||||
}
|
||||
Rename { new_name: OsString },
|
||||
}
|
||||
|
||||
|
||||
21
src/main.rs
21
src/main.rs
@ -116,12 +116,13 @@ fn main() -> Result<(), String> {
|
||||
let actions = servers
|
||||
.iter()
|
||||
.map(|server| {
|
||||
let working_directory = server.server_directory_path.join(&upload_directory);
|
||||
Ok(ServerActions {
|
||||
server,
|
||||
actions: {
|
||||
let output = ShellCmd::new("ssh")
|
||||
.arg(&server.ssh_name)
|
||||
.arg(osf!("ls ") + server.server_directory_path.join(&upload_directory))
|
||||
.arg(osf!("ls ") + &working_directory)
|
||||
.stdout(Stdio::piped())
|
||||
.output()
|
||||
.map_err(|e| format!("failed to query files via ssh: {e}"))?;
|
||||
@ -183,9 +184,10 @@ fn main() -> Result<(), String> {
|
||||
actions.push(add_action);
|
||||
}
|
||||
actions
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
working_directory,
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, String>>()?;
|
||||
@ -219,11 +221,7 @@ fn main() -> Result<(), String> {
|
||||
Action::Add | Action::Replace => {
|
||||
ShellCmd::new("scp")
|
||||
.arg(file.clone())
|
||||
.arg(
|
||||
osf!(&server.ssh_name)
|
||||
+ ":"
|
||||
+ server.server_directory_path.join(&upload_directory),
|
||||
)
|
||||
.arg(osf!(&server.ssh_name) + ":" + &server_actions.working_directory)
|
||||
.spawn()
|
||||
.map_err(|e| format!("failed to upload file: {e}"))?
|
||||
.wait()
|
||||
@ -232,12 +230,7 @@ fn main() -> Result<(), String> {
|
||||
Action::Delete => {
|
||||
ShellCmd::new("ssh")
|
||||
.arg(&server.ssh_name)
|
||||
.arg(
|
||||
osf!("cd ")
|
||||
+ server.server_directory_path.join(&upload_directory)
|
||||
+ "; rm "
|
||||
+ &file_action.file,
|
||||
)
|
||||
.arg(osf!("cd ") + &server_actions.working_directory + "; rm " + &file_action.file)
|
||||
.spawn()
|
||||
.map_err(|e| format!("failed to send delete command: {e}"))?
|
||||
.wait()
|
||||
@ -248,7 +241,7 @@ fn main() -> Result<(), String> {
|
||||
.arg(&server.ssh_name)
|
||||
.arg(
|
||||
osf!("cd ")
|
||||
+ server.server_directory_path.join(&upload_directory)
|
||||
+ &server_actions.working_directory
|
||||
+ "; mv "
|
||||
+ &file_action.file
|
||||
+ " "
|
||||
|
||||
Loading…
Reference in New Issue
Block a user