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

This commit is contained in:
Andrew Kelley 2018-08-20 17:57:03 -04:00
parent 820bf054ea
commit 9e9dce76ff

View File

@ -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