Skip to content

Commit

Permalink
Merge pull request #364 from rbran/fix-363
Browse files Browse the repository at this point in the history
Fix issue 363
  • Loading branch information
wcampbell0x2a authored Dec 1, 2023
2 parents ac1e980 + 570e0e0 commit 4bc4ea3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions backhand-test/tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ fn issue_359() {
fs.push_dir_all("a/b/c/d/e/f/g", header).unwrap();
fs.write(&mut writer).unwrap();
}

/// https://github.com/wcampbell0x2a/backhand/issues/363
#[test]
#[cfg(feature = "xz")]
fn issue_363() {
let dummy_file = std::io::Cursor::new(&[]);
let dummy_header = backhand::NodeHeader::default();
let mut fs = backhand::FilesystemWriter::default();
// create a files
fs.push_file(dummy_file.clone(), "a", dummy_header).unwrap();
// try to put a file inside the first file
match fs.push_file(dummy_file, "a/b", dummy_header) {
// correct result: InvalidFilePath (or equivalent error?)
Err(backhand::BackhandError::InvalidFilePath) => {}
Ok(_) => panic!("Invalid result"),
x => x.unwrap(),
};
}
8 changes: 6 additions & 2 deletions backhand/src/filesystem/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ impl<T> Nodes<T> {
let path = &node.fullpath;
let parent = node.fullpath.parent().ok_or(BackhandError::InvalidFilePath)?;

//check the parent exists
let _parent = self.node_mut(parent).ok_or(BackhandError::InvalidFilePath)?;
//check if the parent exists and is a dir
let parent = self.node_mut(parent).ok_or(BackhandError::InvalidFilePath)?;
match &parent.inner {
InnerNode::Dir(_) => {}
_ => return Err(BackhandError::InvalidFilePath),
}

match self.nodes.binary_search_by(|node| node.fullpath.as_path().cmp(path)) {
//file with this fullpath already exists
Expand Down

0 comments on commit 4bc4ea3

Please sign in to comment.