aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-20 17:57:03 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-08-20 17:57:03 -0400
commit9e9dce76ffeae54d41ad6485a4fbaf9cd6610c1f (patch)
tree7e6b8713a6e3db7b2e979244df114f600c9ccc37 /std
parent820bf054ea01070b64d6cabf2f20e747909e2611 (diff)
downloadzig-9e9dce76ffeae54d41ad6485a4fbaf9cd6610c1f.tar.gz
zig-9e9dce76ffeae54d41ad6485a4fbaf9cd6610c1f.zip
refactor std.os.makePath to use a switch instead of if
Diffstat (limited to 'std')
-rw-r--r--std/os/index.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/std/os/index.zig b/std/os/index.zig
index 34be1acabe..caef6d1e37 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -1149,22 +1149,22 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
var end_index: usize = resolved_path.len;
while (true) {
- makeDir(allocator, resolved_path[0..end_index]) catch |err| {
- if (err == error.PathAlreadyExists) {
+ makeDir(allocator, resolved_path[0..end_index]) catch |err| switch (err) {
+ error.PathAlreadyExists => {
// TODO stat the file and return an error if it's not a directory
// this is important because otherwise a dangling symlink
// could cause an infinite loop
if (end_index == resolved_path.len) return;
- } else if (err == error.FileNotFound) {
+ },
+ error.FileNotFound => {
// march end_index backward until next path component
while (true) {
end_index -= 1;
if (os.path.isSep(resolved_path[end_index])) break;
}
continue;
- } else {
- return err;
- }
+ },
+ else => return err,
};
if (end_index == resolved_path.len) return;
// march end_index forward until next path component