mirror of
https://github.com/cobalt-org/cobalt.rs
synced 2024-11-15 08:27:15 +00:00
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:
parent
2b1d499a7d
commit
f8c6034342
1 changed files with 3 additions and 4 deletions
|
@ -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())));
|
||||
|
|
Loading…
Reference in a new issue