Skip to content

Commit 851c7c5

Browse files
committed
cleanup
1 parent 1bcb6b8 commit 851c7c5

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

src/link.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,16 @@ impl LinkGroup {
9191
let path = source.path();
9292
let target = self.target.join(&source.file);
9393
println!("linking {:?} to {:?}", path, target);
94-
fs::create_dir_all(target.parent().unwrap()).unwrap();
94+
fs::create_dir_all(
95+
target.parent().expect(
96+
format!(
97+
"could not get parent directory of link {}",
98+
target.display()
99+
)
100+
.as_str(),
101+
),
102+
)
103+
.expect(format!("could not create parent tree for link {}", target.display()).as_str());
95104
match symlink(path, target) {
96105
Ok(_) => {}
97106
Err(e) => {
@@ -109,15 +118,18 @@ impl LinkGroup {
109118
println!("unlinking {:?}", target);
110119
match fs::symlink_metadata(&target) {
111120
Ok(f) if f.is_symlink() && target.read_link().unwrap() == source.path() => {
112-
fs::remove_file(&target).unwrap();
113-
let mut parent = target.parent().unwrap();
114-
while !leave_orphans
115-
&& parent.read_dir().unwrap().count() == 0
116-
&& parent != self.target
117-
{
118-
fs::remove_dir(parent).unwrap();
119-
println!("removing {:?}", parent);
120-
parent = parent.parent().unwrap();
121+
fs::remove_file(&target)
122+
.expect(format!("could not remove link {}", target.display()).as_str());
123+
if !leave_orphans {
124+
let mut parent = target.parent().unwrap();
125+
while parent.read_dir().unwrap().count() == 0 && parent != self.target {
126+
fs::remove_dir(parent).unwrap();
127+
println!("removing {:?}", parent);
128+
match parent.parent() {
129+
Some(p) if p != self.target => parent = p,
130+
_ => break,
131+
}
132+
}
121133
}
122134
}
123135
_ => {}

0 commit comments

Comments
 (0)