| ... | @@ -1843,6 +1843,33 @@ test "read from locked file" { | ... | @@ -1843,6 +1843,33 @@ test "read from locked file" { |
| 1843 | }.impl); | 1843 | }.impl); |
| 1844 | } | 1844 | } |
| 1845 | | 1845 | |
| | 1846 | test "use Lock.none to unlock files" { |
| | 1847 | if (native_os == .wasi) return error.SkipZigTest; |
| | 1848 | |
| | 1849 | const io = testing.io; |
| | 1850 | |
| | 1851 | var tmp = tmpDir(.{}); |
| | 1852 | defer tmp.cleanup(); |
| | 1853 | |
| | 1854 | // Create a locked file. |
| | 1855 | const test_file = try tmp.dir.createFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); |
| | 1856 | defer test_file.close(io); |
| | 1857 | |
| | 1858 | // Attempt to unlock the file via fs.lock with Lock.none. |
| | 1859 | try test_file.lock(io, .none); |
| | 1860 | |
| | 1861 | // Attempt to open the file now that it should be unlocked. |
| | 1862 | const test_file2 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); |
| | 1863 | defer test_file2.close(io); |
| | 1864 | |
| | 1865 | // Make sure Lock.none works with tryLock as well. |
| | 1866 | try testing.expect(try test_file2.tryLock(io, .none)); |
| | 1867 | |
| | 1868 | // Attempt to open the file since it should be unlocked again. |
| | 1869 | const test_file3 = try tmp.dir.openFile(io, "test_file", .{ .lock = .exclusive, .lock_nonblocking = true }); |
| | 1870 | test_file3.close(io); |
| | 1871 | } |
| | 1872 | |
| 1846 | test "walker" { | 1873 | test "walker" { |
| 1847 | const io = testing.io; | 1874 | const io = testing.io; |
| 1848 | | 1875 | |