summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2023-01-27 14:52:38 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2023-01-27 14:52:38 +0000
commit10e79d4bc7a85ff28ffbcfb1584c80bd5b796eae (patch)
tree12765236b2fb452cb2246cdeb8348647fb452ca1
parent39b32521291dde5254d6148b3601b2c17bb4cdad (diff)
downloadpam_usercg_rust-10e79d4bc7a85ff28ffbcfb1584c80bd5b796eae.tar.gz
pam_usercg_rust-10e79d4bc7a85ff28ffbcfb1584c80bd5b796eae.tar.xz
pam_usercg_rust-10e79d4bc7a85ff28ffbcfb1584c80bd5b796eae.zip
Shorten create_and_open_dir error handling
-rw-r--r--src/lib.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 73cd9b0..6f68c22 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,13 +15,11 @@ fn create_and_open_dir<P: AsRef<Path> + Copy>(
d: &Dir,
path: P,
) -> std::io::Result<Dir> {
- match d.create_dir(path) {
- Ok(()) => Ok(()),
- Err(e) => match e.kind() {
- ErrorKind::AlreadyExists => Ok(()),
- _ => Err(e),
- },
- }?;
+ if let Err(e) = d.create_dir(path) {
+ if e.kind() != ErrorKind::AlreadyExists {
+ return Err(e);
+ }
+ }
d.open_dir(path)
}