Refactor: fstab nutzt Side::as_str() statt einer eigenen Kopie
TruffleHog Secret Scan / TruffleHog (push) Successful in 21s
Security Scans / Trivy & OSV-Scanner (push) Successful in 37s
Code Quality (Auto-Format & Clippy-Fix) / Formatierung & Clippy automatisch beheben (push) Successful in 2m14s
Testing Build, Publish & Preview Release / Build, Publish Packages (Testing) & Create Preview Release (push) Skipped
TruffleHog Secret Scan / TruffleHog (push) Successful in 21s
Security Scans / Trivy & OSV-Scanner (push) Successful in 37s
Code Quality (Auto-Format & Clippy-Fix) / Formatierung & Clippy automatisch beheben (push) Successful in 2m14s
Testing Build, Publish & Preview Release / Build, Publish Packages (Testing) & Create Preview Release (push) Skipped
fstab::side_str() bildete exakt dieselbe Zuordnung wie das bereits importierte db::credentials::Side::as_str() nach - eine kuenftige Aenderung der String-Repraesentation (oder ein dritter Side-Wert) haette leicht dazu fuehren koennen, dass die fstab-Tag-Zeilen unbemerkt von der ueberall sonst genutzten Darstellung abweichen. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+9
-17
@@ -39,9 +39,7 @@ pub fn setup() -> Result<()> {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let sudo_user = std::env::var("SUDO_USER")
|
let sudo_user = std::env::var("SUDO_USER").ok().filter(|s| !s.is_empty());
|
||||||
.ok()
|
|
||||||
.filter(|s| !s.is_empty());
|
|
||||||
|
|
||||||
if let Some(sudo_user) = &sudo_user
|
if let Some(sudo_user) = &sudo_user
|
||||||
&& config_ctdra::get_custom_path().is_none()
|
&& config_ctdra::get_custom_path().is_none()
|
||||||
@@ -276,13 +274,6 @@ fn write_atomic(path: &Path, contents: &str) -> Result<()> {
|
|||||||
std::fs::rename(&tmp_path, path).map_err(|e| Error::io(path, e))
|
std::fs::rename(&tmp_path, path).map_err(|e| Error::io(path, e))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn side_str(side: Side) -> &'static str {
|
|
||||||
match side {
|
|
||||||
Side::Local => "local",
|
|
||||||
Side::Cloud => "cloud",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Tag-Kommentar, der an jede von smart-mount geschriebene fstab-Zeile angehängt wird
|
/// Tag-Kommentar, der an jede von smart-mount geschriebene fstab-Zeile angehängt wird
|
||||||
/// (`man 5 fstab`: ein `#` leitet einen bis zum Zeilenende reichenden Kommentar ein, auch nach
|
/// (`man 5 fstab`: ein `#` leitet einen bis zum Zeilenende reichenden Kommentar ein, auch nach
|
||||||
/// den 6 regulären Feldern - das stört `mount(8)` nicht). Erlaubt, beim nächsten `setup fstab`
|
/// den 6 regulären Feldern - das stört `mount(8)` nicht). Erlaubt, beim nächsten `setup fstab`
|
||||||
@@ -293,7 +284,7 @@ fn line_tag(pair: &DrivePair, side: Side) -> String {
|
|||||||
format!(
|
format!(
|
||||||
"smart-mount pair={} side={} owner={}",
|
"smart-mount pair={} side={} owner={}",
|
||||||
pair.id,
|
pair.id,
|
||||||
side_str(side),
|
side.as_str(),
|
||||||
pair.owner_user.as_deref().unwrap_or("-")
|
pair.owner_user.as_deref().unwrap_or("-")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -359,7 +350,7 @@ fn merge_managed_block(
|
|||||||
for side in [Side::Local, Side::Cloud] {
|
for side in [Side::Local, Side::Cloud] {
|
||||||
match tagged_line(pair, side, settings) {
|
match tagged_line(pair, side, settings) {
|
||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
replaced.insert((pair.id.clone(), side_str(side)));
|
replaced.insert((pair.id.clone(), side.as_str()));
|
||||||
new_lines.push(line);
|
new_lines.push(line);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -369,7 +360,7 @@ fn merge_managed_block(
|
|||||||
"could not compute fstab entry for pair '{}' ({}): {e} - leaving \
|
"could not compute fstab entry for pair '{}' ({}): {e} - leaving \
|
||||||
any existing entry for it untouched",
|
any existing entry for it untouched",
|
||||||
pair.id,
|
pair.id,
|
||||||
side_str(side)
|
side.as_str()
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -455,7 +446,9 @@ fn user_config_path(username: &str) -> PathBuf {
|
|||||||
user_home_dir(username)
|
user_home_dir(username)
|
||||||
.map(|h| h.join(".config").join(&program_name).join(&file_name))
|
.map(|h| h.join(".config").join(&program_name).join(&file_name))
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
PathBuf::from(format!("/home/{username}/.config/{program_name}/{file_name}"))
|
PathBuf::from(format!(
|
||||||
|
"/home/{username}/.config/{program_name}/{file_name}"
|
||||||
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,9 +602,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
// `deleted-pair` is no longer part of `pairs`, so its line should be dropped since it
|
// `deleted-pair` is no longer part of `pairs`, so its line should be dropped since it
|
||||||
// belongs to the same owner this run is scoped to - but only then.
|
// belongs to the same owner this run is scoped to - but only then.
|
||||||
let block = merge_managed_block(&stale_line, &[&pair], &GlobalSettings::default(), &[
|
let block =
|
||||||
owner,
|
merge_managed_block(&stale_line, &[&pair], &GlobalSettings::default(), &[owner]);
|
||||||
]);
|
|
||||||
|
|
||||||
assert!(!block.contains("deleted-pair"));
|
assert!(!block.contains("deleted-pair"));
|
||||||
assert!(block.contains("pair=pair-1"));
|
assert!(block.contains("pair=pair-1"));
|
||||||
|
|||||||
Reference in New Issue
Block a user