| ... | ... | @@ -218,16 +218,10 @@ test "Dir.readLink" { |
| 218 | 218 | // test 1: symlink to a file |
| 219 | 219 | try setupSymlink(io, ctx.dir, file_target_path, "symlink1", .{}); |
| 220 | 220 | try testReadLink(io, ctx.dir, canonical_file_target_path, "symlink1"); |
| 221 | | if (builtin.os.tag == .windows) { |
| 222 | | try testReadLinkW(testing.allocator, ctx.dir, canonical_file_target_path, "symlink1"); |
| 223 | | } |
| 224 | 221 | |
| 225 | 222 | // test 2: symlink to a directory (can be different on Windows) |
| 226 | 223 | try setupSymlink(io, ctx.dir, dir_target_path, "symlink2", .{ .is_directory = true }); |
| 227 | 224 | try testReadLink(io, ctx.dir, canonical_dir_target_path, "symlink2"); |
| 228 | | if (builtin.os.tag == .windows) { |
| 229 | | try testReadLinkW(testing.allocator, ctx.dir, canonical_dir_target_path, "symlink2"); |
| 230 | | } |
| 231 | 225 | |
| 232 | 226 | // test 3: relative path symlink |
| 233 | 227 | const parent_file = ".." ++ Dir.path.sep_str ++ "target.txt"; |
| ... | ... | @@ -236,9 +230,6 @@ test "Dir.readLink" { |
| 236 | 230 | defer subdir.close(io); |
| 237 | 231 | try setupSymlink(io, subdir, canonical_parent_file, "relative-link.txt", .{}); |
| 238 | 232 | try testReadLink(io, subdir, canonical_parent_file, "relative-link.txt"); |
| 239 | | if (builtin.os.tag == .windows) { |
| 240 | | try testReadLinkW(testing.allocator, subdir, canonical_parent_file, "relative-link.txt"); |
| 241 | | } |
| 242 | 233 | } |
| 243 | 234 | }.impl); |
| 244 | 235 | } |
| ... | ... | @@ -275,17 +266,6 @@ fn testReadLink(io: Io, dir: Dir, target_path: []const u8, symlink_path: []const |
| 275 | 266 | try expectEqualStrings(target_path, actual); |
| 276 | 267 | } |
| 277 | 268 | |
| 278 | | fn testReadLinkW(allocator: Allocator, dir: Dir, target_path: []const u8, symlink_path: []const u8) !void { |
| 279 | | const target_path_w = try std.unicode.wtf8ToWtf16LeAlloc(allocator, target_path); |
| 280 | | defer allocator.free(target_path_w); |
| 281 | | // Calling the W functions directly requires the path to be NT-prefixed |
| 282 | | const symlink_path_w = try std.os.windows.sliceToPrefixedFileW(dir.handle, symlink_path); |
| 283 | | const wtf16_buffer = try allocator.alloc(u16, target_path_w.len); |
| 284 | | defer allocator.free(wtf16_buffer); |
| 285 | | const actual = try dir.readLinkW(symlink_path_w.span(), wtf16_buffer); |
| 286 | | try expectEqualSlices(u16, target_path_w, actual); |
| 287 | | } |
| 288 | | |
| 289 | 269 | fn testReadLinkAbsolute(io: Io, target_path: []const u8, symlink_path: []const u8) !void { |
| 290 | 270 | var buffer: [Dir.max_path_bytes]u8 = undefined; |
| 291 | 271 | const given = buffer[0..try Dir.readLinkAbsolute(io, symlink_path, &buffer)]; |
| ... | ... | @@ -2153,6 +2133,7 @@ test "invalid UTF-8/WTF-8 paths" { |
| 2153 | 2133 | try expectError(expected_err, Dir.rename(ctx.dir, invalid_path, ctx.dir, invalid_path, io)); |
| 2154 | 2134 | |
| 2155 | 2135 | if (native_os != .wasi and ctx.path_type != .relative) { |
| 2136 | var buf: [Dir.max_path_bytes]u8 = undefined; |
| 2156 | 2137 | try expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, io, .{})); |
| 2157 | 2138 | try expectError(expected_err, Dir.makeDirAbsolute(io, invalid_path, .default_dir)); |
| 2158 | 2139 | try expectError(expected_err, Dir.deleteDirAbsolute(io, invalid_path)); |
| ... | ... | @@ -2162,10 +2143,10 @@ test "invalid UTF-8/WTF-8 paths" { |
| 2162 | 2143 | try expectError(expected_err, Dir.accessAbsolute(io, invalid_path, .{})); |
| 2163 | 2144 | try expectError(expected_err, Dir.createFileAbsolute(io, invalid_path, .{})); |
| 2164 | 2145 | try expectError(expected_err, Dir.deleteFileAbsolute(io, invalid_path)); |
| 2165 | | var readlink_buf: [Dir.max_path_bytes]u8 = undefined; |
| 2166 | | try expectError(expected_err, Dir.readLinkAbsolute(io, invalid_path, &readlink_buf)); |
| 2146 | try expectError(expected_err, Dir.readLinkAbsolute(io, invalid_path, &buf)); |
| 2167 | 2147 | try expectError(expected_err, Dir.symLinkAbsolute(io, invalid_path, invalid_path, .{})); |
| 2168 | | try expectError(expected_err, Dir.realPathAbsoluteAlloc(io, invalid_path, testing.allocator)); |
| 2148 | try expectError(expected_err, Dir.realPathFileAbsolute(io, invalid_path, &buf)); |
| 2149 | try expectError(expected_err, Dir.realPathFileAbsoluteAlloc(io, invalid_path, testing.allocator)); |
| 2169 | 2150 | } |
| 2170 | 2151 | } |
| 2171 | 2152 | }.impl); |