Improve dir creation during copy

This fixes two minor problems introduced by 02f866cade:

- We disallow the use of unsafe `unwrap`, even if they were unlikely to
  blow up, because errors should not invoke a panic but be returned as a
  Result. In this case the unwrap is especially unsafe, since
  path.parent() returns None on paths like `/`.
- `dest.clone()` was called without need
This commit is contained in:
Johann 2016-03-21 17:18:47 +01:00
parent 2b1d499a7d
commit f8c6034342

View file

@ -141,10 +141,9 @@ pub fn build(config: &Config) -> Result<()> {
try!(fs::create_dir_all(&dest.join(relative)));
debug!("Created new directory {:?}", dest.join(relative));
} else {
let parent_folder_path = dest.clone()
.join(Path::new(relative).parent().unwrap());
try!(fs::create_dir_all(&parent_folder_path));
if let Some(ref parent) = Path::new(relative).parent() {
try!(fs::create_dir_all(&dest.join(parent)));
}
try!(fs::copy(entry.path(), &dest.join(relative))
.map_err(|_| format!("Could not copy {:?}", entry.path())));