Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
705ecd8142
|
||
|
|
7f5c8db6ce
|
||
|
|
2f33e2202d
|
@@ -149,7 +149,6 @@ async fn remove(id: &str) -> anyhow::Result<()> {
|
||||
creds.delete(id, None).await?;
|
||||
smart_mount::mount::cleanup_credentials(&pair, &cfg.settings);
|
||||
|
||||
logger_ctdra::info("drive", &format!("drive pair '{id}' removed"));
|
||||
println!("Drive pair '{id}' removed.");
|
||||
Ok(())
|
||||
}
|
||||
@@ -242,7 +241,6 @@ async fn add(args: DriveArgs) -> anyhow::Result<()> {
|
||||
.await?;
|
||||
}
|
||||
|
||||
logger_ctdra::info("drive", &format!("drive pair '{id}' created"));
|
||||
println!("Drive pair '{id}' created.");
|
||||
Ok(())
|
||||
}
|
||||
@@ -375,7 +373,6 @@ async fn edit(id: &str, args: DriveArgs) -> anyhow::Result<()> {
|
||||
.await?;
|
||||
}
|
||||
|
||||
logger_ctdra::info("drive", &format!("drive pair '{id}' updated"));
|
||||
println!("Drive pair '{id}' updated.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -20,14 +20,9 @@ use clap_complete::Shell;
|
||||
/// `sudo` nicht gefunden).
|
||||
pub(crate) fn require_root(context: &str) -> anyhow::Result<()> {
|
||||
if !sudo_ctdra::is_run_as_root() {
|
||||
logger_ctdra::info(
|
||||
"cli",
|
||||
&format!("'{context}' requires root - re-executing via sudo"),
|
||||
);
|
||||
let err = sudo_ctdra::run_as_root();
|
||||
anyhow::bail!("'{context}' requires root privileges: could not re-exec via sudo: {err}");
|
||||
}
|
||||
logger_ctdra::debug("cli", &format!("'{context}': already running as root"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -93,27 +88,8 @@ pub enum Commands {
|
||||
Completions { shell: Shell },
|
||||
}
|
||||
|
||||
/// Kurzname eines Subcommands fürs Logging (siehe [`dispatch`]) - kein `Debug`-Derive auf
|
||||
/// `Commands` nötig, das würde auch die (teils sensiblen) Argument-Felder mit abdrucken.
|
||||
fn command_label(cmd: &Commands) -> &'static str {
|
||||
match cmd {
|
||||
Commands::Drive { .. } => "drive",
|
||||
Commands::Mount { .. } => "mount",
|
||||
Commands::Unmount { .. } => "unmount",
|
||||
Commands::Status { .. } => "status",
|
||||
Commands::Watch => "watch",
|
||||
Commands::Service { .. } => "service",
|
||||
Commands::Doctor { .. } => "doctor",
|
||||
Commands::Completions { .. } => "completions",
|
||||
}
|
||||
}
|
||||
|
||||
/// Führt das per `Cli` geparste Subcommand aus.
|
||||
pub async fn dispatch(cli: Cli) -> anyhow::Result<()> {
|
||||
logger_ctdra::debug(
|
||||
"cli",
|
||||
&format!("dispatching '{}'", command_label(&cli.command)),
|
||||
);
|
||||
match cli.command {
|
||||
Commands::Drive { action } => drive::run(*action).await,
|
||||
Commands::Mount { name, all } => mount_cmd::run_mount(name, all).await,
|
||||
|
||||
@@ -26,10 +26,6 @@ pub async fn run_mount(name: Option<String>, all: bool) -> anyhow::Result<()> {
|
||||
println!("No matching drive pairs found.");
|
||||
return Ok(());
|
||||
}
|
||||
logger_ctdra::info(
|
||||
"mount",
|
||||
&format!("mount: processing {} drive pair(s)", pairs.len()),
|
||||
);
|
||||
|
||||
let creds = CredentialStore::open().await?;
|
||||
for pair in &pairs {
|
||||
@@ -47,10 +43,6 @@ pub async fn run_unmount(name: Option<String>, all: bool) -> anyhow::Result<()>
|
||||
println!("No matching drive pairs found.");
|
||||
return Ok(());
|
||||
}
|
||||
logger_ctdra::info(
|
||||
"mount",
|
||||
&format!("unmount: processing {} drive pair(s)", pairs.len()),
|
||||
);
|
||||
|
||||
for pair in &pairs {
|
||||
match reconcile::unmount_pair(pair, &cfg.settings).await {
|
||||
|
||||
+1
-8
@@ -31,10 +31,6 @@ fn install() -> anyhow::Result<()> {
|
||||
|
||||
match systemd::install_cron(interval)? {
|
||||
systemd::CronInstallOutcome::SystemFile(path) => {
|
||||
logger_ctdra::info(
|
||||
"service",
|
||||
&format!("cron entry written: {}", path.display()),
|
||||
);
|
||||
println!("Cron entry written: {}", path.display());
|
||||
}
|
||||
systemd::CronInstallOutcome::Unavailable => {
|
||||
@@ -49,10 +45,7 @@ fn install() -> anyhow::Result<()> {
|
||||
|
||||
fn uninstall() -> anyhow::Result<()> {
|
||||
match systemd::uninstall_cron()? {
|
||||
systemd::CronUninstallOutcome::Removed => {
|
||||
logger_ctdra::info("service", "cron entry removed");
|
||||
println!("Cron entry removed.");
|
||||
}
|
||||
systemd::CronUninstallOutcome::Removed => println!("Cron entry removed."),
|
||||
systemd::CronUninstallOutcome::NotPresent => {
|
||||
println!("Nothing to remove - no cron entry was installed.")
|
||||
}
|
||||
|
||||
@@ -19,18 +19,6 @@ pub async fn run() -> anyhow::Result<()> {
|
||||
had_failure = true;
|
||||
}
|
||||
}
|
||||
logger_ctdra::info(
|
||||
"watch",
|
||||
&format!(
|
||||
"watch pass done: {} pair(s), {}",
|
||||
outcomes.len(),
|
||||
if had_failure {
|
||||
"with failures"
|
||||
} else {
|
||||
"no failures"
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
if had_failure {
|
||||
anyhow::bail!("at least one drive pair could not be reconciled");
|
||||
|
||||
+1
-3
@@ -19,7 +19,5 @@ pub use schema::{
|
||||
pub fn init() {
|
||||
config_ctdra::set_config_name("config");
|
||||
let program = config_ctdra::get_program_name();
|
||||
let dir = std::path::PathBuf::from("/etc").join(program);
|
||||
logger_ctdra::debug("config", &format!("config directory: {}", dir.display()));
|
||||
config_ctdra::set_custom_dir(dir);
|
||||
config_ctdra::set_custom_dir(std::path::PathBuf::from("/etc").join(program));
|
||||
}
|
||||
|
||||
@@ -10,10 +10,6 @@ pub fn load() -> Result<AppConfig> {
|
||||
|
||||
/// Fügt ein neues Laufwerkspaar hinzu (load-mutate-store in einem atomaren Schritt).
|
||||
pub fn add_pair(pair: DrivePair) -> Result<AppConfig> {
|
||||
logger_ctdra::debug(
|
||||
"config",
|
||||
&format!("writing new pair '{}' to config", pair.id),
|
||||
);
|
||||
Ok(config_ctdra::modify::<AppConfig, _>(|cfg| {
|
||||
cfg.pairs.push(pair.clone());
|
||||
})?)
|
||||
@@ -22,7 +18,6 @@ pub fn add_pair(pair: DrivePair) -> Result<AppConfig> {
|
||||
/// Ersetzt ein bestehendes Laufwerkspaar (Vergleich über `id`).
|
||||
pub fn update_pair(pair: DrivePair) -> Result<AppConfig> {
|
||||
let id = pair.id.clone();
|
||||
logger_ctdra::debug("config", &format!("writing updated pair '{id}' to config"));
|
||||
let updated = config_ctdra::modify::<AppConfig, _>(move |cfg| {
|
||||
if let Some(existing) = cfg.pairs.iter_mut().find(|p| p.id == pair.id) {
|
||||
*existing = pair.clone();
|
||||
@@ -36,7 +31,6 @@ pub fn update_pair(pair: DrivePair) -> Result<AppConfig> {
|
||||
|
||||
/// Entfernt ein Laufwerkspaar per ID.
|
||||
pub fn remove_pair(id: &str) -> Result<AppConfig> {
|
||||
logger_ctdra::debug("config", &format!("removing pair '{id}' from config"));
|
||||
// Die "vorher"-Länge wird INNERHALB desselben `modify`-Aufrufs (auf der bereits frisch
|
||||
// geladenen `cfg`) ermittelt statt über einen separaten, vorgelagerten `load()`-Aufruf:
|
||||
// zwischen zwei getrennten Aufrufen könnte ein nebenläufiger Schreiber die Paarliste
|
||||
|
||||
@@ -32,16 +32,8 @@ mod file_key {
|
||||
|
||||
pub fn load_or_create(path: &Path) -> Result<[u8; 32]> {
|
||||
if path.exists() {
|
||||
logger_ctdra::debug(
|
||||
"crypto",
|
||||
&format!("loading master key from '{}'", path.display()),
|
||||
);
|
||||
return read(path);
|
||||
}
|
||||
logger_ctdra::info(
|
||||
"crypto",
|
||||
&format!("creating new master key at '{}'", path.display()),
|
||||
);
|
||||
create(path)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ pub const NONCE_LEN: usize = 12;
|
||||
/// aes-gcms Re-Export-Kette nicht automatisch aktiviert wird). `getrandom::fill` ist
|
||||
/// unabhängig davon stabil und genau für diesen Zweck gedacht.
|
||||
pub fn encrypt(plaintext: &[u8], key: &[u8; 32]) -> Result<(Vec<u8>, Vec<u8>)> {
|
||||
logger_ctdra::debug("crypto", "encrypting credential data");
|
||||
let cipher = Aes256Gcm::new(&Key::<Aes256Gcm>::from(*key));
|
||||
|
||||
let mut nonce_bytes = [0u8; NONCE_LEN];
|
||||
@@ -45,7 +44,6 @@ pub fn encrypt(plaintext: &[u8], key: &[u8; 32]) -> Result<(Vec<u8>, Vec<u8>)> {
|
||||
|
||||
/// Entschlüsselt einen zuvor mit [`encrypt`] erzeugten Ciphertext.
|
||||
pub fn decrypt(ciphertext: &[u8], nonce: &[u8], key: &[u8; 32]) -> Result<Vec<u8>> {
|
||||
logger_ctdra::debug("crypto", "decrypting credential data");
|
||||
if nonce.len() != NONCE_LEN {
|
||||
return Err(Error::Crypto(format!(
|
||||
"invalid nonce length: expected {NONCE_LEN}, got {}",
|
||||
|
||||
@@ -58,13 +58,6 @@ impl CredentialStore {
|
||||
domain: Option<&str>,
|
||||
password: &str,
|
||||
) -> Result<()> {
|
||||
logger_ctdra::debug(
|
||||
"db",
|
||||
&format!(
|
||||
"storing credential for pair '{pair_id}' ({})",
|
||||
side.as_str()
|
||||
),
|
||||
);
|
||||
let key = resolve_master_key()?;
|
||||
let (ciphertext, nonce) = crypto::encrypt(password.as_bytes(), &key)?;
|
||||
let now = now_unix();
|
||||
@@ -92,13 +85,6 @@ impl CredentialStore {
|
||||
|
||||
/// Liest und entschlüsselt die Zugangsdaten für `pair_id`/`side`, falls vorhanden.
|
||||
pub async fn get(&self, pair_id: &str, side: Side) -> Result<Option<Credential>> {
|
||||
logger_ctdra::debug(
|
||||
"db",
|
||||
&format!(
|
||||
"reading credential for pair '{pair_id}' ({})",
|
||||
side.as_str()
|
||||
),
|
||||
);
|
||||
let mut rows = self
|
||||
.conn
|
||||
.query(
|
||||
@@ -131,13 +117,6 @@ impl CredentialStore {
|
||||
|
||||
/// Löscht Zugangsdaten. `side = None` löscht beide Seiten (z. B. beim Entfernen eines Paars).
|
||||
pub async fn delete(&self, pair_id: &str, side: Option<Side>) -> Result<()> {
|
||||
logger_ctdra::debug(
|
||||
"db",
|
||||
&format!(
|
||||
"deleting credential(s) for pair '{pair_id}' ({})",
|
||||
side.map(|s| s.as_str()).unwrap_or("both sides")
|
||||
),
|
||||
);
|
||||
match side {
|
||||
Some(side) => {
|
||||
self.conn
|
||||
|
||||
@@ -21,7 +21,6 @@ pub fn resolve_db_path() -> PathBuf {
|
||||
/// Öffnet (und initialisiert bei Bedarf) die lokale Datenbank am aufgelösten Pfad.
|
||||
pub async fn open() -> Result<turso::Connection> {
|
||||
let path = resolve_db_path();
|
||||
logger_ctdra::debug("db", &format!("opening database at '{}'", path.display()));
|
||||
if let Some(dir) = path.parent() {
|
||||
tokio::fs::create_dir_all(dir)
|
||||
.await
|
||||
|
||||
@@ -13,13 +13,6 @@ async fn main() -> ExitCode {
|
||||
Err(_) => "info".to_string(),
|
||||
};
|
||||
logger_ctdra::set_log_level(parse_log_level(&log_level));
|
||||
logger_ctdra::info(
|
||||
"main",
|
||||
&format!(
|
||||
"smart-mount {} starting (log level: {log_level})",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
),
|
||||
);
|
||||
|
||||
let cli = cli::Cli::parse();
|
||||
match cli::dispatch(cli).await {
|
||||
|
||||
+1
-13
@@ -23,16 +23,9 @@ use crate::error::{Error, Result};
|
||||
/// Datei-Deskriptor), bis der Guard gedroppt wird - Schließen des Deskriptors gibt die Sperre
|
||||
/// implizit frei, ein explizites `unlock()` ist dafür nicht nötig.
|
||||
pub struct PairLock {
|
||||
pair_id: String,
|
||||
_file: File,
|
||||
}
|
||||
|
||||
impl Drop for PairLock {
|
||||
fn drop(&mut self) {
|
||||
logger_ctdra::debug("lock", &format!("pair '{}': lock released", self.pair_id));
|
||||
}
|
||||
}
|
||||
|
||||
/// Verzeichnis für die Sperrdateien: `/run/smart-mount/locks` im Root-/System-Kontext (root ist
|
||||
/// dort ohnehin die einzige Partei, die Paare in diesem Kontext mountet), sonst
|
||||
/// `$XDG_RUNTIME_DIR` (per-Nutzer, von systemd `0700`-geschützt angelegt) mit Fallback auf das
|
||||
@@ -66,13 +59,8 @@ fn acquire_blocking(pair_id: &str) -> Result<PairLock> {
|
||||
// Blockiert, bis die Sperre frei wird - `flock(2)` kennt keinen Async-Mechanismus, daher
|
||||
// läuft dieser gesamte Aufruf über `spawn_blocking` (siehe [`acquire`]) auf einem
|
||||
// Blocking-Thread statt einem Tokio-Worker-Thread.
|
||||
logger_ctdra::debug("lock", &format!("pair '{pair_id}': waiting for lock"));
|
||||
file.lock().map_err(|e| Error::io(&path, e))?;
|
||||
logger_ctdra::debug("lock", &format!("pair '{pair_id}': lock acquired"));
|
||||
Ok(PairLock {
|
||||
pair_id: pair_id.to_string(),
|
||||
_file: file,
|
||||
})
|
||||
Ok(PairLock { _file: file })
|
||||
}
|
||||
|
||||
/// Sperrt ein Laufwerkspaar prozessübergreifend für die Dauer des zurückgegebenen Guards.
|
||||
|
||||
+5
-21
@@ -93,17 +93,6 @@ fn run_tolerating_already_done_with_timeout(
|
||||
tolerate_timeout: bool,
|
||||
timeout_secs: u64,
|
||||
) -> Result<()> {
|
||||
logger_ctdra::debug(
|
||||
"mount",
|
||||
&format!(
|
||||
"{context}: running '{} {}' (timeout {timeout_secs}s)",
|
||||
cmd.get_program().to_string_lossy(),
|
||||
cmd.get_args()
|
||||
.map(|a| a.to_string_lossy().into_owned())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
),
|
||||
);
|
||||
let output =
|
||||
run_with_timeout(cmd, timeout_secs).map_err(|e| crate::error::Error::MountFailed {
|
||||
context: context.to_string(),
|
||||
@@ -111,7 +100,6 @@ fn run_tolerating_already_done_with_timeout(
|
||||
})?;
|
||||
|
||||
if output.status.success() {
|
||||
logger_ctdra::debug("mount", &format!("{context}: succeeded"));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -185,20 +173,16 @@ fn cleanup_side_credentials(
|
||||
match kind {
|
||||
MountKind::Smb => {
|
||||
let path = smb::credentials_path(&pair.id, side);
|
||||
if path.exists() {
|
||||
match std::fs::remove_file(&path) {
|
||||
Ok(()) => logger_ctdra::debug(
|
||||
"mount",
|
||||
&format!("deleted credentials file '{}'", path.display()),
|
||||
),
|
||||
Err(e) => logger_ctdra::warn(
|
||||
if path.exists()
|
||||
&& let Err(e) = std::fs::remove_file(&path)
|
||||
{
|
||||
logger_ctdra::warn(
|
||||
"mount",
|
||||
&format!(
|
||||
"Could not delete credentials file '{}': {e}",
|
||||
path.display()
|
||||
),
|
||||
),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
MountKind::WebDav => {
|
||||
|
||||
+1
-6
@@ -29,12 +29,7 @@ impl MountBackend for SmbBackend {
|
||||
|
||||
fn prepare(&self, target: &MountTarget, cred: Option<&Credential>) -> Result<()> {
|
||||
if let Some(cred) = cred {
|
||||
let path = credentials_path(&target.pair_id, target.side);
|
||||
logger_ctdra::debug(
|
||||
"mount",
|
||||
&format!("cifs: writing credentials file '{}'", path.display()),
|
||||
);
|
||||
write_credentials_file(&path, cred)?;
|
||||
write_credentials_file(&credentials_path(&target.pair_id, target.side), cred)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -301,15 +301,6 @@ pub fn activate_symlink(pair: &DrivePair, side: Side) -> Result<()> {
|
||||
let _ = std::fs::remove_file(&tmp_path);
|
||||
std::os::unix::fs::symlink(&target, &tmp_path).map_err(|e| Error::io(&tmp_path, e))?;
|
||||
std::fs::rename(&tmp_path, link_path).map_err(|e| Error::io(link_path, e))?;
|
||||
logger_ctdra::info(
|
||||
"mount",
|
||||
&format!(
|
||||
"pair '{}': activated '{}' -> '{}'",
|
||||
pair.id,
|
||||
link_path.display(),
|
||||
target.display()
|
||||
),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,6 @@ impl MountBackend for WebDavBackend {
|
||||
"davfs2 credential has an empty username or password".to_string(),
|
||||
));
|
||||
}
|
||||
logger_ctdra::debug(
|
||||
"mount",
|
||||
&format!("davfs2: writing secrets entry for '{}'", target.source),
|
||||
);
|
||||
write_secrets_entry(
|
||||
&davfs2_secrets_path(),
|
||||
&target.source,
|
||||
|
||||
+1
-19
@@ -38,12 +38,6 @@ enum Mac2IpOutput {
|
||||
/// `binary` ist der konfigurierte Binary-Name/-Pfad (`GlobalSettings::mac2ip_binary`,
|
||||
/// standardmäßig `"mac2ip"`, per PATH aufgelöst).
|
||||
pub fn resolve(mac: &str, binary: &str) -> Result<Ipv4Addr> {
|
||||
logger_ctdra::info(
|
||||
"network",
|
||||
&format!(
|
||||
"resolving MAC '{mac}' via '{binary}' (may take up to {MAC2IP_TIMEOUT_SECS}s, e.g. for an nmap scan)"
|
||||
),
|
||||
);
|
||||
let output = Command::new("timeout")
|
||||
.arg(MAC2IP_TIMEOUT_SECS.to_string())
|
||||
.arg(binary)
|
||||
@@ -55,25 +49,13 @@ pub fn resolve(mac: &str, binary: &str) -> Result<Ipv4Addr> {
|
||||
})?;
|
||||
|
||||
if output.status.code() == Some(124) {
|
||||
logger_ctdra::warn(
|
||||
"network",
|
||||
&format!("'{binary}' did not respond within {MAC2IP_TIMEOUT_SECS}s for MAC '{mac}'"),
|
||||
);
|
||||
return Err(Error::Mac2Ip {
|
||||
mac: mac.to_string(),
|
||||
reason: format!("'{binary}' did not respond within {MAC2IP_TIMEOUT_SECS}s (timed out)"),
|
||||
});
|
||||
}
|
||||
|
||||
let result = parse_output(&output.stdout, mac);
|
||||
match &result {
|
||||
Ok(ip) => logger_ctdra::info("network", &format!("MAC '{mac}' resolved to {ip}")),
|
||||
Err(e) => logger_ctdra::debug(
|
||||
"network",
|
||||
&format!("MAC '{mac}' could not be resolved: {e}"),
|
||||
),
|
||||
}
|
||||
result
|
||||
parse_output(&output.stdout, mac)
|
||||
}
|
||||
|
||||
/// Prüft, ob das konfigurierte `mac2ip`-Binary über `PATH` auffindbar ist.
|
||||
|
||||
@@ -17,15 +17,6 @@ use std::process::{Command, Stdio};
|
||||
/// (z. B. ein kaputter Reverse-Proxy) sonst bei jedem `watch`-Durchlauf einen vollen,
|
||||
/// letztlich erfolglosen Umschaltversuch (inkl. `MOUNT_TIMEOUT_SECS`-Wartezeit) auslösen würde.
|
||||
pub fn is_reachable(addr: &str) -> bool {
|
||||
let reachable = is_reachable_inner(addr);
|
||||
logger_ctdra::debug(
|
||||
"network",
|
||||
&format!("reachability check for '{addr}': {reachable}"),
|
||||
);
|
||||
reachable
|
||||
}
|
||||
|
||||
fn is_reachable_inner(addr: &str) -> bool {
|
||||
if addr.starts_with("http://") || addr.starts_with("https://") {
|
||||
Command::new("curl")
|
||||
.args([
|
||||
|
||||
+6
-78
@@ -50,13 +50,6 @@ pub struct ReconcileOutcome {
|
||||
/// Risiko für einen Effizienzgewinn, den die Reachability-Parallelisierung bereits liefert.
|
||||
pub async fn watch_once(cfg: &AppConfig, creds: &CredentialStore) -> Vec<ReconcileOutcome> {
|
||||
let enabled: Vec<&DrivePair> = cfg.pairs.iter().filter(|p| p.enabled).collect();
|
||||
logger_ctdra::debug(
|
||||
"reconcile",
|
||||
&format!(
|
||||
"watch: checking reachability for {} enabled pair(s)",
|
||||
enabled.len()
|
||||
),
|
||||
);
|
||||
|
||||
let mut checks = Vec::with_capacity(enabled.len());
|
||||
for pair in &enabled {
|
||||
@@ -130,28 +123,16 @@ async fn reconcile_pair_checked(
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(action) => {
|
||||
logger_ctdra::info(
|
||||
"reconcile",
|
||||
&format!("pair '{pair_name}' ({pair_id}): {action:?}"),
|
||||
);
|
||||
ReconcileOutcome {
|
||||
Ok(action) => ReconcileOutcome {
|
||||
pair_id,
|
||||
pair_name,
|
||||
action,
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
logger_ctdra::error(
|
||||
"reconcile",
|
||||
&format!("pair '{pair_name}' ({pair_id}): reconcile failed: {e}"),
|
||||
);
|
||||
ReconcileOutcome {
|
||||
},
|
||||
Err(e) => ReconcileOutcome {
|
||||
pair_id,
|
||||
pair_name,
|
||||
action: Action::Failed(e.to_string()),
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,13 +147,6 @@ async fn reconcile_pair_inner(
|
||||
let _guard = lock::acquire(&pair.id).await?;
|
||||
|
||||
let active = target::active_side(pair);
|
||||
logger_ctdra::debug(
|
||||
"reconcile",
|
||||
&format!(
|
||||
"pair '{}': local_reachable={local_reachable} cloud_reachable={cloud_reachable} active={:?}",
|
||||
pair.id, active
|
||||
),
|
||||
);
|
||||
cleanup_orphaned_mounts(pair, settings, active).await;
|
||||
|
||||
if local_reachable {
|
||||
@@ -208,13 +182,7 @@ async fn reconcile_pair_inner(
|
||||
fn check_local_reachable(local: &LocalSide, settings: &GlobalSettings) -> (bool, Option<Ipv4Addr>) {
|
||||
match address::resolve_ip(&local.address, settings) {
|
||||
Ok(ip) => (network::is_reachable(&ip.to_string()), Some(ip)),
|
||||
Err(e) => {
|
||||
logger_ctdra::debug(
|
||||
"reconcile",
|
||||
&format!("local address could not be resolved: {e}"),
|
||||
);
|
||||
(false, None)
|
||||
}
|
||||
Err(_) => (false, None),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,15 +251,6 @@ async fn switch_to(
|
||||
old_active: Option<Side>,
|
||||
cached_local_ip: Option<Ipv4Addr>,
|
||||
) -> Result<()> {
|
||||
logger_ctdra::info(
|
||||
"reconcile",
|
||||
&format!(
|
||||
"pair '{}': switching to '{}' (previously active: {:?})",
|
||||
pair.id,
|
||||
new_side.as_str(),
|
||||
old_active
|
||||
),
|
||||
);
|
||||
mount_side(pair, settings, new_side, creds, cached_local_ip).await?;
|
||||
|
||||
// Falls das Aktivieren des Symlinks fehlschlägt, muss die gerade gemountete `new_side`
|
||||
@@ -321,16 +280,6 @@ async fn mount_side(
|
||||
) -> Result<()> {
|
||||
let mount_target =
|
||||
target::build_target_with_cached_local_ip(pair, settings, side, cached_local_ip)?;
|
||||
logger_ctdra::debug(
|
||||
"reconcile",
|
||||
&format!(
|
||||
"pair '{}' ({}): resolved source '{}' -> '{}'",
|
||||
pair.id,
|
||||
side.as_str(),
|
||||
mount_target.source,
|
||||
mount_target.mount_point.display()
|
||||
),
|
||||
);
|
||||
std::fs::create_dir_all(&mount_target.mount_point)
|
||||
.map_err(|e| crate::error::Error::io(&mount_target.mount_point, e))?;
|
||||
// Backing-Verzeichnis auf `owner_user` chownen (0700) - relevant vor allem für NFS, wo es
|
||||
@@ -344,15 +293,6 @@ async fn mount_side(
|
||||
backend.check_available()?;
|
||||
let cred = creds.get(&pair.id, side).await?;
|
||||
backend.prepare(&mount_target, cred.as_ref())?;
|
||||
logger_ctdra::info(
|
||||
"reconcile",
|
||||
&format!(
|
||||
"pair '{}' ({}): mounting via {} ...",
|
||||
pair.id,
|
||||
side.as_str(),
|
||||
backend.name()
|
||||
),
|
||||
);
|
||||
backend.mount(&mount_target)
|
||||
}
|
||||
|
||||
@@ -361,7 +301,6 @@ async fn mount_side(
|
||||
/// ein leeres, ausgehängtes Backing-Verzeichnis) - der nächste `mount`/`watch`-Lauf räumt das
|
||||
/// beim erneuten Aktivieren automatisch auf.
|
||||
pub async fn unmount_pair(pair: &DrivePair, settings: &GlobalSettings) -> Result<Action> {
|
||||
logger_ctdra::info("reconcile", &format!("pair '{}': unmounting", pair.id));
|
||||
let _guard = lock::acquire(&pair.id).await?;
|
||||
|
||||
// Beide Seiten werden unabhängig voneinander versucht - ein Fehler (auch ein
|
||||
@@ -424,18 +363,7 @@ async fn unmount_side(pair: &DrivePair, settings: &GlobalSettings, side: Side) -
|
||||
owner_user: pair.owner_user.clone(),
|
||||
}
|
||||
});
|
||||
let backend = mount::backend_for(target::side_kind(pair, side));
|
||||
logger_ctdra::debug(
|
||||
"reconcile",
|
||||
&format!(
|
||||
"pair '{}' ({}): unmounting via {} ({})",
|
||||
pair.id,
|
||||
side.as_str(),
|
||||
backend.name(),
|
||||
mount_target.mount_point.display()
|
||||
),
|
||||
);
|
||||
backend.unmount(&mount_target)
|
||||
mount::backend_for(target::side_kind(pair, side)).unmount(&mount_target)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -67,7 +67,6 @@ pub fn install_cron(watch_interval_secs: u64) -> Result<CronInstallOutcome> {
|
||||
std::fs::set_permissions(CRON_D_PATH, std::fs::Permissions::from_mode(0o644))
|
||||
.map_err(|e| Error::io(CRON_D_PATH, e))?;
|
||||
}
|
||||
logger_ctdra::info("systemd", &format!("cron entry written to '{CRON_D_PATH}'"));
|
||||
Ok(CronInstallOutcome::SystemFile(PathBuf::from(CRON_D_PATH)))
|
||||
}
|
||||
|
||||
@@ -97,10 +96,6 @@ pub fn uninstall_cron() -> Result<CronUninstallOutcome> {
|
||||
return Ok(CronUninstallOutcome::NotPresent);
|
||||
}
|
||||
std::fs::remove_file(path).map_err(|e| Error::io(CRON_D_PATH, e))?;
|
||||
logger_ctdra::info(
|
||||
"systemd",
|
||||
&format!("cron entry removed from '{CRON_D_PATH}'"),
|
||||
);
|
||||
Ok(CronUninstallOutcome::Removed)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user