Fix: local_source() gibt wieder ein Result zurueck
mount::target::local_source() gab bei fehlgeschlagener Adressaufloesung
(mac2ip findet die MAC-Adresse nicht) bisher den Platzhalter-String
"unresolved" zurueck und formatierte daraus eine syntaktisch gueltige,
aber sinnlose Mount-Quelle - statt den Fehler an den Aufrufer
durchzureichen. mount::cleanup_side_credentials() (WebDAV-Zweig)
erwartet bereits seit 690f727 ein Result von lokal_source(), um einen
Aufloesungsfehler zu loggen statt ihn zu verschlucken; ohne diese
Aenderung war das im Repository committete HEAD dadurch nicht
kompilierbar. local_source() gibt jetzt ein Result<String> zurueck und
reicht den Aufloesungsfehler ueber `?` durch.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+18
-7
@@ -54,7 +54,7 @@ pub fn build_target(
|
||||
|
||||
let (source, mut options) = match side {
|
||||
Side::Local => (
|
||||
local_source(&pair.local, settings),
|
||||
local_source(&pair.local, settings)?,
|
||||
parse_options(&pair.local.extra_options),
|
||||
),
|
||||
Side::Cloud => (
|
||||
@@ -169,11 +169,14 @@ fn run_id(username: &str, flag: &str) -> Result<u32> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn local_source(local: &LocalSide, settings: &GlobalSettings) -> String {
|
||||
let ip = address::resolve_ip(&local.address, settings)
|
||||
.map(|ip| ip.to_string())
|
||||
.unwrap_or_else(|_| "unresolved".to_string());
|
||||
format_source(local.kind, &ip, &local.share)
|
||||
/// Löst die konfigurierte lokale Adresse auf und formatiert die Mount-Quelle daraus. Gibt
|
||||
/// einen Fehler zurück, statt eine fehlgeschlagene Auflösung (z. B. `mac2ip` findet die
|
||||
/// MAC-Adresse nicht) hinter dem Platzhalter-String `"unresolved"` zu verstecken - Aufrufer
|
||||
/// sollen einen echten Auflösungsfehler von einer tatsächlich formatierten, aber unerreichbaren
|
||||
/// Quelle unterscheiden können.
|
||||
pub fn local_source(local: &LocalSide, settings: &GlobalSettings) -> Result<String> {
|
||||
let ip = address::resolve_ip(&local.address, settings)?;
|
||||
Ok(format_source(local.kind, &ip.to_string(), &local.share))
|
||||
}
|
||||
|
||||
pub fn cloud_source(cloud: &CloudSide) -> String {
|
||||
@@ -297,11 +300,19 @@ mod tests {
|
||||
fn local_source_formats_smb_unc_path() {
|
||||
let pair = sample_pair();
|
||||
assert_eq!(
|
||||
local_source(&pair.local, &GlobalSettings::default()),
|
||||
local_source(&pair.local, &GlobalSettings::default()).expect("local_source"),
|
||||
"//192.168.1.10/share"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_source_propagates_mac2ip_error() {
|
||||
let mut pair = sample_pair();
|
||||
pair.local.address = crate::config::LocalAddress::Mac("00:11:22:33:44:55".into());
|
||||
let err = local_source(&pair.local, &GlobalSettings::default()).unwrap_err();
|
||||
assert!(matches!(err, crate::error::Error::Mac2Ip { .. }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cloud_source_uses_full_url_for_webdav() {
|
||||
let pair = sample_pair();
|
||||
|
||||
@@ -215,7 +215,8 @@ mod tests {
|
||||
#[test]
|
||||
fn local_source_formats_smb_unc_path() {
|
||||
let pair = sample_pair(MountKind::Smb, MountKind::WebDav);
|
||||
let source = target::local_source(&pair.local, &GlobalSettings::default());
|
||||
let source =
|
||||
target::local_source(&pair.local, &GlobalSettings::default()).expect("local_source");
|
||||
assert_eq!(source, "//192.168.1.10/share");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user