refactor: apply clippy let-chains and harden password validation
- Auto-fix 29 clippy warnings by converting nested if-lets to let-chains - Harden password strength validator to reject restricted substrings - Simplify rate_limiter state checks using is_none_or - Improves idiomatic Rust style and overall security posture
This commit is contained in:
1 parent
f2f615b456
commit
b25a015898
17 files changed
+81
-109
No files matched your search
+8
-12
@@ -566,11 +566,10 @@ async fn cmd_init(
|
||||
let sqlite_path = config.database.sqlite_path();
|
||||
let db_path = std::path::Path::new(&sqlite_path);
|
||||
println!("Creating database directory...");
|
||||
if let Some(parent) = db_path.parent() {
|
||||
if !parent.as_os_str().is_empty() {
|
||||
if let Some(parent) = db_path.parent()
|
||||
&& !parent.as_os_str().is_empty() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Create state directory
|
||||
if let Ok(home) = std::env::var("HOME") {
|
||||
@@ -664,11 +663,10 @@ async fn run_init_validation(config: &Config, admin_skipped: bool) -> anyhow::Re
|
||||
let sqlite_path = config.database.sqlite_path();
|
||||
let db_path = std::path::Path::new(&sqlite_path);
|
||||
let mut dirs_ok = true;
|
||||
if let Some(parent) = db_path.parent() {
|
||||
if !parent.as_os_str().is_empty() && std::fs::create_dir_all(parent).is_err() {
|
||||
if let Some(parent) = db_path.parent()
|
||||
&& !parent.as_os_str().is_empty() && std::fs::create_dir_all(parent).is_err() {
|
||||
dirs_ok = false;
|
||||
}
|
||||
}
|
||||
if let Ok(home) = std::env::var("HOME") {
|
||||
let state_dir = std::path::Path::new(&home).join(".local/state/nx9-auth");
|
||||
if std::fs::create_dir_all(&state_dir).is_err() {
|
||||
@@ -892,11 +890,10 @@ async fn cmd_backup(config: &Config, path: &std::path::Path) -> anyhow::Result<(
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(parent) = path.parent() {
|
||||
if !parent.as_os_str().is_empty() {
|
||||
if let Some(parent) = path.parent()
|
||||
&& !parent.as_os_str().is_empty() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
}
|
||||
|
||||
if path.exists() {
|
||||
std::fs::remove_file(path)?;
|
||||
@@ -958,11 +955,10 @@ async fn cmd_restore(config: &Config, path: &std::path::Path) -> anyhow::Result<
|
||||
crate::config::DatabaseBackend::Sqlite => {
|
||||
let sqlite_path = config.database.sqlite_path();
|
||||
let target_path = std::path::Path::new(&sqlite_path);
|
||||
if let Some(parent) = target_path.parent() {
|
||||
if !parent.as_os_str().is_empty() {
|
||||
if let Some(parent) = target_path.parent()
|
||||
&& !parent.as_os_str().is_empty() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
}
|
||||
std::fs::copy(path, target_path).with_context(|| {
|
||||
format!("failed to restore backup to {}", target_path.display())
|
||||
})?;
|
||||
|
||||
Reference in new issue
Block a user