mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: check for files in is_database_empty (#8351)
This commit is contained in:
@ -23,9 +23,25 @@ pub fn is_database_empty<P: AsRef<Path>>(path: P) -> bool {
|
|||||||
|
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
true
|
true
|
||||||
|
} else if path.is_file() {
|
||||||
|
false
|
||||||
} else if let Ok(dir) = path.read_dir() {
|
} else if let Ok(dir) = path.read_dir() {
|
||||||
dir.count() == 0
|
dir.count() == 0
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_database_empty_false_if_db_path_is_a_file() {
|
||||||
|
let db_file = tempfile::NamedTempFile::new().unwrap();
|
||||||
|
|
||||||
|
let result = is_database_empty(&db_file);
|
||||||
|
|
||||||
|
assert!(!result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user