Commit ba35eeb417
Changed files (5)
src
lib/std/Build/Cache.zig
@@ -408,7 +408,7 @@ pub const Manifest = struct {
if (self.cache.manifest_dir.createFile(&manifest_file_path, .{
.read = true,
.truncate = false,
- .lock = .Exclusive,
+ .lock = .exclusive,
.lock_nonblocking = self.want_shared_lock,
})) |manifest_file| {
self.manifest_file = manifest_file;
@@ -418,7 +418,7 @@ pub const Manifest = struct {
error.WouldBlock => {
self.manifest_file = try self.cache.manifest_dir.openFile(&manifest_file_path, .{
.mode = .read_write,
- .lock = .Shared,
+ .lock = .shared,
});
break;
},
@@ -885,7 +885,7 @@ pub const Manifest = struct {
// Here we intentionally have a period where the lock is released, in case there are
// other processes holding a shared lock.
manifest_file.unlock();
- try manifest_file.lock(.Exclusive);
+ try manifest_file.lock(.exclusive);
}
self.have_exclusive_lock = true;
return true;
lib/std/fs/file.zig
@@ -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,
@@ -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
@@ -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
@@ -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,
lib/std/fs/test.zig
@@ -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();
@@ -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();
lib/std/fs.zig
@@ -1157,9 +1157,9 @@ pub const Dir = struct {
else
0;
os_flags |= switch (flags.lock) {
- .None => @as(u32, 0),
- .Shared => os.O.SHLOCK | nonblocking_lock_flag,
- .Exclusive => os.O.EXLOCK | nonblocking_lock_flag,
+ .none => @as(u32, 0),
+ .shared => os.O.SHLOCK | nonblocking_lock_flag,
+ .exclusive => os.O.EXLOCK | nonblocking_lock_flag,
};
}
if (@hasDecl(os.O, "LARGEFILE")) {
@@ -1182,13 +1182,13 @@ pub const Dir = struct {
// WASI doesn't have os.flock so we intetinally check OS prior to the inner if block
// since it is not compiltime-known and we need to avoid undefined symbol in Wasm.
if (builtin.target.os.tag != .wasi) {
- if (!has_flock_open_flags and flags.lock != .None) {
+ if (!has_flock_open_flags and flags.lock != .none) {
// TODO: integrate async I/O
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK.NB else @as(i32, 0);
try os.flock(fd, switch (flags.lock) {
- .None => unreachable,
- .Shared => os.LOCK.SH | lock_nonblocking,
- .Exclusive => os.LOCK.EX | lock_nonblocking,
+ .none => unreachable,
+ .shared => os.LOCK.SH | lock_nonblocking,
+ .exclusive => os.LOCK.EX | lock_nonblocking,
});
}
}
@@ -1241,9 +1241,9 @@ pub const Dir = struct {
const range_off: w.LARGE_INTEGER = 0;
const range_len: w.LARGE_INTEGER = 1;
const exclusive = switch (flags.lock) {
- .None => return file,
- .Shared => false,
- .Exclusive => true,
+ .none => return file,
+ .shared => false,
+ .exclusive => true,
};
try w.LockFile(
file.handle,
@@ -1320,9 +1320,9 @@ pub const Dir = struct {
else
0;
const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {
- .None => @as(u32, 0),
- .Shared => os.O.SHLOCK | nonblocking_lock_flag,
- .Exclusive => os.O.EXLOCK | nonblocking_lock_flag,
+ .none => @as(u32, 0),
+ .shared => os.O.SHLOCK | nonblocking_lock_flag,
+ .exclusive => os.O.EXLOCK | nonblocking_lock_flag,
} else 0;
const O_LARGEFILE = if (@hasDecl(os.O, "LARGEFILE")) os.O.LARGEFILE else 0;
@@ -1339,13 +1339,13 @@ pub const Dir = struct {
// WASI doesn't have os.flock so we intetinally check OS prior to the inner if block
// since it is not compiltime-known and we need to avoid undefined symbol in Wasm.
if (builtin.target.os.tag != .wasi) {
- if (!has_flock_open_flags and flags.lock != .None) {
+ if (!has_flock_open_flags and flags.lock != .none) {
// TODO: integrate async I/O
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK.NB else @as(i32, 0);
try os.flock(fd, switch (flags.lock) {
- .None => unreachable,
- .Shared => os.LOCK.SH | lock_nonblocking,
- .Exclusive => os.LOCK.EX | lock_nonblocking,
+ .none => unreachable,
+ .shared => os.LOCK.SH | lock_nonblocking,
+ .exclusive => os.LOCK.EX | lock_nonblocking,
});
}
}
@@ -1402,9 +1402,9 @@ pub const Dir = struct {
const range_off: w.LARGE_INTEGER = 0;
const range_len: w.LARGE_INTEGER = 1;
const exclusive = switch (flags.lock) {
- .None => return file,
- .Shared => false,
- .Exclusive => true,
+ .none => return file,
+ .shared => false,
+ .exclusive => true,
};
try w.LockFile(
file.handle,
src/Module.zig
@@ -3618,7 +3618,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
file.sub_file_path, want_local_cache, &digest,
});
- break :lock .Shared;
+ break :lock .shared;
},
.parse_failure, .astgen_failure, .success_zir => lock: {
const unchanged_metadata =
@@ -3633,7 +3633,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
log.debug("metadata changed: {s}", .{file.sub_file_path});
- break :lock .Exclusive;
+ break :lock .exclusive;
},
};
@@ -3715,11 +3715,11 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
}
// If we already have the exclusive lock then it is our job to update.
- if (builtin.os.tag == .wasi or lock == .Exclusive) break;
+ if (builtin.os.tag == .wasi or lock == .exclusive) break;
// Otherwise, unlock to give someone a chance to get the exclusive lock
// and then upgrade to an exclusive lock.
cache_file.unlock();
- lock = .Exclusive;
+ lock = .exclusive;
try cache_file.lock(lock);
}