authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-14 18:26:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-19 12:39:36-07:00
log414641eb95cd006f4f291d259fe912885050bd2c
tree33be7ad3250e9b1aea37599828767b28f560076e
parentba0cfda93dabd07ded441ecf475fc28a90bd495e

std.fs.path.resolvePosix: avoid deprecated managed array list API


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

lib/std/fs/path.zig+16-16
...@@ -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}
10951095
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 path1105/// This function does not perform any syscalls. Executing this series of path
1106/// lookups on the actual filesystem may produce different results due to1106/// lookups on an actual filesystem may produce different results due to
1107/// symlinks.1107/// symlinks.
1108pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.Error![]u8 {1108pub fn resolvePosix(gpa: Allocator, paths: []const []const u8) Allocator.Error![]u8 {
1109 assert(paths.len > 0);1109 assert(paths.len > 0);
11101110
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);
11131113
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 }
11461146
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 }
11651165
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) {