Skip to content

Commit 2f02d29

Browse files
authored
Merge pull request #142 from fjall-rs/fix/recovery/mac-underscore-files
Fix recovery with mac underscore file
2 parents e116e9a + f27d000 commit 2f02d29

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/tree/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,16 @@ impl Tree {
920920

921921
let file_name = dirent.file_name();
922922

923+
// https://en.wikipedia.org/wiki/.DS_Store
923924
if file_name == ".DS_Store" {
924925
continue;
925926
}
926927

928+
// https://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_formats
929+
if file_name.to_string_lossy().starts_with("._") {
930+
continue;
931+
}
932+
927933
let segment_file_name = file_name.to_str().ok_or_else(|| {
928934
log::error!("invalid segment file name {file_name:?}");
929935
crate::Error::Unrecoverable

tests/recovery_mac_underscore.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use lsm_tree::{AbstractTree, Config};
2+
use test_log::test;
3+
4+
#[test]
5+
fn recovery_mac_underscore_file() -> lsm_tree::Result<()> {
6+
let folder = tempfile::tempdir()?.into_path();
7+
8+
{
9+
let tree = Config::new(&folder).open()?;
10+
tree.insert("a", "a", 0);
11+
tree.flush_active_memtable(0)?;
12+
assert_eq!(1, tree.segment_count());
13+
}
14+
15+
let ds_store = folder.join("segments").join("._0");
16+
std::fs::File::create(&ds_store)?;
17+
assert!(ds_store.try_exists()?);
18+
19+
{
20+
let tree = Config::new(&folder).open()?;
21+
assert_eq!(1, tree.segment_count());
22+
}
23+
assert!(ds_store.try_exists()?);
24+
25+
Ok(())
26+
}

0 commit comments

Comments
 (0)