| ... | ... | @@ -298,6 +298,28 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" { |
| 298 | 298 | }.impl); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | test "Dir.statFile on a symlink" { |
| 302 | const io = testing.io; |
| 303 | |
| 304 | try testWithAllSupportedPathTypes(struct { |
| 305 | fn impl(ctx: *TestContext) !void { |
| 306 | const dir_target_path = try ctx.transformPath("test_file"); |
| 307 | try ctx.dir.writeFile(io, .{ |
| 308 | .sub_path = dir_target_path, |
| 309 | .data = "Some test content", |
| 310 | }); |
| 311 | |
| 312 | try setupSymlink(io, ctx.dir, dir_target_path, "symlink", .{}); |
| 313 | |
| 314 | const file_stat = try ctx.dir.statFile(io, "test_file", .{ .follow_symlinks = false }); |
| 315 | try testing.expectEqual(File.Kind.file, file_stat.kind); |
| 316 | |
| 317 | const link_stat = try ctx.dir.statFile(io, "symlink", .{ .follow_symlinks = false }); |
| 318 | try testing.expectEqual(File.Kind.sym_link, link_stat.kind); |
| 319 | } |
| 320 | }.impl); |
| 321 | } |
| 322 | |
| 301 | 323 | test "openDir" { |
| 302 | 324 | const io = testing.io; |
| 303 | 325 | |
| ... | ... | @@ -1843,6 +1865,33 @@ test "read from locked file" { |
| 1843 | 1865 | }.impl); |
| 1844 | 1866 | } |
| 1845 | 1867 | |
| 1868 | test "use Lock.none to unlock files" { |
| 1869 | if (native_os == .wasi) return error.SkipZigTest; |
| 1870 | |
| 1871 | const io = testing.io; |
| 1872 | |
| 1873 | var tmp = tmpDir(.{}); |
| 1874 | defer tmp.cleanup(); |
| 1875 | |
| 1876 | // Create a locked file. |
| 1877 | const test_file = try tmp.dir.createFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); |
| 1878 | defer test_file.close(io); |
| 1879 | |
| 1880 | // Attempt to unlock the file via fs.lock with Lock.none. |
| 1881 | try test_file.lock(io, .none); |
| 1882 | |
| 1883 | // Attempt to open the file now that it should be unlocked. |
| 1884 | const test_file2 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); |
| 1885 | defer test_file2.close(io); |
| 1886 | |
| 1887 | // Make sure Lock.none works with tryLock as well. |
| 1888 | try testing.expect(try test_file2.tryLock(io, .none)); |
| 1889 | |
| 1890 | // Attempt to open the file since it should be unlocked again. |
| 1891 | const test_file3 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); |
| 1892 | test_file3.close(io); |
| 1893 | } |
| 1894 | |
| 1846 | 1895 | test "walker" { |
| 1847 | 1896 | const io = testing.io; |
| 1848 | 1897 | |