| ... | @@ -1093,23 +1093,23 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) Allocator | ... | @@ -1093,23 +1093,23 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) Allocator |
| 1093 | return result.toOwnedSlice(allocator); | 1093 | return result.toOwnedSlice(allocator); |
| 1094 | } | 1094 | } |
| 1095 | | 1095 | |
| 1096 | /// This function is like a series of `cd` statements executed one after another. | 1096 | /// Simulates a series of relative directory changes on a virtual filesystem |
| 1097 | /// | 1097 | /// that has no symlinks. |
| 1098 | /// It resolves "." and ".." to the best of its ability, but will not convert relative paths to | | |
| 1099 | /// an absolute path, use Io.Dir.realpath instead. | | |
| 1100 | /// | 1098 | /// |
| 1101 | /// ".." components may persist in the resolved path if the resolved path is relative. | 1099 | /// "." and ".." are resolved but will not make relative paths absolute. ".." |
| | 1100 | /// components remain in the resolved path when the resolved path is relative |
| | 1101 | /// and there are not previous components to cancel out. |
| 1102 | /// | 1102 | /// |
| 1103 | /// The result does not have a trailing path separator. | 1103 | /// The result does not have a trailing path separator. |
| 1104 | /// | 1104 | /// |
| 1105 | /// This function does not perform any syscalls. Executing this series of path | 1105 | /// This function does not perform any syscalls. Executing this series of path |
| 1106 | /// lookups on the actual filesystem may produce different results due to | 1106 | /// lookups on an actual filesystem may produce different results due to |
| 1107 | /// symlinks. | 1107 | /// symlinks. |
| 1108 | pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.Error![]u8 { | 1108 | pub fn resolvePosix(gpa: Allocator, paths: []const []const u8) Allocator.Error![]u8 { |
| 1109 | assert(paths.len > 0); | 1109 | assert(paths.len > 0); |
| 1110 | | 1110 | |
| 1111 | var result = std.array_list.Managed(u8).init(allocator); | 1111 | var result: std.ArrayList(u8) = .empty; |
| 1112 | defer result.deinit(); | 1112 | defer result.deinit(gpa); |
| 1113 | | 1113 | |
| 1114 | var negative_count: usize = 0; | 1114 | var negative_count: usize = 0; |
| 1115 | var is_abs = false; | 1115 | var is_abs = false; |
| ... | @@ -1135,23 +1135,23 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E | ... | @@ -1135,23 +1135,23 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E |
| 1135 | if (ends_with_slash or result.items.len == 0) break; | 1135 | if (ends_with_slash or result.items.len == 0) break; |
| 1136 | } | 1136 | } |
| 1137 | } else if (result.items.len > 0 or is_abs) { | 1137 | } else if (result.items.len > 0 or is_abs) { |
| 1138 | try result.ensureUnusedCapacity(1 + component.len); | 1138 | try result.ensureUnusedCapacity(gpa, 1 + component.len); |
| 1139 | result.appendAssumeCapacity('/'); | 1139 | result.appendAssumeCapacity('/'); |
| 1140 | result.appendSliceAssumeCapacity(component); | 1140 | result.appendSliceAssumeCapacity(component); |
| 1141 | } else { | 1141 | } else { |
| 1142 | try result.appendSlice(component); | 1142 | try result.appendSlice(gpa, component); |
| 1143 | } | 1143 | } |
| 1144 | } | 1144 | } |
| 1145 | } | 1145 | } |
| 1146 | | 1146 | |
| 1147 | if (result.items.len == 0) { | 1147 | if (result.items.len == 0) { |
| 1148 | if (is_abs) { | 1148 | if (is_abs) { |
| 1149 | return allocator.dupe(u8, "/"); | 1149 | return gpa.dupe(u8, "/"); |
| 1150 | } | 1150 | } |
| 1151 | if (negative_count == 0) { | 1151 | if (negative_count == 0) { |
| 1152 | return allocator.dupe(u8, "."); | 1152 | return gpa.dupe(u8, "."); |
| 1153 | } else { | 1153 | } else { |
| 1154 | const real_result = try allocator.alloc(u8, 3 * negative_count - 1); | 1154 | const real_result = try gpa.alloc(u8, 3 * negative_count - 1); |
| 1155 | var count = negative_count - 1; | 1155 | var count = negative_count - 1; |
| 1156 | var i: usize = 0; | 1156 | var i: usize = 0; |
| 1157 | while (count > 0) : (count -= 1) { | 1157 | while (count > 0) : (count -= 1) { |
| ... | @@ -1164,9 +1164,9 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E | ... | @@ -1164,9 +1164,9 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E |
| 1164 | } | 1164 | } |
| 1165 | | 1165 | |
| 1166 | if (negative_count == 0) { | 1166 | if (negative_count == 0) { |
| 1167 | return result.toOwnedSlice(); | 1167 | return result.toOwnedSlice(gpa); |
| 1168 | } else { | 1168 | } else { |
| 1169 | const real_result = try allocator.alloc(u8, 3 * negative_count + result.items.len); | 1169 | const real_result = try gpa.alloc(u8, 3 * negative_count + result.items.len); |
| 1170 | var count = negative_count; | 1170 | var count = negative_count; |
| 1171 | var i: usize = 0; | 1171 | var i: usize = 0; |
| 1172 | while (count > 0) : (count -= 1) { | 1172 | while (count > 0) : (count -= 1) { |