2024-12-13 00:03:25 +01:00
|
|
|
use crate::server::Server;
|
|
|
|
|
use std::ffi::OsString;
|
|
|
|
|
use std::fmt::{Display, Formatter};
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct ServerActions<'a> {
|
|
|
|
|
pub server: &'a Server,
|
2024-12-13 18:09:17 +01:00
|
|
|
pub working_directory: PathBuf,
|
|
|
|
|
pub actions: Vec<FileAction>,
|
2024-12-13 00:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for ServerActions<'_> {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
2025-02-02 02:23:25 +01:00
|
|
|
write!(f, "{}: ({})", self.server.get_name(), self.working_directory.to_string_lossy())?;
|
2024-12-13 00:03:25 +01:00
|
|
|
for action in &self.actions {
|
|
|
|
|
write!(f, "\n{}", action)?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
|
|
|
|
pub struct FileAction {
|
|
|
|
|
pub file: PathBuf,
|
|
|
|
|
pub kind: Action,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for FileAction {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
match &self.kind {
|
2024-12-13 00:46:35 +01:00
|
|
|
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()),
|
2024-12-13 18:09:17 +01:00
|
|
|
Action::Rename { new_name } => write!(
|
|
|
|
|
f,
|
|
|
|
|
"* renaming {} -> {}",
|
|
|
|
|
self.file.to_string_lossy(),
|
|
|
|
|
new_name.to_string_lossy()
|
|
|
|
|
),
|
2024-12-13 00:03:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
|
|
|
|
pub enum Action {
|
|
|
|
|
Add,
|
|
|
|
|
Replace,
|
|
|
|
|
Delete,
|
2024-12-13 18:09:17 +01:00
|
|
|
Rename { new_name: OsString },
|
2024-12-13 00:03:25 +01:00
|
|
|
}
|