authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-20 17:57:03-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-20 17:57:03-04:00
log9e9dce76ffeae54d41ad6485a4fbaf9cd6610c1f
tree7e6b8713a6e3db7b2e979244df114f600c9ccc37
parent820bf054ea01070b64d6cabf2f20e747909e2611

refactor std.os.makePath to use a switch instead of if


1 files changed, 6 insertions(+), 6 deletions(-)

std/os/index.zig+6-6
...@@ -1149,22 +1149,22 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {...@@ -1149,22 +1149,22 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
11491149
1150 var end_index: usize = resolved_path.len;1150 var end_index: usize = resolved_path.len;
1151 while (true) {1151 while (true) {
1152 makeDir(allocator, resolved_path[0..end_index]) catch |err| {1152 makeDir(allocator, resolved_path[0..end_index]) catch |err| switch (err) {
1153 if (err == error.PathAlreadyExists) {1153 error.PathAlreadyExists => {
1154 // TODO stat the file and return an error if it's not a directory1154 // TODO stat the file and return an error if it's not a directory
1155 // this is important because otherwise a dangling symlink1155 // this is important because otherwise a dangling symlink
1156 // could cause an infinite loop1156 // could cause an infinite loop
1157 if (end_index == resolved_path.len) return;1157 if (end_index == resolved_path.len) return;
1158 } else if (err == error.FileNotFound) {1158 },
1159 error.FileNotFound => {
1159 // march end_index backward until next path component1160 // march end_index backward until next path component
1160 while (true) {1161 while (true) {
1161 end_index -= 1;1162 end_index -= 1;
1162 if (os.path.isSep(resolved_path[end_index])) break;1163 if (os.path.isSep(resolved_path[end_index])) break;
1163 }1164 }
1164 continue;1165 continue;
1165 } else {1166 },
1166 return err;1167 else => return err,
1167 }
1168 };1168 };
1169 if (end_index == resolved_path.len) return;1169 if (end_index == resolved_path.len) return;
1170 // march end_index forward until next path component1170 // march end_index forward until next path component