Skip to content

Commit 127683f

Browse files
committed
export: do not fail if symlink already exists
Although not fully checked, the assumption is that if the destination already exists, that is probably just a previous version of the same link. Signed-off-by: Paul Osborne <[email protected]>
1 parent a26f8d9 commit 127683f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/export.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use std::path;
44
use std::os::unix::fs;
5+
use std::io::ErrorKind;
56
use config::PinConfig;
67
use sysfs_gpio;
78

@@ -25,7 +26,15 @@ pub fn export(pin: &PinConfig, symlink_root: Option<&str>) -> Result<(), sysfs_g
2526
for name in &pin.names {
2627
let mut dst = path::PathBuf::from(symroot);
2728
dst.push(name);
28-
try!(fs::symlink(format!("/sys/class/gpio{}", pin.num), dst));
29+
try!(match fs::symlink(format!("/sys/class/gpio{}", pin.num), dst) {
30+
Ok(_) => Ok(()),
31+
Err(e) => {
32+
match e.kind() {
33+
ErrorKind::AlreadyExists => Ok(()),
34+
_ => Err(e),
35+
}
36+
}
37+
});
2938
}
3039
}
3140

0 commit comments

Comments
 (0)