Skip to content

Commit

Permalink
fix: check for files in is_database_empty (#8351)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez authored May 22, 2024
1 parent dbc65ad commit bc914a6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/storage/db/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,25 @@ pub fn is_database_empty<P: AsRef<Path>>(path: P) -> bool {

if !path.exists() {
true
} else if path.is_file() {
false
} else if let Ok(dir) = path.read_dir() {
dir.count() == 0
} else {
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);
}
}

0 comments on commit bc914a6

Please sign in to comment.