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 {...@@ -1046,11 +1046,13 @@ pub fn relative(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 {
1046}1046}
10471047
1048pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 {1048pub 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 });
1050 defer allocator.free(resolved_from);1052 defer allocator.free(resolved_from);
10511053
1052 var clean_up_resolved_to = true;1054 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 });
1054 defer if (clean_up_resolved_to) allocator.free(resolved_to);1056 defer if (clean_up_resolved_to) allocator.free(resolved_to);
10551057
1056 const parsed_from = windowsParsePath(resolved_from);1058 const parsed_from = windowsParsePath(resolved_from);
...@@ -1096,12 +1098,8 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !...@@ -1096,12 +1098,8 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
10961098
1097 var result_index: usize = 0;1099 var result_index: usize = 0;
1098 while (result_index < up_index_end) {1100 while (result_index < up_index_end) {
1099 result[result_index] = '.';1101 result[result_index..][0..3].* = "..\\".*;
1100 result_index += 1;1102 result_index += 3;
1101 result[result_index] = '.';
1102 result_index += 1;
1103 result[result_index] = '\\';
1104 result_index += 1;
1105 }1103 }
1106 // shave off the trailing slash1104 // shave off the trailing slash
1107 result_index -= 1;1105 result_index -= 1;
...@@ -1121,10 +1119,11 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !...@@ -1121,10 +1119,11 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
1121}1119}
11221120
1123pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 {1121pub 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 });
1125 defer allocator.free(resolved_from);1125 defer allocator.free(resolved_from);
11261126 const resolved_to = try resolvePosix(allocator, &[_][]const u8{ cwd, to });
1127 const resolved_to = try resolvePosix(allocator, &[_][]const u8{to});
1128 defer allocator.free(resolved_to);1127 defer allocator.free(resolved_to);
11291128
1130 var from_it = mem.tokenize(u8, resolved_from, "/");1129 var from_it = mem.tokenize(u8, resolved_from, "/");
...@@ -1146,12 +1145,8 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]...@@ -1146,12 +1145,8 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
11461145
1147 var result_index: usize = 0;1146 var result_index: usize = 0;
1148 while (result_index < up_index_end) {1147 while (result_index < up_index_end) {
1149 result[result_index] = '.';1148 result[result_index..][0..3].* = "../".*;
1150 result_index += 1;1149 result_index += 3;
1151 result[result_index] = '.';
1152 result_index += 1;
1153 result[result_index] = '/';
1154 result_index += 1;
1155 }1150 }
1156 if (to_rest.len == 0) {1151 if (to_rest.len == 0) {
1157 // shave off the trailing slash1152 // shave off the trailing slash