Repository: alexcrichton/tar-rs (language: rust)

Issue:
Don't remove CurrentDir on Copy Path
The current logic for copy `copy_path_into` will remove any current directories, aka `.`, from the path. For example, if you pass in the path `./control` the header will have the path `control`.

This logic can be found here:

https://github.com/alexcrichton/tar-rs/blob/8b141d0d7119a412373a558d0b884c519b6d44a8/src/header.rs#L1497-L1500

I'm trying to use this repository to build Debian packages. Those packages contain a control.tar file which contain a file named `./control`. With the current implementation of tar-rs, its impossible to mimic this functionality.

My suggestion would be to not remove any current directories in `copy_path_into`.


Discussion / hints:

Fix patch:
diff --git a/src/header.rs b/src/header.rs
index 4214e67f..bcce1808 100644
--- a/src/header.rs
+++ b/src/header.rs
@@ -362,7 +362,8 @@ impl Header {
     ///
     /// This function will set the pathname listed in this header, encoding it
     /// in the appropriate format. May fail if the path is too long or if the
-    /// path specified is not Unicode and this is a Windows platform.
+    /// path specified is not Unicode and this is a Windows platform. Will
+    /// strip out any "." path component, which signifies the current directory.
     pub fn set_path<P: AsRef<Path>>(&mut self, p: P) -> io::Result<()> {
         self._set_path(p.as_ref())
     }
@@ -414,7 +415,8 @@ impl Header {
     ///
     /// This function will set the linkname listed in this header, encoding it
     /// in the appropriate format. May fail if the link name is too long or if
-    /// the path specified is not Unicode and this is a Windows platform.
+    /// the path specified is not Unicode and this is a Windows platform. Will
+    /// strip out any "." path component, which signifies the current directory.
     pub fn set_link_name<P: AsRef<Path>>(&mut self, p: P) -> io::Result<()> {
         self._set_link_name(p.as_ref())
     }


Test patch:
diff --git a/tests/header/mod.rs b/tests/header/mod.rs
index f9c8df7c..a85a1472 100644
--- a/tests/header/mod.rs
+++ b/tests/header/mod.rs
@@ -139,6 +139,12 @@ fn set_path() {
         assert_eq!(t!(h.path()).to_str(), Some("foo\\bar"));
     }
 
+    // set_path documentation explictly states it removes any ".", signfying the
+    // current directory, from the path. This test ensures that documented
+    // beavhior occurs
+    t!(h.set_path("./control"));
+    assert_eq!(t!(h.path()).to_str(), Some("control"));
+
     let long_name = iter::repeat("foo").take(100).collect::<String>();
     let medium1 = iter::repeat("foo").take(52).collect::<String>();
     let medium2 = iter::repeat("fo/").take(52).collect::<String>();