Skip to content

Commit

Permalink
Add documentation to stripping of tar path (alexcrichton#220)
Browse files Browse the repository at this point in the history
tar-rs will strip any current directory out of the paths users are
passing into the API. This documents that behavior and adds a test
to ensure the documented behavior.
  • Loading branch information
schultetwin1 authored and moschroe committed Jun 11, 2020
1 parent 8b141d0 commit c612792
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down
6 changes: 6 additions & 0 deletions tests/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down

0 comments on commit c612792

Please sign in to comment.