authorgravatar for nycex@cccp.orgnycex <nycex@cccp.org> 2020-05-02 10:19:07+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-05-02 04:19:07-04:00
log77376a54bf4a379135261f40f7f4025a79314897
treebc00d70937962d66bd5e423066b45cdd2bb269dd
parent428065da30cd957cadd9d1f2428933bab9d17637
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

correct usages of std.fs.dir.DeleteFileError (#5058)

* correct usages of std.fs.dir.DeleteFileError * test std.fs.createFileAbsolute() and std.fs.deleteFileAbsolute()

2 files changed, 19 insertions(+), 3 deletions(-)

lib/std/fs.zig+3-3
......@@ -1442,7 +1442,7 @@ pub fn createFileAbsoluteW(absolute_path_w: [*:0]const u16, flags: File.CreateFl
14421442/// Asserts that the path is absolute. See `Dir.deleteFile` for a function that
14431443/// operates on both absolute and relative paths.
14441444/// Asserts that the path parameter has no null bytes.
1445pub fn deleteFileAbsolute(absolute_path: []const u8) DeleteFileError!void {
1445pub fn deleteFileAbsolute(absolute_path: []const u8) Dir.DeleteFileError!void {
14461446 assert(path.isAbsolute(absolute_path));
14471447 return cwd().deleteFile(absolute_path);
14481448}
......@@ -1450,13 +1450,13 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) DeleteFileError!void {
14501450pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ");
14511451
14521452/// Same as `deleteFileAbsolute` except the parameter is null-terminated.
1453pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) DeleteFileError!void {
1453pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) Dir.DeleteFileError!void {
14541454 assert(path.isAbsoluteZ(absolute_path_c));
14551455 return cwd().deleteFileZ(absolute_path_c);
14561456}
14571457
14581458/// Same as `deleteFileAbsolute` except the parameter is WTF-16 encoded.
1459pub fn deleteFileAbsoluteW(absolute_path_w: [*:0]const u16) DeleteFileError!void {
1459pub fn deleteFileAbsoluteW(absolute_path_w: [*:0]const u16) Dir.DeleteFileError!void {
14601460 assert(path.isAbsoluteWindowsW(absolute_path_w));
14611461 return cwd().deleteFileW(absolute_path_w);
14621462}
lib/std/fs/test.zig+16
......@@ -100,6 +100,22 @@ test "create file, lock and read from multiple process at once" {
100100 };
101101}
102102
103test "open file with exclusive nonblocking lock twice (absolute paths)" {
104 const allocator = std.testing.allocator;
105
106 const file_paths: [1][]const u8 = .{"zig-test-absolute-paths.txt"};
107 const filename = try fs.path.resolve(allocator, &file_paths);
108 defer allocator.free(filename);
109
110 const file1 = try fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
111
112 const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
113 file1.close();
114 std.testing.expectError(error.WouldBlock, file2);
115
116 try fs.deleteFileAbsolute(filename);
117}
118
103119const FileLockTestContext = struct {
104120 filename: []const u8,
105121 pid: if (builtin.os.tag == .windows) ?void else ?std.os.pid_t = null,