Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 363 #364

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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