diff --git a/backhand-test/tests/issues.rs b/backhand-test/tests/issues.rs index e6d67aca..bf621cf1 100644 --- a/backhand-test/tests/issues.rs +++ b/backhand-test/tests/issues.rs @@ -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(), + }; +} diff --git a/backhand/src/filesystem/node.rs b/backhand/src/filesystem/node.rs index 2c35e4ee..10eec112 100644 --- a/backhand/src/filesystem/node.rs +++ b/backhand/src/filesystem/node.rs @@ -158,8 +158,12 @@ impl Nodes { 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