feat: persist file mode

This commit is contained in:
LordMZTE 2023-01-26 21:28:15 +01:00
parent ba39527dc9
commit 6fcfa85605
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
1 changed files with 3 additions and 1 deletions

View File

@ -106,6 +106,7 @@ fn genfile(
var content: []const u8 = undefined;
var fname: ?[]const u8 = null;
var file_mode: std.fs.File.Mode = std.fs.File.default_mode;
switch (file.content) {
.string => |s| content = s,
.path => |p| {
@ -113,6 +114,7 @@ fn genfile(
const path = try std.fs.path.join(std.heap.c_allocator, &.{ state.rootpath, p });
defer std.heap.c_allocator.free(path);
file_mode = (try std.fs.cwd().statFile(path)).mode;
const f = try std.fs.cwd().openFile(path, .{});
defer f.close();
@ -143,7 +145,7 @@ fn genfile(
try std.fs.cwd().makePath(dir);
}
var outfile = try std.fs.cwd().createFile(path, .{});
var outfile = try std.fs.cwd().createFile(path, .{ .mode = file_mode });
defer outfile.close();
try outfile.writeAll(out);