diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-12-11 21:00:14 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-12-23 22:15:09 -0800 |
| commit | 0e230993d51d0ecded40d5235ada4f2f64036b26 (patch) | |
| tree | 4caa6e7f003c791cd96a54b63226b78eaa649282 /src | |
| parent | c4cefd68358470d464bf66bc41985cadd874db73 (diff) | |
| download | zig-0e230993d51d0ecded40d5235ada4f2f64036b26.tar.gz zig-0e230993d51d0ecded40d5235ada4f2f64036b26.zip | |
std.Io.Dir: add setFilePermissions and setFileOwner
Diffstat (limited to 'src')
| -rw-r--r-- | src/Package/Fetch.zig | 4 | ||||
| -rw-r--r-- | src/link/Lld.zig | 12 | ||||
| -rw-r--r-- | src/link/Wasm.zig | 2 |
3 files changed, 7 insertions, 11 deletions
diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig index 137d7635e7..844acf9339 100644 --- a/src/Package/Fetch.zig +++ b/src/Package/Fetch.zig @@ -1717,7 +1717,7 @@ fn deleteFileFallible(io: Io, dir: Io.Dir, deleted_file: *DeletedFile) DeletedFi } fn setExecutable(file: Io.File) !void { - if (!std.fs.has_executable_bit) return; + if (!Io.File.Permissions.has_executable_bit) return; const S = std.posix.S; const mode = Io.File.default_mode | S.IXUSR | S.IXGRP | S.IXOTH; @@ -2183,7 +2183,7 @@ test "tarball without root folder" { } test "set executable bit based on file content" { - if (!std.fs.has_executable_bit) return error.SkipZigTest; + if (!Io.File.Permissions.has_executable_bit) return error.SkipZigTest; const gpa = std.testing.allocator; const io = std.testing.io; diff --git a/src/link/Lld.zig b/src/link/Lld.zig index e3127b24bf..91455f3fde 100644 --- a/src/link/Lld.zig +++ b/src/link/Lld.zig @@ -1327,6 +1327,7 @@ fn getLDMOption(target: *const std.Target) ?[]const u8 { } fn wasmLink(lld: *Lld, arena: Allocator) !void { const comp = lld.base.comp; + const diags = &comp.link_diags; const shared_memory = comp.config.shared_memory; const export_memory = comp.config.export_memory; const import_memory = comp.config.import_memory; @@ -1566,17 +1567,12 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void { // is not the case, it means we will get "exec format error" when trying to run // it, and then can react to that in the same way as trying to run an ELF file // from a foreign CPU architecture. - if (fs.has_executable_bit and target.os.tag == .wasi and + if (Io.File.Permissions.has_executable_bit and target.os.tag == .wasi and comp.config.output_mode == .Exe) { - // TODO: what's our strategy for reporting linker errors from this function? - // report a nice error here with the file path if it fails instead of - // just returning the error code. // chmod does not interact with umask, so we use a conservative -rwxr--r-- here. - std.posix.fchmodat(Io.Dir.cwd().handle, full_out_path, 0o744, 0) catch |err| switch (err) { - error.OperationNotSupported => unreachable, // Not a symlink. - else => |e| return e, - }; + Io.Dir.cwd().setFilePermissions(full_out_path, .fromMode(0o744), .{}) catch |err| + return diags.fail("{s}: failed to enable executable permissions: {t}", .{ full_out_path, err }); } } } diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 5f89625d56..80a248eb6f 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -3002,7 +3002,7 @@ pub fn createEmpty( wasm.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{ .truncate = true, .read = true, - .mode = if (fs.has_executable_bit) + .mode = if (Io.File.Permissions.has_executable_bit) if (target.os.tag == .wasi and output_mode == .Exe) Io.File.default_mode | 0b001_000_000 else |
