| ... | ... | @@ -27,7 +27,7 @@ const PathType = enum { |
| 27 | 27 | pub fn isSupported(self: PathType, target_os: std.Target.Os) bool { |
| 28 | 28 | return switch (self) { |
| 29 | 29 | .relative => true, |
| 30 | | .absolute => std.os.isGetFdPathSupportedOnTarget(target_os), |
| 30 | .absolute => target_os.tag == .windows, // TODO: implement getPathForHandle for other targets |
| 31 | 31 | .unc => target_os.tag == .windows, |
| 32 | 32 | }; |
| 33 | 33 | } |
| ... | ... | @@ -49,7 +49,7 @@ const PathType = enum { |
| 49 | 49 | // The final path may not actually exist which would cause realpath to fail. |
| 50 | 50 | // So instead, we get the path of the dir and join it with the relative path. |
| 51 | 51 | var fd_path_buf: [Dir.max_path_bytes]u8 = undefined; |
| 52 | | const dir_path = try std.os.getFdPath(dir.handle, &fd_path_buf); |
| 52 | const dir_path = try getPathForHandle(dir.handle, &fd_path_buf); |
| 53 | 53 | return Dir.path.joinZ(allocator, &.{ dir_path, relative_path }); |
| 54 | 54 | } |
| 55 | 55 | }.transform, |
| ... | ... | @@ -58,7 +58,7 @@ const PathType = enum { |
| 58 | 58 | // Any drive absolute path (C:\foo) can be converted into a UNC path by |
| 59 | 59 | // using '127.0.0.1' as the server name and '<drive letter>$' as the share name. |
| 60 | 60 | var fd_path_buf: [Dir.max_path_bytes]u8 = undefined; |
| 61 | | const dir_path = try std.os.getFdPath(dir.handle, &fd_path_buf); |
| 61 | const dir_path = try getPathForHandle(dir.handle, &fd_path_buf); |
| 62 | 62 | const windows_path_type = windows.getWin32PathType(u8, dir_path); |
| 63 | 63 | switch (windows_path_type) { |
| 64 | 64 | .unc_absolute => return Dir.path.joinZ(allocator, &.{ dir_path, relative_path }), |
| ... | ... | @@ -77,6 +77,19 @@ const PathType = enum { |
| 77 | 77 | } |
| 78 | 78 | }; |
| 79 | 79 | |
| 80 | fn getPathForHandle(handle: File.Handle, out_buffer: *[Dir.max_path_bytes]u8) ![]u8 { |
| 81 | switch (native_os) { |
| 82 | .windows => { |
| 83 | var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined; |
| 84 | const wide_slice = try windows.GetFinalPathNameByHandle(handle, .{}, wide_buf[0..]); |
| 85 | |
| 86 | const end_index = std.unicode.wtf16LeToWtf8(out_buffer, wide_slice); |
| 87 | return out_buffer[0..end_index]; |
| 88 | }, |
| 89 | else => @compileError("TODO or unsupported"), |
| 90 | } |
| 91 | } |
| 92 | |
| 80 | 93 | const TestContext = struct { |
| 81 | 94 | io: Io, |
| 82 | 95 | path_type: PathType, |
| ... | ... | @@ -488,16 +501,16 @@ test "Dir.Iterator" { |
| 488 | 501 | |
| 489 | 502 | // Create iterator. |
| 490 | 503 | var iter = tmp_dir.dir.iterate(); |
| 491 | | while (try iter.next()) |entry| { |
| 504 | while (try iter.next(io)) |entry| { |
| 492 | 505 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 493 | 506 | // which means we'll actually share the `name` pointer between entries! |
| 494 | 507 | const name = try allocator.dupe(u8, entry.name); |
| 495 | | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind }); |
| 508 | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind, .inode = 0 }); |
| 496 | 509 | } |
| 497 | 510 | |
| 498 | 511 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' |
| 499 | | try expect(contains(&entries, .{ .name = "some_file", .kind = .file })); |
| 500 | | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory })); |
| 512 | try expect(contains(&entries, .{ .name = "some_file", .kind = .file, .inode = 0 })); |
| 513 | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); |
| 501 | 514 | } |
| 502 | 515 | |
| 503 | 516 | test "Dir.Iterator many entries" { |
| ... | ... | @@ -523,17 +536,17 @@ test "Dir.Iterator many entries" { |
| 523 | 536 | |
| 524 | 537 | // Create iterator. |
| 525 | 538 | var iter = tmp_dir.dir.iterate(); |
| 526 | | while (try iter.next()) |entry| { |
| 539 | while (try iter.next(io)) |entry| { |
| 527 | 540 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 528 | 541 | // which means we'll actually share the `name` pointer between entries! |
| 529 | 542 | const name = try allocator.dupe(u8, entry.name); |
| 530 | | try entries.append(.{ .name = name, .kind = entry.kind }); |
| 543 | try entries.append(.{ .name = name, .kind = entry.kind, .inode = 0 }); |
| 531 | 544 | } |
| 532 | 545 | |
| 533 | 546 | i = 0; |
| 534 | 547 | while (i < num) : (i += 1) { |
| 535 | 548 | const name = try std.fmt.bufPrint(&buf, "{}", .{i}); |
| 536 | | try expect(contains(&entries, .{ .name = name, .kind = .file })); |
| 549 | try expect(contains(&entries, .{ .name = name, .kind = .file, .inode = 0 })); |
| 537 | 550 | } |
| 538 | 551 | } |
| 539 | 552 | |
| ... | ... | @@ -559,16 +572,16 @@ test "Dir.Iterator twice" { |
| 559 | 572 | |
| 560 | 573 | // Create iterator. |
| 561 | 574 | var iter = tmp_dir.dir.iterate(); |
| 562 | | while (try iter.next()) |entry| { |
| 575 | while (try iter.next(io)) |entry| { |
| 563 | 576 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 564 | 577 | // which means we'll actually share the `name` pointer between entries! |
| 565 | 578 | const name = try allocator.dupe(u8, entry.name); |
| 566 | | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind }); |
| 579 | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind, .inode = 0 }); |
| 567 | 580 | } |
| 568 | 581 | |
| 569 | 582 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' |
| 570 | | try expect(contains(&entries, .{ .name = "some_file", .kind = .file })); |
| 571 | | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory })); |
| 583 | try expect(contains(&entries, .{ .name = "some_file", .kind = .file, .inode = 0 })); |
| 584 | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); |
| 572 | 585 | } |
| 573 | 586 | } |
| 574 | 587 | |
| ... | ... | @@ -595,18 +608,18 @@ test "Dir.Iterator reset" { |
| 595 | 608 | while (i < 2) : (i += 1) { |
| 596 | 609 | var entries = std.array_list.Managed(Dir.Entry).init(allocator); |
| 597 | 610 | |
| 598 | | while (try iter.next()) |entry| { |
| 611 | while (try iter.next(io)) |entry| { |
| 599 | 612 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 600 | 613 | // which means we'll actually share the `name` pointer between entries! |
| 601 | 614 | const name = try allocator.dupe(u8, entry.name); |
| 602 | | try entries.append(.{ .name = name, .kind = entry.kind }); |
| 615 | try entries.append(.{ .name = name, .kind = entry.kind, .inode = 0 }); |
| 603 | 616 | } |
| 604 | 617 | |
| 605 | 618 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' |
| 606 | | try expect(contains(&entries, .{ .name = "some_file", .kind = .file })); |
| 607 | | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory })); |
| 619 | try expect(contains(&entries, .{ .name = "some_file", .kind = .file, .inode = 0 })); |
| 620 | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); |
| 608 | 621 | |
| 609 | | iter.reset(); |
| 622 | iter.reader.reset(); |
| 610 | 623 | } |
| 611 | 624 | } |
| 612 | 625 | |
| ... | ... | @@ -617,7 +630,7 @@ test "Dir.Iterator but dir is deleted during iteration" { |
| 617 | 630 | defer tmp.cleanup(); |
| 618 | 631 | |
| 619 | 632 | // Create directory and setup an iterator for it |
| 620 | | var subdir = try tmp.dir.makeOpenPath(io, "subdir", .{ .iterate = true }); |
| 633 | var subdir = try tmp.dir.makeOpenPath(io, "subdir", .{ .open_options = .{ .iterate = true } }); |
| 621 | 634 | defer subdir.close(io); |
| 622 | 635 | |
| 623 | 636 | var iterator = subdir.iterate(); |
| ... | ... | @@ -632,8 +645,8 @@ test "Dir.Iterator but dir is deleted during iteration" { |
| 632 | 645 | tmp.dir.deleteTree(io, "subdir") catch return error.SkipZigTest; |
| 633 | 646 | |
| 634 | 647 | // Now, when we try to iterate, the next call should return null immediately. |
| 635 | | const entry = try iterator.next(); |
| 636 | | try std.expect(entry == null); |
| 648 | const entry = try iterator.next(io); |
| 649 | try testing.expect(entry == null); |
| 637 | 650 | |
| 638 | 651 | // On Linux, we can opt-in to receiving a more specific error by calling `nextLinux` |
| 639 | 652 | if (native_os == .linux) { |
| ... | ... | @@ -652,8 +665,8 @@ fn contains(entries: *const std.array_list.Managed(Dir.Entry), el: Dir.Entry) bo |
| 652 | 665 | return false; |
| 653 | 666 | } |
| 654 | 667 | |
| 655 | | test "Dir.realpath smoke test" { |
| 656 | | if (!comptime std.os.isGetFdPathSupportedOnTarget(builtin.os)) return error.SkipZigTest; |
| 668 | test "Dir.realPath smoke test" { |
| 669 | if (native_os == .wasi) return error.SkipZigTest; |
| 657 | 670 | |
| 658 | 671 | try testWithAllSupportedPathTypes(struct { |
| 659 | 672 | fn impl(ctx: *TestContext) !void { |
| ... | ... | @@ -686,10 +699,10 @@ test "Dir.realpath smoke test" { |
| 686 | 699 | |
| 687 | 700 | // First, test non-alloc version |
| 688 | 701 | { |
| 689 | | const file_path = try ctx.dir.realpath(test_file_path, &buf); |
| 702 | const file_path = try ctx.dir.realPath(io, test_file_path, &buf); |
| 690 | 703 | try expectEqualStrings(expected_file_path, file_path); |
| 691 | 704 | |
| 692 | | const dir_path = try ctx.dir.realpath(test_dir_path, &buf); |
| 705 | const dir_path = try ctx.dir.realPath(io, test_dir_path, &buf); |
| 693 | 706 | try expectEqualStrings(expected_dir_path, dir_path); |
| 694 | 707 | } |
| 695 | 708 | |
| ... | ... | @@ -769,7 +782,7 @@ test "Dir.statFile" { |
| 769 | 782 | |
| 770 | 783 | try expectError(error.FileNotFound, ctx.dir.statFile(io, test_dir_name, .{})); |
| 771 | 784 | |
| 772 | | try ctx.dir.makeDir(io, test_dir_name); |
| 785 | try ctx.dir.makeDir(io, test_dir_name, .default_dir); |
| 773 | 786 | |
| 774 | 787 | const stat = try ctx.dir.statFile(io, test_dir_name, .{}); |
| 775 | 788 | try expectEqual(.directory, stat.kind); |
| ... | ... | @@ -1148,7 +1161,7 @@ test "openExecutable" { |
| 1148 | 1161 | |
| 1149 | 1162 | const io = testing.io; |
| 1150 | 1163 | |
| 1151 | | const self_exe_file = try std.fs.openExecutable(.{}); |
| 1164 | const self_exe_file = try std.process.openExecutable(io, .{}); |
| 1152 | 1165 | self_exe_file.close(io); |
| 1153 | 1166 | } |
| 1154 | 1167 | |
| ... | ... | @@ -1157,7 +1170,8 @@ test "executablePath" { |
| 1157 | 1170 | |
| 1158 | 1171 | const io = testing.io; |
| 1159 | 1172 | var buf: [Dir.max_path_bytes]u8 = undefined; |
| 1160 | | const buf_self_exe_path = try std.process.executablePath(io, &buf); |
| 1173 | const len = try std.process.executablePath(io, &buf); |
| 1174 | const buf_self_exe_path = buf[0..len]; |
| 1161 | 1175 | const alloc_self_exe_path = try std.process.executablePathAlloc(io, testing.allocator); |
| 1162 | 1176 | defer testing.allocator.free(alloc_self_exe_path); |
| 1163 | 1177 | try expectEqualSlices(u8, buf_self_exe_path, alloc_self_exe_path); |
| ... | ... | @@ -1246,7 +1260,7 @@ test "makePath, put some files in it, deleteTreeMinStackSize" { |
| 1246 | 1260 | .data = "blah", |
| 1247 | 1261 | }); |
| 1248 | 1262 | |
| 1249 | | try ctx.dir.deleteTreeMinStackSize(dir_path); |
| 1263 | try ctx.dir.deleteTreeMinStackSize(io, dir_path); |
| 1250 | 1264 | try expectError(error.FileNotFound, ctx.dir.openDir(io, dir_path, .{})); |
| 1251 | 1265 | } |
| 1252 | 1266 | }.impl); |
| ... | ... | @@ -1395,7 +1409,7 @@ fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !vo |
| 1395 | 1409 | defer walker.deinit(); |
| 1396 | 1410 | |
| 1397 | 1411 | var count: usize = 0; |
| 1398 | | while (try walker.next()) |entry| { |
| 1412 | while (try walker.next(io)) |entry| { |
| 1399 | 1413 | try expectEqualStrings(maxed_filename, entry.basename); |
| 1400 | 1414 | count += 1; |
| 1401 | 1415 | } |
| ... | ... | @@ -1452,7 +1466,7 @@ test "writev, readv" { |
| 1452 | 1466 | try writer.interface.flush(); |
| 1453 | 1467 | try expectEqual(@as(u64, line1.len + line2.len), try src_file.length(io)); |
| 1454 | 1468 | |
| 1455 | | var reader = writer.moveToReader(io); |
| 1469 | var reader = writer.moveToReader(); |
| 1456 | 1470 | try reader.seekTo(0); |
| 1457 | 1471 | try reader.interface.readVecAll(&read_vecs); |
| 1458 | 1472 | try expectEqualStrings(&buf1, "line2\n"); |
| ... | ... | @@ -1483,7 +1497,7 @@ test "pwritev, preadv" { |
| 1483 | 1497 | try writer.interface.flush(); |
| 1484 | 1498 | try expectEqual(@as(u64, 16 + line1.len + line2.len), try src_file.length(io)); |
| 1485 | 1499 | |
| 1486 | | var reader = writer.moveToReader(io); |
| 1500 | var reader = writer.moveToReader(); |
| 1487 | 1501 | try reader.seekTo(16); |
| 1488 | 1502 | try reader.interface.readVecAll(&read_vecs); |
| 1489 | 1503 | try expectEqualStrings(&buf1, "line2\n"); |
| ... | ... | @@ -1549,7 +1563,7 @@ test "sendfile" { |
| 1549 | 1563 | try expectEqual(10, try file_writer.interface.sendFileAll(&file_reader, .limited(10))); |
| 1550 | 1564 | try file_writer.interface.writeVecAll(&trailers); |
| 1551 | 1565 | try file_writer.interface.flush(); |
| 1552 | | var fr = file_writer.moveToReader(io); |
| 1566 | var fr = file_writer.moveToReader(); |
| 1553 | 1567 | try fr.seekTo(0); |
| 1554 | 1568 | const amt = try fr.interface.readSliceShort(&written_buf); |
| 1555 | 1569 | try expectEqualStrings("header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n", written_buf[0..amt]); |
| ... | ... | @@ -1586,7 +1600,7 @@ test "sendfile with buffered data" { |
| 1586 | 1600 | try expectEqual(4, try file_writer.interface.sendFileAll(&file_reader, .limited(4))); |
| 1587 | 1601 | |
| 1588 | 1602 | var written_buf: [8]u8 = undefined; |
| 1589 | | var fr = file_writer.moveToReader(io); |
| 1603 | var fr = file_writer.moveToReader(); |
| 1590 | 1604 | try fr.seekTo(0); |
| 1591 | 1605 | const amt = try fr.interface.readSliceShort(&written_buf); |
| 1592 | 1606 | |
| ... | ... | @@ -1609,7 +1623,7 @@ test "copyFile" { |
| 1609 | 1623 | try ctx.dir.copyFile(src_file, ctx.dir, dest_file, io, .{}); |
| 1610 | 1624 | defer ctx.dir.deleteFile(io, dest_file) catch {}; |
| 1611 | 1625 | |
| 1612 | | try ctx.dir.copyFile(src_file, ctx.dir, dest_file2, io, .{ .permissions = File.default_mode }); |
| 1626 | try ctx.dir.copyFile(src_file, ctx.dir, dest_file2, io, .{ .permissions = .default_file }); |
| 1613 | 1627 | defer ctx.dir.deleteFile(io, dest_file2) catch {}; |
| 1614 | 1628 | |
| 1615 | 1629 | try expectFileContents(io, ctx.dir, dest_file, data); |
| ... | ... | @@ -1714,12 +1728,12 @@ test "open file with exclusive lock twice, make sure second lock waits" { |
| 1714 | 1728 | errdefer file.close(io); |
| 1715 | 1729 | |
| 1716 | 1730 | const S = struct { |
| 1717 | | fn checkFn(dir: *Dir, path: []const u8, started: *std.Thread.ResetEvent, locked: *std.Thread.ResetEvent) !void { |
| 1731 | fn checkFn(inner_ctx: *TestContext, path: []const u8, started: *std.Thread.ResetEvent, locked: *std.Thread.ResetEvent) !void { |
| 1718 | 1732 | started.set(); |
| 1719 | | const file1 = try dir.createFile(io, path, .{ .lock = .exclusive }); |
| 1733 | const file1 = try inner_ctx.dir.createFile(inner_ctx.io, path, .{ .lock = .exclusive }); |
| 1720 | 1734 | |
| 1721 | 1735 | locked.set(); |
| 1722 | | file1.close(io); |
| 1736 | file1.close(inner_ctx.io); |
| 1723 | 1737 | } |
| 1724 | 1738 | }; |
| 1725 | 1739 | |
| ... | ... | @@ -1727,7 +1741,7 @@ test "open file with exclusive lock twice, make sure second lock waits" { |
| 1727 | 1741 | var locked: std.Thread.ResetEvent = .unset; |
| 1728 | 1742 | |
| 1729 | 1743 | const t = try std.Thread.spawn(.{}, S.checkFn, .{ |
| 1730 | | &ctx.dir, |
| 1744 | ctx, |
| 1731 | 1745 | filename, |
| 1732 | 1746 | &started, |
| 1733 | 1747 | &locked, |
| ... | ... | @@ -1848,7 +1862,7 @@ test "walker" { |
| 1848 | 1862 | defer walker.deinit(); |
| 1849 | 1863 | |
| 1850 | 1864 | var num_walked: usize = 0; |
| 1851 | | while (try walker.next()) |entry| { |
| 1865 | while (try walker.next(io)) |entry| { |
| 1852 | 1866 | expect(expected_basenames.has(entry.basename)) catch |err| { |
| 1853 | 1867 | std.debug.print("found unexpected basename: {f}\n", .{std.ascii.hexEscape(entry.basename, .lower)}); |
| 1854 | 1868 | return err; |
| ... | ... | @@ -1910,10 +1924,10 @@ test "selective walker, skip entries that start with ." { |
| 1910 | 1924 | defer walker.deinit(); |
| 1911 | 1925 | |
| 1912 | 1926 | var num_walked: usize = 0; |
| 1913 | | while (try walker.next()) |entry| { |
| 1927 | while (try walker.next(io)) |entry| { |
| 1914 | 1928 | if (entry.basename[0] == '.') continue; |
| 1915 | 1929 | if (entry.kind == .directory) { |
| 1916 | | try walker.enter(entry); |
| 1930 | try walker.enter(io, entry); |
| 1917 | 1931 | } |
| 1918 | 1932 | |
| 1919 | 1933 | expect(expected_basenames.has(entry.basename)) catch |err| { |
| ... | ... | @@ -1953,7 +1967,7 @@ test "walker without fully iterating" { |
| 1953 | 1967 | try tmp.dir.makePath(io, "b"); |
| 1954 | 1968 | |
| 1955 | 1969 | var num_walked: usize = 0; |
| 1956 | | while (try walker.next()) |_| { |
| 1970 | while (try walker.next(io)) |_| { |
| 1957 | 1971 | num_walked += 1; |
| 1958 | 1972 | break; |
| 1959 | 1973 | } |
| ... | ... | @@ -2093,48 +2107,42 @@ test "invalid UTF-8/WTF-8 paths" { |
| 2093 | 2107 | // This is both invalid UTF-8 and WTF-8, since \xFF is an invalid start byte |
| 2094 | 2108 | const invalid_path = try ctx.transformPath("\xFF"); |
| 2095 | 2109 | |
| 2096 | | try expectError(expected_err, ctx.dir.openFile(invalid_path, .{})); |
| 2110 | try expectError(expected_err, ctx.dir.openFile(io, invalid_path, .{})); |
| 2097 | 2111 | |
| 2098 | | try expectError(expected_err, ctx.dir.createFile(invalid_path, .{})); |
| 2112 | try expectError(expected_err, ctx.dir.createFile(io, invalid_path, .{})); |
| 2099 | 2113 | |
| 2100 | | try expectError(expected_err, ctx.dir.makeDir(invalid_path, .default_dir)); |
| 2114 | try expectError(expected_err, ctx.dir.makeDir(io, invalid_path, .default_dir)); |
| 2101 | 2115 | |
| 2102 | | try expectError(expected_err, ctx.dir.makePath(invalid_path)); |
| 2103 | | try expectError(expected_err, ctx.dir.makeOpenPath(invalid_path, .{})); |
| 2116 | try expectError(expected_err, ctx.dir.makePath(io, invalid_path)); |
| 2117 | try expectError(expected_err, ctx.dir.makeOpenPath(io, invalid_path, .{})); |
| 2104 | 2118 | |
| 2105 | | try expectError(expected_err, ctx.dir.openDir(invalid_path, .{})); |
| 2119 | try expectError(expected_err, ctx.dir.openDir(io, invalid_path, .{})); |
| 2106 | 2120 | |
| 2107 | | try expectError(expected_err, ctx.dir.deleteFile(invalid_path)); |
| 2121 | try expectError(expected_err, ctx.dir.deleteFile(io, invalid_path)); |
| 2108 | 2122 | |
| 2109 | 2123 | try expectError(expected_err, ctx.dir.deleteDir(io, invalid_path)); |
| 2110 | 2124 | |
| 2111 | 2125 | try expectError(expected_err, ctx.dir.rename(invalid_path, ctx.dir, invalid_path, io)); |
| 2112 | 2126 | |
| 2113 | 2127 | try expectError(expected_err, ctx.dir.symLink(io, invalid_path, invalid_path, .{})); |
| 2114 | | if (native_os == .wasi) { |
| 2115 | | try expectError(expected_err, ctx.dir.symLinkWasi(invalid_path, invalid_path, .{})); |
| 2116 | | } |
| 2117 | 2128 | |
| 2118 | 2129 | try expectError(expected_err, ctx.dir.readLink(io, invalid_path, &[_]u8{})); |
| 2119 | | if (native_os == .wasi) { |
| 2120 | | try expectError(expected_err, ctx.dir.readLinkWasi(invalid_path, &[_]u8{})); |
| 2121 | | } |
| 2122 | 2130 | |
| 2123 | | try expectError(expected_err, ctx.dir.readFile(invalid_path, &[_]u8{})); |
| 2124 | | try expectError(expected_err, ctx.dir.readFileAlloc(invalid_path, testing.allocator, .limited(0))); |
| 2131 | try expectError(expected_err, ctx.dir.readFile(io, invalid_path, &[_]u8{})); |
| 2132 | try expectError(expected_err, ctx.dir.readFileAlloc(io, invalid_path, testing.allocator, .limited(0))); |
| 2125 | 2133 | |
| 2126 | 2134 | try expectError(expected_err, ctx.dir.deleteTree(io, invalid_path)); |
| 2127 | | try expectError(expected_err, ctx.dir.deleteTreeMinStackSize(invalid_path)); |
| 2135 | try expectError(expected_err, ctx.dir.deleteTreeMinStackSize(io, invalid_path)); |
| 2128 | 2136 | |
| 2129 | 2137 | try expectError(expected_err, ctx.dir.writeFile(io, .{ .sub_path = invalid_path, .data = "" })); |
| 2130 | 2138 | |
| 2131 | | try expectError(expected_err, ctx.dir.access(invalid_path, .{})); |
| 2139 | try expectError(expected_err, ctx.dir.access(io, invalid_path, .{})); |
| 2132 | 2140 | |
| 2133 | 2141 | var dir = ctx.dir; |
| 2134 | 2142 | try expectError(expected_err, dir.updateFile(io, invalid_path, dir, invalid_path, .{})); |
| 2135 | 2143 | try expectError(expected_err, ctx.dir.copyFile(invalid_path, ctx.dir, invalid_path, io, .{})); |
| 2136 | 2144 | |
| 2137 | | try expectError(expected_err, ctx.dir.statFile(invalid_path)); |
| 2145 | try expectError(expected_err, ctx.dir.statFile(io, invalid_path, .{})); |
| 2138 | 2146 | |
| 2139 | 2147 | if (native_os != .wasi) { |
| 2140 | 2148 | try expectError(expected_err, ctx.dir.realPath(io, invalid_path, &[_]u8{})); |
| ... | ... | @@ -2146,17 +2154,17 @@ test "invalid UTF-8/WTF-8 paths" { |
| 2146 | 2154 | if (native_os != .wasi and ctx.path_type != .relative) { |
| 2147 | 2155 | try expectError(expected_err, Dir.copyFileAbsolute(invalid_path, invalid_path, io, .{})); |
| 2148 | 2156 | try expectError(expected_err, Dir.makeDirAbsolute(io, invalid_path, .default_dir)); |
| 2149 | | try expectError(expected_err, Dir.deleteDirAbsolute(invalid_path)); |
| 2157 | try expectError(expected_err, Dir.deleteDirAbsolute(io, invalid_path)); |
| 2150 | 2158 | try expectError(expected_err, Dir.renameAbsolute(invalid_path, invalid_path, io)); |
| 2151 | 2159 | try expectError(expected_err, Dir.openDirAbsolute(io, invalid_path, .{})); |
| 2152 | 2160 | try expectError(expected_err, Dir.openFileAbsolute(io, invalid_path, .{})); |
| 2153 | | try expectError(expected_err, Dir.accessAbsolute(invalid_path, .{})); |
| 2154 | | try expectError(expected_err, Dir.createFileAbsolute(invalid_path, .{})); |
| 2155 | | try expectError(expected_err, Dir.deleteFileAbsolute(invalid_path)); |
| 2161 | try expectError(expected_err, Dir.accessAbsolute(io, invalid_path, .{})); |
| 2162 | try expectError(expected_err, Dir.createFileAbsolute(io, invalid_path, .{})); |
| 2163 | try expectError(expected_err, Dir.deleteFileAbsolute(io, invalid_path)); |
| 2156 | 2164 | var readlink_buf: [Dir.max_path_bytes]u8 = undefined; |
| 2157 | | try expectError(expected_err, Dir.readLinkAbsolute(invalid_path, &readlink_buf)); |
| 2158 | | try expectError(expected_err, Dir.symLinkAbsolute(invalid_path, invalid_path, .{})); |
| 2159 | | try expectError(expected_err, Dir.realPathAlloc(io, invalid_path, testing.allocator)); |
| 2165 | try expectError(expected_err, Dir.readLinkAbsolute(io, invalid_path, &readlink_buf)); |
| 2166 | try expectError(expected_err, Dir.symLinkAbsolute(io, invalid_path, invalid_path, .{})); |
| 2167 | try expectError(expected_err, Dir.realPathAbsoluteAlloc(io, invalid_path, testing.allocator)); |
| 2160 | 2168 | } |
| 2161 | 2169 | } |
| 2162 | 2170 | }.impl); |
| ... | ... | @@ -2327,7 +2335,8 @@ test "readlink on Windows" { |
| 2327 | 2335 | |
| 2328 | 2336 | fn testReadLinkWindows(io: Io, target_path: []const u8, symlink_path: []const u8) !void { |
| 2329 | 2337 | var buffer: [Dir.max_path_bytes]u8 = undefined; |
| 2330 | | const given = try Dir.readLinkAbsolute(io, symlink_path, &buffer); |
| 2338 | const len = try Dir.readLinkAbsolute(io, symlink_path, &buffer); |
| 2339 | const given = buffer[0..len]; |
| 2331 | 2340 | try expect(mem.eql(u8, target_path, given)); |
| 2332 | 2341 | } |
| 2333 | 2342 | |
| ... | ... | @@ -2495,7 +2504,7 @@ test "access smoke test" { |
| 2495 | 2504 | |
| 2496 | 2505 | { |
| 2497 | 2506 | // Create some directory |
| 2498 | | try tmp.dir.makeDir(io, "some_dir", .default_file); |
| 2507 | try tmp.dir.makeDir(io, "some_dir", .default_dir); |
| 2499 | 2508 | } |
| 2500 | 2509 | |
| 2501 | 2510 | { |
| ... | ... | @@ -2563,6 +2572,8 @@ test "open smoke test" { |
| 2563 | 2572 | } |
| 2564 | 2573 | |
| 2565 | 2574 | test "hard link with different directories" { |
| 2575 | if (native_os == .wasi or native_os == .windows) return error.SkipZigTest; |
| 2576 | |
| 2566 | 2577 | const io = testing.io; |
| 2567 | 2578 | |
| 2568 | 2579 | var tmp = tmpDir(.{}); |