| ... | ... | @@ -1046,11 +1046,13 @@ pub fn relative(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 { |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | pub 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 | 1052 | defer allocator.free(resolved_from); |
| 1051 | 1053 | |
| 1052 | 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 | 1056 | defer if (clean_up_resolved_to) allocator.free(resolved_to); |
| 1055 | 1057 | |
| 1056 | 1058 | const parsed_from = windowsParsePath(resolved_from); |
| ... | ... | @@ -1096,12 +1098,8 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) ! |
| 1096 | 1098 | |
| 1097 | 1099 | var result_index: usize = 0; |
| 1098 | 1100 | 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; |
| 1105 | 1103 | } |
| 1106 | 1104 | // shave off the trailing slash |
| 1107 | 1105 | result_index -= 1; |
| ... | ... | @@ -1121,10 +1119,11 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) ! |
| 1121 | 1119 | } |
| 1122 | 1120 | |
| 1123 | 1121 | pub 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 | 1125 | 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 }); |
| 1128 | 1127 | defer allocator.free(resolved_to); |
| 1129 | 1128 | |
| 1130 | 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 | 1145 | |
| 1147 | 1146 | var result_index: usize = 0; |
| 1148 | 1147 | 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; |
| 1155 | 1150 | } |
| 1156 | 1151 | if (to_rest.len == 0) { |
| 1157 | 1152 | // shave off the trailing slash |