authorgravatar for 38442746+pluick@users.noreply.github.compluick <38442746+pluick@users.noreply.github.com> 2023-01-05 03:37:00-06:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-01-05 01:37:00-08:00
log2d617c482ca24563a27125d626ac51e194d49eff
treeebc0dd086752d85b3337aa0bfcfdfd0c1c20055c
parentf83834993e2628e347da71a11ffb07c804fc46c5
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Fix cache-dir specified on the command line (#14076)

The resolvePosix and resolveWindows routines changed behaviour in an earlier commit so that the return value is not always an absolute path. That caused the relativePosix and relativeWindows to return a relative path that is not correct. The change in behaviour mentioned above would cause a local cache-dir to be created in the wrong directory when --cache-dir was specified for a build.

1 files changed, 12 insertions(+), 17 deletions(-)

lib/std/fs/path.zig+12-17
......@@ -1046,11 +1046,13 @@ pub fn relative(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 {
10461046}
10471047
10481048pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 {
1049 const resolved_from = try resolveWindows(allocator, &[_][]const u8{from});
1049 const cwd = try process.getCwdAlloc(allocator);
1050 defer allocator.free(cwd);
1051 const resolved_from = try resolveWindows(allocator, &[_][]const u8{ cwd, from });
10501052 defer allocator.free(resolved_from);
10511053
10521054 var clean_up_resolved_to = true;
1053 const resolved_to = try resolveWindows(allocator, &[_][]const u8{to});
1055 const resolved_to = try resolveWindows(allocator, &[_][]const u8{ cwd, to });
10541056 defer if (clean_up_resolved_to) allocator.free(resolved_to);
10551057
10561058 const parsed_from = windowsParsePath(resolved_from);
......@@ -1096,12 +1098,8 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
10961098
10971099 var result_index: usize = 0;
10981100 while (result_index < up_index_end) {
1099 result[result_index] = '.';
1100 result_index += 1;
1101 result[result_index] = '.';
1102 result_index += 1;
1103 result[result_index] = '\\';
1104 result_index += 1;
1101 result[result_index..][0..3].* = "..\\".*;
1102 result_index += 3;
11051103 }
11061104 // shave off the trailing slash
11071105 result_index -= 1;
......@@ -1121,10 +1119,11 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
11211119}
11221120
11231121pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 {
1124 const resolved_from = try resolvePosix(allocator, &[_][]const u8{from});
1122 const cwd = try process.getCwdAlloc(allocator);
1123 defer allocator.free(cwd);
1124 const resolved_from = try resolvePosix(allocator, &[_][]const u8{ cwd, from });
11251125 defer allocator.free(resolved_from);
1126
1127 const resolved_to = try resolvePosix(allocator, &[_][]const u8{to});
1126 const resolved_to = try resolvePosix(allocator, &[_][]const u8{ cwd, to });
11281127 defer allocator.free(resolved_to);
11291128
11301129 var from_it = mem.tokenize(u8, resolved_from, "/");
......@@ -1146,12 +1145,8 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
11461145
11471146 var result_index: usize = 0;
11481147 while (result_index < up_index_end) {
1149 result[result_index] = '.';
1150 result_index += 1;
1151 result[result_index] = '.';
1152 result_index += 1;
1153 result[result_index] = '/';
1154 result_index += 1;
1148 result[result_index..][0..3].* = "../".*;
1149 result_index += 3;
11551150 }
11561151 if (to_rest.len == 0) {
11571152 // shave off the trailing slash