Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
Fixed off-by-one error in output file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Apr 22, 2018
1 parent a9dffc6 commit a88859c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fo2dat"
version = "0.0.1"
version = "0.0.5"
authors = ["Adam Kewley <[email protected]>"]

[dependencies]
Expand Down
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn read_tree_entry(data: &[u8]) -> io::Result<(TreeEntry, usize)> {
return Err(err);
}

let filename = match str::from_utf8(&data[TREE_ENTRY_HEADER_SIZE + 1..filename_len]) {
let filename = match str::from_utf8(&data[TREE_ENTRY_HEADER_SIZE..filename_len]) {
Ok(s) => {
let mut filename = PathBuf::new();
for el in s.split(TREE_ENTRY_PATH_SEPARATOR) {
Expand Down Expand Up @@ -130,8 +130,15 @@ pub fn list_contents(dat_path_str: &str) -> io::Result<()> {

fn mmap_dat(dat_path_str: &str) -> io::Result<Mmap> {
let dat_path = Path::new(&dat_path_str);
let dat_file = File::open(dat_path)?;
unsafe { Mmap::map(&dat_file) }
if dat_path.exists() {
let dat_file = File::open(dat_path)?;
unsafe { Mmap::map(&dat_file) }
} else {
let err_kind = std::io::ErrorKind::NotFound;
let err_msg = format!("{}: no such file", dat_path_str);
let err = std::io::Error::new(err_kind, err_msg);
return Err(err);
}
}

fn find_entries(dat_file: &[u8]) -> io::Result<TreeEntryIterator> {
Expand Down

0 comments on commit a88859c

Please sign in to comment.