diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 3da3d1d9d7..df8bfe97d7 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -1442,7 +1442,7 @@ pub fn createFileAbsoluteW(absolute_path_w: [*:0]const u16, flags: File.CreateFl /// Asserts that the path is absolute. See `Dir.deleteFile` for a function that /// operates on both absolute and relative paths. /// Asserts that the path parameter has no null bytes. -pub fn deleteFileAbsolute(absolute_path: []const u8) DeleteFileError!void { +pub fn deleteFileAbsolute(absolute_path: []const u8) Dir.DeleteFileError!void { assert(path.isAbsolute(absolute_path)); return cwd().deleteFile(absolute_path); } @@ -1450,13 +1450,13 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) DeleteFileError!void { pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ"); /// Same as `deleteFileAbsolute` except the parameter is null-terminated. -pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) DeleteFileError!void { +pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) Dir.DeleteFileError!void { assert(path.isAbsoluteZ(absolute_path_c)); return cwd().deleteFileZ(absolute_path_c); } /// Same as `deleteFileAbsolute` except the parameter is WTF-16 encoded. -pub fn deleteFileAbsoluteW(absolute_path_w: [*:0]const u16) DeleteFileError!void { +pub fn deleteFileAbsoluteW(absolute_path_w: [*:0]const u16) Dir.DeleteFileError!void { assert(path.isAbsoluteWindowsW(absolute_path_w)); return cwd().deleteFileW(absolute_path_w); } diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index da2d2c0d0c..2d0141a5d9 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -100,6 +100,22 @@ test "create file, lock and read from multiple process at once" { }; } +test "open file with exclusive nonblocking lock twice (absolute paths)" { + const allocator = std.testing.allocator; + + const file_paths: [1][]const u8 = .{"zig-test-absolute-paths.txt"}; + const filename = try fs.path.resolve(allocator, &file_paths); + defer allocator.free(filename); + + const file1 = try fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true }); + + const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true }); + file1.close(); + std.testing.expectError(error.WouldBlock, file2); + + try fs.deleteFileAbsolute(filename); +} + const FileLockTestContext = struct { filename: []const u8, pid: if (builtin.os.tag == .windows) ?void else ?std.os.pid_t = null,