Skip to content

Commit 3605b7e

Browse files
committed
Auto merge of #1098 - ranma42:safe-untar, r=brson
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.
2 parents 4bc7522 + ab40997 commit 3605b7e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/rustup-dist/src/component/package.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ fn unpack_without_first_dir<R: Read>(archive: &mut tar::Archive<R>, path: &Path)
199199
// Throw away the first path component
200200
components.next();
201201
let full_path = path.join(&components.as_path());
202+
203+
// Create the full path to the entry if it does not exist already
204+
match full_path.parent() {
205+
Some(parent) if !parent.exists() =>
206+
try!(::std::fs::create_dir_all(&parent).chain_err(|| ErrorKind::ExtractingPackage)),
207+
_ => (),
208+
};
209+
202210
try!(entry.unpack(&full_path).chain_err(|| ErrorKind::ExtractingPackage));
203211
}
204212

0 commit comments

Comments
 (0)