fix: Versteckte Dateien (.gitignore etc.) werden nicht mehr fälschlicherweise umbenannt
- Bugfix: Dateien mit führendem Punkt wurden zu "unnamed.xxx" umbenannt, da der Punkt fälschlicherweise als Extension-Trenner interpretiert wurde. Jetzt wird der führende Punkt als hidden_prefix separat behandelt. - Alle Clippy-Warnungen behoben (redundanter Import, kollabierbare if-Blöcke, manuelle Range-Checks) - CLAUDE.md für Projekt-Dokumentation hinzugefügt Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5997aad904
commit
df4421af2f
4 changed files with 162 additions and 32 deletions
|
|
@ -135,10 +135,8 @@ impl Config {
|
|||
config.replacements.len()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if verbose {
|
||||
info!("Keine Konfigurationsdateien gefunden. Verwende nur die Standardwerte.");
|
||||
}
|
||||
} else if verbose {
|
||||
info!("Keine Konfigurationsdateien gefunden. Verwende nur die Standardwerte.");
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
|
|
|
|||
28
src/main.rs
28
src/main.rs
|
|
@ -82,13 +82,11 @@ fn main() -> Result<()> {
|
|||
let old_path = entry.path();
|
||||
|
||||
// Ebenentiefe 0 -> überspringen wir als Verzeichnis, außer --modify_root ist gesetzt
|
||||
if entry.depth() == 0 {
|
||||
if entry.file_type().is_dir() && !args.modify_root {
|
||||
if args.verbose {
|
||||
debug!("Skip root directory: {}", old_path.display());
|
||||
}
|
||||
continue;
|
||||
if entry.depth() == 0 && entry.file_type().is_dir() && !args.modify_root {
|
||||
if args.verbose {
|
||||
debug!("Skip root directory: {}", old_path.display());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Dateiname (oder Verzeichnisname) ermitteln
|
||||
|
|
@ -107,16 +105,14 @@ fn main() -> Result<()> {
|
|||
info!("{} -> {}", old_path.display(), new_path.display());
|
||||
}
|
||||
|
||||
if !args.no_changes {
|
||||
if is_safe_rename(old_path, &new_path, args.force) {
|
||||
fs::rename(old_path, &new_path).with_context(|| {
|
||||
format!(
|
||||
"Fehler beim Umbenennen: {} -> {}",
|
||||
old_path.display(),
|
||||
new_path.display()
|
||||
)
|
||||
})?;
|
||||
}
|
||||
if !args.no_changes && is_safe_rename(old_path, &new_path, args.force) {
|
||||
fs::rename(old_path, &new_path).with_context(|| {
|
||||
format!(
|
||||
"Fehler beim Umbenennen: {} -> {}",
|
||||
old_path.display(),
|
||||
new_path.display()
|
||||
)
|
||||
})?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::config::Config;
|
||||
use emojis;
|
||||
use glob::Pattern;
|
||||
use log::{debug, warn};
|
||||
use once_cell::sync::Lazy;
|
||||
|
|
@ -18,10 +17,16 @@ static RE_MULTI: Lazy<Regex> = Lazy::new(|| Regex::new(r"[_\.]{2,}").unwrap());
|
|||
pub fn clean_filename(name: &OsStr, config: &Config, verbose: bool) -> Option<String> {
|
||||
let original = name.to_string_lossy();
|
||||
|
||||
// Stamm und Extension trennen
|
||||
let (mut base, mut ext) = match original.rsplit_once('.') {
|
||||
Some((b, e)) => (b.to_string(), format!(".{e}")),
|
||||
None => (original.to_string(), String::new()),
|
||||
// Versteckte Dateien (mit führendem Punkt) korrekt behandeln
|
||||
let (hidden_prefix, rest) = match original.strip_prefix('.') {
|
||||
Some(rest) => (".", rest),
|
||||
None => ("", original.as_ref()),
|
||||
};
|
||||
|
||||
// Stamm und Extension trennen (nur im Rest, nicht im hidden_prefix)
|
||||
let (mut base, mut ext) = match rest.rsplit_once('.') {
|
||||
Some((b, e)) if !b.is_empty() => (b.to_string(), format!(".{e}")),
|
||||
_ => (rest.to_string(), String::new()),
|
||||
};
|
||||
|
||||
// Platzhalter (C++, c++, C#, c#) anlegen
|
||||
|
|
@ -71,8 +76,8 @@ pub fn clean_filename(name: &OsStr, config: &Config, verbose: bool) -> Option<St
|
|||
base = "unnamed".to_string();
|
||||
}
|
||||
|
||||
// Endgültigen Dateinamen zusammenbauen
|
||||
let mut result = format!("{}{}", base, ext);
|
||||
// Endgültigen Dateinamen zusammenbauen (hidden_prefix wieder hinzufügen)
|
||||
let mut result = format!("{}{}{}", hidden_prefix, base, ext);
|
||||
|
||||
// Platzhalter zurückverwandeln
|
||||
result = restore_special_identifiers(&result);
|
||||
|
|
@ -146,9 +151,7 @@ fn replace_emojis_and_superscript(input: &str) -> String {
|
|||
input
|
||||
.graphemes(true)
|
||||
.map(|g| {
|
||||
if emojis::get(g).is_some() {
|
||||
"_".to_string()
|
||||
} else if is_superscript(g) {
|
||||
if emojis::get(g).is_some() || is_superscript(g) {
|
||||
"_".to_string()
|
||||
} else {
|
||||
g.to_string()
|
||||
|
|
@ -162,9 +165,9 @@ fn is_superscript(g: &str) -> bool {
|
|||
g.chars().all(|c| {
|
||||
c == '\u{00AA}'
|
||||
|| c == '\u{00BA}'
|
||||
|| (c >= '\u{00B2}' && c <= '\u{00B3}')
|
||||
|| ('\u{00B2}'..='\u{00B3}').contains(&c)
|
||||
|| c == '\u{00B9}'
|
||||
|| (c >= '\u{2070}' && c <= '\u{209F}')
|
||||
|| ('\u{2070}'..='\u{209F}').contains(&c)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue