From 414641eb95cd006f4f291d259fe912885050bd2c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 14 Aug 2026 18:26:54 -0700 Subject: [PATCH] std.fs.path.resolvePosix: avoid deprecated managed array list API --- lib/std/fs/path.zig | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig index d5b7f751acf77f6a4b98951f8039bbbf4c20b752..55e362f456e88f6cc36715f04260e160a17a31cd 100644 --- a/lib/std/fs/path.zig +++ b/lib/std/fs/path.zig @@ -1093,23 +1093,23 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) Allocator return result.toOwnedSlice(allocator); } -/// This function is like a series of `cd` statements executed one after another. +/// Simulates a series of relative directory changes on a virtual filesystem +/// that has no symlinks. /// -/// It resolves "." and ".." to the best of its ability, but will not convert relative paths to -/// an absolute path, use Io.Dir.realpath instead. -/// -/// ".." components may persist in the resolved path if the resolved path is relative. +/// "." and ".." are resolved but will not make relative paths absolute. ".." +/// components remain in the resolved path when the resolved path is relative +/// and there are not previous components to cancel out. /// /// The result does not have a trailing path separator. /// /// This function does not perform any syscalls. Executing this series of path -/// lookups on the actual filesystem may produce different results due to +/// lookups on an actual filesystem may produce different results due to /// symlinks. -pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.Error![]u8 { +pub fn resolvePosix(gpa: Allocator, paths: []const []const u8) Allocator.Error![]u8 { assert(paths.len > 0); - var result = std.array_list.Managed(u8).init(allocator); - defer result.deinit(); + var result: std.ArrayList(u8) = .empty; + defer result.deinit(gpa); var negative_count: usize = 0; var is_abs = false; @@ -1135,23 +1135,23 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E if (ends_with_slash or result.items.len == 0) break; } } else if (result.items.len > 0 or is_abs) { - try result.ensureUnusedCapacity(1 + component.len); + try result.ensureUnusedCapacity(gpa, 1 + component.len); result.appendAssumeCapacity('/'); result.appendSliceAssumeCapacity(component); } else { - try result.appendSlice(component); + try result.appendSlice(gpa, component); } } } if (result.items.len == 0) { if (is_abs) { - return allocator.dupe(u8, "/"); + return gpa.dupe(u8, "/"); } if (negative_count == 0) { - return allocator.dupe(u8, "."); + return gpa.dupe(u8, "."); } else { - const real_result = try allocator.alloc(u8, 3 * negative_count - 1); + const real_result = try gpa.alloc(u8, 3 * negative_count - 1); var count = negative_count - 1; var i: usize = 0; while (count > 0) : (count -= 1) { @@ -1164,9 +1164,9 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E } if (negative_count == 0) { - return result.toOwnedSlice(); + return result.toOwnedSlice(gpa); } else { - const real_result = try allocator.alloc(u8, 3 * negative_count + result.items.len); + const real_result = try gpa.alloc(u8, 3 * negative_count + result.items.len); var count = negative_count; var i: usize = 0; while (count > 0) : (count -= 1) { -- 2.54.0