| ... | @@ -218,6 +218,32 @@ test "Dir.readLink" { | ... | @@ -218,6 +218,32 @@ test "Dir.readLink" { |
| 218 | }.impl); | 218 | }.impl); |
| 219 | } | 219 | } |
| 220 | | 220 | |
| | 221 | test "Dir.readLink on non-symlinks" { |
| | 222 | try testWithAllSupportedPathTypes(struct { |
| | 223 | fn impl(ctx: *TestContext) !void { |
| | 224 | const file_path = try ctx.transformPath("file.txt"); |
| | 225 | try ctx.dir.writeFile(.{ .sub_path = file_path, .data = "nonsense" }); |
| | 226 | const dir_path = try ctx.transformPath("subdir"); |
| | 227 | try ctx.dir.makeDir(dir_path); |
| | 228 | |
| | 229 | // file |
| | 230 | var buffer: [fs.max_path_bytes]u8 = undefined; |
| | 231 | try std.testing.expectError(error.NotLink, ctx.dir.readLink(file_path, &buffer)); |
| | 232 | if (builtin.os.tag == .windows) { |
| | 233 | var file_path_w = try std.os.windows.sliceToPrefixedFileW(ctx.dir.fd, file_path); |
| | 234 | try std.testing.expectError(error.NotLink, ctx.dir.readLinkW(file_path_w.span(), &file_path_w.data)); |
| | 235 | } |
| | 236 | |
| | 237 | // dir |
| | 238 | try std.testing.expectError(error.NotLink, ctx.dir.readLink(dir_path, &buffer)); |
| | 239 | if (builtin.os.tag == .windows) { |
| | 240 | var dir_path_w = try std.os.windows.sliceToPrefixedFileW(ctx.dir.fd, dir_path); |
| | 241 | try std.testing.expectError(error.NotLink, ctx.dir.readLinkW(dir_path_w.span(), &dir_path_w.data)); |
| | 242 | } |
| | 243 | } |
| | 244 | }.impl); |
| | 245 | } |
| | 246 | |
| 221 | fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void { | 247 | fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void { |
| 222 | var buffer: [fs.max_path_bytes]u8 = undefined; | 248 | var buffer: [fs.max_path_bytes]u8 = undefined; |
| 223 | const actual = try dir.readLink(symlink_path, buffer[0..]); | 249 | const actual = try dir.readLink(symlink_path, buffer[0..]); |