Skip to content

Commit

Permalink
Auto merge of #1098 - ranma42:safe-untar, r=brson
Browse files Browse the repository at this point in the history
Ensure that intermediate directories exist when unpacking an entry

The `unpack` function assumes that the directory in which the file is
being extracted exists, while most `tar` tools will automatically
create the intermediate directories if they are missing.

This would have avoided #1092.
  • Loading branch information
bors committed May 10, 2017
2 parents b8443be + ab40997 commit 6a5f6f2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/rustup-dist/src/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ fn unpack_without_first_dir<R: Read>(archive: &mut tar::Archive<R>, path: &Path)
// Throw away the first path component
components.next();
let full_path = path.join(&components.as_path());

// Create the full path to the entry if it does not exist already
match full_path.parent() {
Some(parent) if !parent.exists() =>
try!(::std::fs::create_dir_all(&parent).chain_err(|| ErrorKind::ExtractingPackage)),
_ => (),
};

try!(entry.unpack(&full_path).chain_err(|| ErrorKind::ExtractingPackage));
}

Expand Down

0 comments on commit 6a5f6f2

Please sign in to comment.