aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fs
diff options
context:
space:
mode:
authorLoris Cro <kappaloris@gmail.com>2023-06-18 09:06:40 +0200
committerGitHub <noreply@github.com>2023-06-18 09:06:40 +0200
commit216ef10dc471e4db60a30208be178d6c59efeaaf (patch)
tree8c239dab283ae9cb3b7fe099bae240bcc53f894e /lib/std/fs
parent0fc1d396495c1ab482197021dedac8bea3f9401c (diff)
parent729a051e9e38674233190aea23c0ac8c134f2d67 (diff)
downloadzig-216ef10dc471e4db60a30208be178d6c59efeaaf.tar.gz
zig-216ef10dc471e4db60a30208be178d6c59efeaaf.zip
Merge branch 'master' into autodoc-searchkey
Diffstat (limited to 'lib/std/fs')
-rw-r--r--lib/std/fs/file.zig158
-rw-r--r--lib/std/fs/path.zig30
-rw-r--r--lib/std/fs/test.zig77
3 files changed, 144 insertions, 121 deletions
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig
index 3f8e7185d0..3ed4b07a3d 100644
--- a/lib/std/fs/file.zig
+++ b/lib/std/fs/file.zig
@@ -35,17 +35,17 @@ pub const File = struct {
pub const Gid = os.gid_t;
pub const Kind = enum {
- BlockDevice,
- CharacterDevice,
- Directory,
- NamedPipe,
- SymLink,
- File,
- UnixDomainSocket,
- Whiteout,
- Door,
- EventPort,
- Unknown,
+ block_device,
+ character_device,
+ directory,
+ named_pipe,
+ sym_link,
+ file,
+ unix_domain_socket,
+ whiteout,
+ door,
+ event_port,
+ unknown,
};
/// This is the default mode given to POSIX operating systems for creating
@@ -81,7 +81,11 @@ pub const File = struct {
read_write,
};
- pub const Lock = enum { None, Shared, Exclusive };
+ pub const Lock = enum {
+ none,
+ shared,
+ exclusive,
+ };
pub const OpenFlags = struct {
mode: OpenMode = .read_only,
@@ -92,7 +96,7 @@ pub const File = struct {
/// processes from acquiring a exclusive lock, but does not prevent
/// other process from getting their own shared locks.
///
- /// The lock is advisory, except on Linux in very specific cirsumstances[1].
+ /// The lock is advisory, except on Linux in very specific circumstances[1].
/// This means that a process that does not respect the locking API can still get access
/// to the file, despite the lock.
///
@@ -110,7 +114,7 @@ pub const File = struct {
/// * Windows
///
/// [1]: https://www.kernel.org/doc/Documentation/filesystems/mandatory-locking.txt
- lock: Lock = .None,
+ lock: Lock = .none,
/// Sets whether or not to wait until the file is locked to return. If set to true,
/// `error.WouldBlock` will be returned. Otherwise, the file will wait until the file
@@ -156,7 +160,7 @@ pub const File = struct {
/// processes from acquiring a exclusive lock, but does not prevent
/// other process from getting their own shared locks.
///
- /// The lock is advisory, except on Linux in very specific cirsumstances[1].
+ /// The lock is advisory, except on Linux in very specific circumstances[1].
/// This means that a process that does not respect the locking API can still get access
/// to the file, despite the lock.
///
@@ -174,7 +178,7 @@ pub const File = struct {
/// * Windows
///
/// [1]: https://www.kernel.org/doc/Documentation/filesystems/mandatory-locking.txt
- lock: Lock = .None,
+ lock: Lock = .none,
/// Sets whether or not to wait until the file is locked to return. If set to true,
/// `error.WouldBlock` will be returned. Otherwise, the file will wait until the file
@@ -329,32 +333,32 @@ pub const File = struct {
const mtime = st.mtime();
const ctime = st.ctime();
const kind: Kind = if (builtin.os.tag == .wasi and !builtin.link_libc) switch (st.filetype) {
- .BLOCK_DEVICE => Kind.BlockDevice,
- .CHARACTER_DEVICE => Kind.CharacterDevice,
- .DIRECTORY => Kind.Directory,
- .SYMBOLIC_LINK => Kind.SymLink,
- .REGULAR_FILE => Kind.File,
- .SOCKET_STREAM, .SOCKET_DGRAM => Kind.UnixDomainSocket,
- else => Kind.Unknown,
+ .BLOCK_DEVICE => .block_device,
+ .CHARACTER_DEVICE => .character_device,
+ .DIRECTORY => .directory,
+ .SYMBOLIC_LINK => .sym_link,
+ .REGULAR_FILE => .file,
+ .SOCKET_STREAM, .SOCKET_DGRAM => .unix_domain_socket,
+ else => .unknown,
} else blk: {
const m = st.mode & os.S.IFMT;
switch (m) {
- os.S.IFBLK => break :blk Kind.BlockDevice,
- os.S.IFCHR => break :blk Kind.CharacterDevice,
- os.S.IFDIR => break :blk Kind.Directory,
- os.S.IFIFO => break :blk Kind.NamedPipe,
- os.S.IFLNK => break :blk Kind.SymLink,
- os.S.IFREG => break :blk Kind.File,
- os.S.IFSOCK => break :blk Kind.UnixDomainSocket,
+ os.S.IFBLK => break :blk .block_device,
+ os.S.IFCHR => break :blk .character_device,
+ os.S.IFDIR => break :blk .directory,
+ os.S.IFIFO => break :blk .named_pipe,
+ os.S.IFLNK => break :blk .sym_link,
+ os.S.IFREG => break :blk .file,
+ os.S.IFSOCK => break :blk .unix_domain_socket,
else => {},
}
if (builtin.os.tag == .solaris) switch (m) {
- os.S.IFDOOR => break :blk Kind.Door,
- os.S.IFPORT => break :blk Kind.EventPort,
+ os.S.IFDOOR => break :blk .door,
+ os.S.IFPORT => break :blk .event_port,
else => {},
};
- break :blk .Unknown;
+ break :blk .unknown;
};
return Stat{
@@ -391,7 +395,7 @@ pub const File = struct {
.inode = info.InternalInformation.IndexNumber,
.size = @bitCast(u64, info.StandardInformation.EndOfFile),
.mode = 0,
- .kind = if (info.StandardInformation.Directory == 0) .File else .Directory,
+ .kind = if (info.StandardInformation.Directory == 0) .file else .directory,
.atime = windows.fromSysTime(info.BasicInformation.LastAccessTime),
.mtime = windows.fromSysTime(info.BasicInformation.LastWriteTime),
.ctime = windows.fromSysTime(info.BasicInformation.CreationTime),
@@ -609,7 +613,7 @@ pub const File = struct {
}
/// Returns the `Kind` of file.
- /// On Windows, can only return: `.File`, `.Directory`, `.SymLink` or `.Unknown`
+ /// On Windows, can only return: `.file`, `.directory`, `.sym_link` or `.unknown`
pub fn kind(self: Self) Kind {
return self.inner.kind();
}
@@ -652,35 +656,35 @@ pub const File = struct {
/// Returns the `Kind` of the file
pub fn kind(self: Self) Kind {
if (builtin.os.tag == .wasi and !builtin.link_libc) return switch (self.stat.filetype) {
- .BLOCK_DEVICE => Kind.BlockDevice,
- .CHARACTER_DEVICE => Kind.CharacterDevice,
- .DIRECTORY => Kind.Directory,
- .SYMBOLIC_LINK => Kind.SymLink,
- .REGULAR_FILE => Kind.File,
- .SOCKET_STREAM, .SOCKET_DGRAM => Kind.UnixDomainSocket,
- else => Kind.Unknown,
+ .BLOCK_DEVICE => .block_device,
+ .CHARACTER_DEVICE => .character_device,
+ .DIRECTORY => .directory,
+ .SYMBOLIC_LINK => .sym_link,
+ .REGULAR_FILE => .file,
+ .SOCKET_STREAM, .SOCKET_DGRAM => .unix_domain_socket,
+ else => .unknown,
};
const m = self.stat.mode & os.S.IFMT;
switch (m) {
- os.S.IFBLK => return Kind.BlockDevice,
- os.S.IFCHR => return Kind.CharacterDevice,
- os.S.IFDIR => return Kind.Directory,
- os.S.IFIFO => return Kind.NamedPipe,
- os.S.IFLNK => return Kind.SymLink,
- os.S.IFREG => return Kind.File,
- os.S.IFSOCK => return Kind.UnixDomainSocket,
+ os.S.IFBLK => return .block_device,
+ os.S.IFCHR => return .character_device,
+ os.S.IFDIR => return .directory,
+ os.S.IFIFO => return .named_pipe,
+ os.S.IFLNK => return .sym_link,
+ os.S.IFREG => return .file,
+ os.S.IFSOCK => return .unix_domain_socket,
else => {},
}
if (builtin.os.tag == .solaris) switch (m) {
- os.S.IFDOOR => return Kind.Door,
- os.S.IFPORT => return Kind.EventPort,
+ os.S.IFDOOR => return .door,
+ os.S.IFPORT => return .event_port,
else => {},
};
- return .Unknown;
+ return .unknown;
}
/// Returns the last time the file was accessed in nanoseconds since UTC 1970-01-01
@@ -738,17 +742,17 @@ pub const File = struct {
const m = self.statx.mode & os.S.IFMT;
switch (m) {
- os.S.IFBLK => return Kind.BlockDevice,
- os.S.IFCHR => return Kind.CharacterDevice,
- os.S.IFDIR => return Kind.Directory,
- os.S.IFIFO => return Kind.NamedPipe,
- os.S.IFLNK => return Kind.SymLink,
- os.S.IFREG => return Kind.File,
- os.S.IFSOCK => return Kind.UnixDomainSocket,
+ os.S.IFBLK => return .block_device,
+ os.S.IFCHR => return .character_device,
+ os.S.IFDIR => return .directory,
+ os.S.IFIFO => return .named_pipe,
+ os.S.IFLNK => return .sym_link,
+ os.S.IFREG => return .file,
+ os.S.IFSOCK => return .unix_domain_socket,
else => {},
}
- return .Unknown;
+ return .unknown;
}
/// Returns the last time the file was accessed in nanoseconds since UTC 1970-01-01
@@ -790,18 +794,18 @@ pub const File = struct {
}
/// Returns the `Kind` of the file.
- /// Can only return: `.File`, `.Directory`, `.SymLink` or `.Unknown`
+ /// Can only return: `.file`, `.directory`, `.sym_link` or `.unknown`
pub fn kind(self: Self) Kind {
if (self.attributes & windows.FILE_ATTRIBUTE_REPARSE_POINT != 0) {
if (self.reparse_tag & 0x20000000 != 0) {
- return .SymLink;
+ return .sym_link;
}
} else if (self.attributes & windows.FILE_ATTRIBUTE_DIRECTORY != 0) {
- return .Directory;
+ return .directory;
} else {
- return .File;
+ return .file;
}
- return .Unknown;
+ return .unknown;
}
/// Returns the last time the file was accessed in nanoseconds since UTC 1970-01-01
@@ -1465,9 +1469,9 @@ pub const File = struct {
if (is_windows) {
var io_status_block: windows.IO_STATUS_BLOCK = undefined;
const exclusive = switch (l) {
- .None => return,
- .Shared => false,
- .Exclusive => true,
+ .none => return,
+ .shared => false,
+ .exclusive => true,
};
return windows.LockFile(
file.handle,
@@ -1486,9 +1490,9 @@ pub const File = struct {
};
} else {
return os.flock(file.handle, switch (l) {
- .None => os.LOCK.UN,
- .Shared => os.LOCK.SH,
- .Exclusive => os.LOCK.EX,
+ .none => os.LOCK.UN,
+ .shared => os.LOCK.SH,
+ .exclusive => os.LOCK.EX,
}) catch |err| switch (err) {
error.WouldBlock => unreachable, // non-blocking=false
else => |e| return e,
@@ -1532,9 +1536,9 @@ pub const File = struct {
if (is_windows) {
var io_status_block: windows.IO_STATUS_BLOCK = undefined;
const exclusive = switch (l) {
- .None => return,
- .Shared => false,
- .Exclusive => true,
+ .none => return,
+ .shared => false,
+ .exclusive => true,
};
windows.LockFile(
file.handle,
@@ -1553,9 +1557,9 @@ pub const File = struct {
};
} else {
os.flock(file.handle, switch (l) {
- .None => os.LOCK.UN,
- .Shared => os.LOCK.SH | os.LOCK.NB,
- .Exclusive => os.LOCK.EX | os.LOCK.NB,
+ .none => os.LOCK.UN,
+ .shared => os.LOCK.SH | os.LOCK.NB,
+ .exclusive => os.LOCK.EX | os.LOCK.NB,
}) catch |err| switch (err) {
error.WouldBlock => return false,
else => |e| return e,
diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig
index 4f3e05cd59..e7a28a7615 100644
--- a/lib/std/fs/path.zig
+++ b/lib/std/fs/path.zig
@@ -105,13 +105,13 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
return buf;
}
-/// Naively combines a series of paths with the native path seperator.
+/// Naively combines a series of paths with the native path separator.
/// Allocates memory for the result, which must be freed by the caller.
pub fn join(allocator: Allocator, paths: []const []const u8) ![]u8 {
return joinSepMaybeZ(allocator, sep, isSep, paths, false);
}
-/// Naively combines a series of paths with the native path seperator and null terminator.
+/// Naively combines a series of paths with the native path separator and null terminator.
/// Allocates memory for the result, which must be freed by the caller.
pub fn joinZ(allocator: Allocator, paths: []const []const u8) ![:0]u8 {
const out = try joinSepMaybeZ(allocator, sep, isSep, paths, true);
@@ -358,7 +358,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
return relative_path;
}
- var it = mem.tokenize(u8, path, &[_]u8{this_sep});
+ var it = mem.tokenizeScalar(u8, path, this_sep);
_ = (it.next() orelse return relative_path);
_ = (it.next() orelse return relative_path);
return WindowsPath{
@@ -420,8 +420,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
const sep1 = ns1[0];
const sep2 = ns2[0];
- var it1 = mem.tokenize(u8, ns1, &[_]u8{sep1});
- var it2 = mem.tokenize(u8, ns2, &[_]u8{sep2});
+ var it1 = mem.tokenizeScalar(u8, ns1, sep1);
+ var it2 = mem.tokenizeScalar(u8, ns2, sep2);
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
return ascii.eqlIgnoreCase(it1.next().?, it2.next().?);
@@ -441,8 +441,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
const sep1 = p1[0];
const sep2 = p2[0];
- var it1 = mem.tokenize(u8, p1, &[_]u8{sep1});
- var it2 = mem.tokenize(u8, p2, &[_]u8{sep2});
+ var it1 = mem.tokenizeScalar(u8, p1, sep1);
+ var it2 = mem.tokenizeScalar(u8, p2, sep2);
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
return ascii.eqlIgnoreCase(it1.next().?, it2.next().?) and ascii.eqlIgnoreCase(it1.next().?, it2.next().?);
@@ -535,7 +535,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
break :l disk_designator.len;
},
.NetworkShare => {
- var it = mem.tokenize(u8, paths[first_index], "/\\");
+ var it = mem.tokenizeAny(u8, paths[first_index], "/\\");
const server_name = it.next().?;
const other_name = it.next().?;
@@ -570,7 +570,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
if (!correct_disk_designator) {
continue;
}
- var it = mem.tokenize(u8, p[parsed.disk_designator.len..], "/\\");
+ var it = mem.tokenizeAny(u8, p[parsed.disk_designator.len..], "/\\");
while (it.next()) |component| {
if (mem.eql(u8, component, ".")) {
continue;
@@ -657,7 +657,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
negative_count = 0;
result.clearRetainingCapacity();
}
- var it = mem.tokenize(u8, p, "/");
+ var it = mem.tokenizeScalar(u8, p, '/');
while (it.next()) |component| {
if (mem.eql(u8, component, ".")) {
continue;
@@ -1078,8 +1078,8 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
return resolved_to;
}
- var from_it = mem.tokenize(u8, resolved_from, "/\\");
- var to_it = mem.tokenize(u8, resolved_to, "/\\");
+ var from_it = mem.tokenizeAny(u8, resolved_from, "/\\");
+ var to_it = mem.tokenizeAny(u8, resolved_to, "/\\");
while (true) {
const from_component = from_it.next() orelse return allocator.dupe(u8, to_it.rest());
const to_rest = to_it.rest();
@@ -1102,7 +1102,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
result_index += 3;
}
- var rest_it = mem.tokenize(u8, to_rest, "/\\");
+ var rest_it = mem.tokenizeAny(u8, to_rest, "/\\");
while (rest_it.next()) |to_component| {
result[result_index] = '\\';
result_index += 1;
@@ -1124,8 +1124,8 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
const resolved_to = try resolvePosix(allocator, &[_][]const u8{ cwd, to });
defer allocator.free(resolved_to);
- var from_it = mem.tokenize(u8, resolved_from, "/");
- var to_it = mem.tokenize(u8, resolved_to, "/");
+ var from_it = mem.tokenizeScalar(u8, resolved_from, '/');
+ var to_it = mem.tokenizeScalar(u8, resolved_to, '/');
while (true) {
const from_component = from_it.next() orelse return allocator.dupe(u8, to_it.rest());
const to_rest = to_it.rest();
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig
index 15c8307f58..4c51e512b6 100644
--- a/lib/std/fs/test.zig
+++ b/lib/std/fs/test.zig
@@ -179,8 +179,8 @@ test "Dir.Iterator" {
}
try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
- try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .File }));
- try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .Directory }));
+ try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));
+ try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));
}
test "Dir.Iterator many entries" {
@@ -214,7 +214,7 @@ test "Dir.Iterator many entries" {
i = 0;
while (i < num) : (i += 1) {
const name = try std.fmt.bufPrint(&buf, "{}", .{i});
- try testing.expect(contains(&entries, .{ .name = name, .kind = .File }));
+ try testing.expect(contains(&entries, .{ .name = name, .kind = .file }));
}
}
@@ -246,8 +246,8 @@ test "Dir.Iterator twice" {
}
try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
- try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .File }));
- try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .Directory }));
+ try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));
+ try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));
}
}
@@ -280,8 +280,8 @@ test "Dir.Iterator reset" {
}
try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
- try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .File }));
- try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .Directory }));
+ try testing.expect(contains(&entries, .{ .name = "some_file", .kind = .file }));
+ try testing.expect(contains(&entries, .{ .name = "some_dir", .kind = .directory }));
iter.reset();
}
@@ -336,7 +336,7 @@ test "Dir.realpath smoke test" {
var tmp_dir = tmpDir(.{});
defer tmp_dir.cleanup();
- var file = try tmp_dir.dir.createFile("test_file", .{ .lock = File.Lock.Shared });
+ var file = try tmp_dir.dir.createFile("test_file", .{ .lock = .shared });
// We need to close the file immediately as otherwise on Windows we'll end up
// with a sharing violation.
file.close();
@@ -428,7 +428,7 @@ test "directory operations on files" {
// ensure the file still exists and is a file as a sanity check
file = try tmp_dir.dir.openFile(test_file_name, .{});
const stat = try file.stat();
- try testing.expect(stat.kind == .File);
+ try testing.expect(stat.kind == .file);
file.close();
}
@@ -664,7 +664,7 @@ test "renameAbsolute" {
try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
const stat = try file.stat();
- try testing.expect(stat.kind == .File);
+ try testing.expect(stat.kind == .file);
file.close();
// Renaming directories
@@ -1035,10 +1035,10 @@ test "open file with exclusive nonblocking lock twice" {
var tmp = tmpDir(.{});
defer tmp.cleanup();
- const file1 = try tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
+ const file1 = try tmp.dir.createFile(filename, .{ .lock = .exclusive, .lock_nonblocking = true });
defer file1.close();
- const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
+ const file2 = tmp.dir.createFile(filename, .{ .lock = .exclusive, .lock_nonblocking = true });
try testing.expectError(error.WouldBlock, file2);
}
@@ -1050,10 +1050,10 @@ test "open file with shared and exclusive nonblocking lock" {
var tmp = tmpDir(.{});
defer tmp.cleanup();
- const file1 = try tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });
+ const file1 = try tmp.dir.createFile(filename, .{ .lock = .shared, .lock_nonblocking = true });
defer file1.close();
- const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
+ const file2 = tmp.dir.createFile(filename, .{ .lock = .exclusive, .lock_nonblocking = true });
try testing.expectError(error.WouldBlock, file2);
}
@@ -1065,10 +1065,10 @@ test "open file with exclusive and shared nonblocking lock" {
var tmp = tmpDir(.{});
defer tmp.cleanup();
- const file1 = try tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
+ const file1 = try tmp.dir.createFile(filename, .{ .lock = .exclusive, .lock_nonblocking = true });
defer file1.close();
- const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });
+ const file2 = tmp.dir.createFile(filename, .{ .lock = .shared, .lock_nonblocking = true });
try testing.expectError(error.WouldBlock, file2);
}
@@ -1085,13 +1085,13 @@ test "open file with exclusive lock twice, make sure second lock waits" {
var tmp = tmpDir(.{});
defer tmp.cleanup();
- const file = try tmp.dir.createFile(filename, .{ .lock = .Exclusive });
+ const file = try tmp.dir.createFile(filename, .{ .lock = .exclusive });
errdefer file.close();
const S = struct {
fn checkFn(dir: *fs.Dir, started: *std.Thread.ResetEvent, locked: *std.Thread.ResetEvent) !void {
started.set();
- const file1 = try dir.createFile(filename, .{ .lock = .Exclusive });
+ const file1 = try dir.createFile(filename, .{ .lock = .exclusive });
locked.set();
file1.close();
@@ -1138,12 +1138,12 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
defer gpa.free(filename);
const file1 = try fs.createFileAbsolute(filename, .{
- .lock = .Exclusive,
+ .lock = .exclusive,
.lock_nonblocking = true,
});
const file2 = fs.createFileAbsolute(filename, .{
- .lock = .Exclusive,
+ .lock = .exclusive,
.lock_nonblocking = true,
});
file1.close();
@@ -1348,7 +1348,7 @@ test "File.Metadata" {
defer file.close();
const metadata = try file.metadata();
- try testing.expect(metadata.kind() == .File);
+ try testing.expect(metadata.kind() == .file);
try testing.expect(metadata.size() == 0);
_ = metadata.accessed();
_ = metadata.modified();
@@ -1416,23 +1416,42 @@ test "File.PermissionsUnix" {
try testing.expect(!permissions_unix.unixHas(.other, .execute));
}
-test "delete a read-only file on windows" {
- if (builtin.os.tag != .windows) return error.SkipZigTest;
+test "delete a read-only file on windows with file pending semantics" {
+ if (builtin.os.tag != .windows or builtin.target.os.version_range.windows.min.isAtLeast(.win10_rs1))
+ return error.SkipZigTest;
+
+ var tmp = tmpDir(.{});
+ defer tmp.cleanup();
+ {
+ const file = try tmp.dir.createFile("test_file", .{ .read = true });
+ defer file.close();
+ // Create a file and make it read-only
+ const metadata = try file.metadata();
+ var permissions = metadata.permissions();
+ permissions.setReadOnly(true);
+ try file.setPermissions(permissions);
+ try testing.expectError(error.AccessDenied, tmp.dir.deleteFile("test_file"));
+ // Now make the file not read-only
+ permissions.setReadOnly(false);
+ try file.setPermissions(permissions);
+ }
+ try tmp.dir.deleteFile("test_file");
+}
+
+test "delete a read-only file on windows with posix semantis" {
+ if (builtin.os.tag != .windows or !builtin.target.os.version_range.windows.min.isAtLeast(.win10_rs1))
+ return error.SkipZigTest;
var tmp = tmpDir(.{});
defer tmp.cleanup();
const file = try tmp.dir.createFile("test_file", .{ .read = true });
+ defer file.close();
// Create a file and make it read-only
const metadata = try file.metadata();
var permissions = metadata.permissions();
permissions.setReadOnly(true);
try file.setPermissions(permissions);
- try testing.expectError(error.AccessDenied, tmp.dir.deleteFile("test_file"));
- // Now make the file not read-only
- permissions.setReadOnly(false);
- try file.setPermissions(permissions);
- file.close();
- try tmp.dir.deleteFile("test_file");
+ try tmp.dir.deleteFile("test_file"); // file is unmapped and deleted once last handle closed
}
test "delete a setAsCwd directory on Windows" {