Repository: wcampbell0x2a/backhand (language: rust)

Issue:
Panic when using `dir_push_all`
Because the function `FilesystemWriter::dir_push_all` don't insert the uid/gid to the lookup table, this [unwrap](https://github.com/wcampbell0x2a/backhand/blob/d8cc6f1d23c3fc9662254fd35a1c6e35b4cce63f/backhand/src/entry.rs#L150) will create a panic because it will be unable to find the uid/gid after a `FilesystemWriter::write` is called.

# PoC
```rust
fn test() {
    let mut writer = std::io::Cursor::new(vec![]);
    let mut fs = FilesystemWriter::default();
    let header = NodeHeader { permissions: 0, uid: 1, gid: 2, mtime: 3 };
    fs.push_dir_all("a/b/c/d/e/f/g", header).unwrap();
    fs.write(&mut writer).unwrap();
}
```


Discussion / hints:

Fix patch:
diff --git a/backhand/src/filesystem/writer.rs b/backhand/src/filesystem/writer.rs
index 61aaa659..9c590385 100644
--- a/backhand/src/filesystem/writer.rs
+++ b/backhand/src/filesystem/writer.rs
@@ -350,16 +350,7 @@ impl<'a, 'b> FilesystemWriter<'a, 'b> {
                     }
                 }
                 //if the dir don't exists, create it
-                Err(index) => {
-                    self.root.nodes.insert(
-                        index,
-                        Node::new(
-                            file.to_path_buf(),
-                            header,
-                            InnerNode::Dir(SquashfsDir::default()),
-                        ),
-                    );
-                }
+                Err(_index) => self.push_dir(file, header)?,
             }
         }
         Ok(())


Test patch:
diff --git a/backhand-test/tests/issues.rs b/backhand-test/tests/issues.rs
index b8d3496e..e6d67aca 100644
--- a/backhand-test/tests/issues.rs
+++ b/backhand-test/tests/issues.rs
@@ -6,3 +6,14 @@ fn issue_275() {
     let mut fs = backhand::FilesystemWriter::default();
     fs.write(&mut writer).unwrap();
 }
+
+/// https://github.com/wcampbell0x2a/backhand/issues/359
+#[test]
+#[cfg(feature = "xz")]
+fn issue_359() {
+    let mut writer = std::io::Cursor::new(vec![]);
+    let mut fs = backhand::FilesystemWriter::default();
+    let header = backhand::NodeHeader { permissions: 0, uid: 1, gid: 2, mtime: 3 };
+    fs.push_dir_all("a/b/c/d/e/f/g", header).unwrap();
+    fs.write(&mut writer).unwrap();
+}