Skip to content

Commit

Permalink
fix index wrongly reporting directory entries as files (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
germangb committed May 23, 2019
1 parent e7887fe commit a355169
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mini-fs"
version = "0.2.0"
version = "0.2.1"
authors = ["german gomez <germangb42@gmail.com>"]
description = "Application filesystem to simplify reading files from both the native filesystem and file archives (tar, tar.gz & zip)."
repository = "https://github.com/germangb/mini-fs"
Expand Down
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a, M> Entries<'a, M> {
iter.next().map(|(n, _)| Entry {
name: n.as_os_str(),
meta: None,
kind: EntryKind::File,
kind: EntryKind::Dir,
})
} else {
None
Expand Down
25 changes: 24 additions & 1 deletion tests/entries.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
use mini_fs::prelude::*;
use mini_fs::{EntryKind, LocalFs, MiniFs};
use mini_fs::{EntryKind, LocalFs, MiniFs, RamFs};
use std::collections::BTreeMap;
use std::ffi::OsStr;
use std::io::Result;

// https://github.com/germangb/mini-fs/issues/6
#[test]
fn ram_fs_entries_kind() {
let mut ram = RamFs::new();

ram.touch("/a.txt", b"low a".to_vec());
ram.touch("/A.TXT", b"high a".to_vec());
ram.touch("/b/b.txt", b"low b".to_vec());
ram.touch("/B/B.TXT", b"high b".to_vec());

let mut map = BTreeMap::new();
for entry in ram.entries("/").unwrap() {
let entry = entry.unwrap();
map.insert(entry.name, entry.kind);
}

assert_eq!(Some(&EntryKind::File), map.get(OsStr::new("a.txt")));
assert_eq!(Some(&EntryKind::File), map.get(OsStr::new("A.TXT")));
assert_eq!(Some(&EntryKind::Dir), map.get(OsStr::new("b")));
assert_eq!(Some(&EntryKind::Dir), map.get(OsStr::new("B")));
}

#[test]
fn mini_fs_entries() {
let local = LocalFs::new("./tests/local");
Expand Down

0 comments on commit a355169

Please sign in to comment.