| author | |
| committer | |
| log | 41e17106cdcb0bc19f26ef67ebe2d98d920ee21b |
| tree | 5097dd7ccdadda390fca0e43c03ab0b504a9ef24 |
| parent | fdff381a5644d5e12519ca53012d7b00a33a33c4 |
The previous commit made zig fmt print absolute paths; this commit keeps
the absolute path resolution but still prints the relative paths to
stdout.2 files changed, 9 insertions(+), 5 deletions(-)
lib/std/io/buffered_atomic_file.zig+7-3| ... | ... | @@ -15,8 +15,12 @@ pub const BufferedAtomicFile = struct { |
| 15 | 15 | |
| 16 | 16 | /// TODO when https://github.com/ziglang/zig/issues/2761 is solved |
| 17 | 17 | /// this API will not need an allocator |
| 18 | /// TODO integrate this with Dir API | |
| 19 | pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { | |
| 18 | pub fn create( | |
| 19 | allocator: *mem.Allocator, | |
| 20 | dir: fs.Dir, | |
| 21 | dest_path: []const u8, | |
| 22 | atomic_file_options: fs.Dir.AtomicFileOptions, | |
| 23 | ) !*BufferedAtomicFile { | |
| 20 | 24 | var self = try allocator.create(BufferedAtomicFile); |
| 21 | 25 | self.* = BufferedAtomicFile{ |
| 22 | 26 | .atomic_file = undefined, |
| ... | ... | @@ -26,7 +30,7 @@ pub const BufferedAtomicFile = struct { |
| 26 | 30 | }; |
| 27 | 31 | errdefer allocator.destroy(self); |
| 28 | 32 | |
| 29 | self.atomic_file = try fs.cwd().atomicFile(dest_path, .{}); | |
| 33 | self.atomic_file = try dir.atomicFile(dest_path, atomic_file_options); | |
| 30 | 34 | errdefer self.atomic_file.deinit(); |
| 31 | 35 | |
| 32 | 36 | self.file_stream = self.atomic_file.file.outStream(); |
src-self-hosted/stage2.zig+2-2| ... | ... | @@ -339,7 +339,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 339 | 339 | |
| 340 | 340 | while (try dir_it.next()) |entry| { |
| 341 | 341 | if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) { |
| 342 | const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ real_path, entry.name }); | |
| 342 | const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ file_path, entry.name }); | |
| 343 | 343 | try fmtPath(fmt, full_path, check_mode); |
| 344 | 344 | } |
| 345 | 345 | } |
| ... | ... | @@ -377,7 +377,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 377 | 377 | fmt.any_error = true; |
| 378 | 378 | } |
| 379 | 379 | } else { |
| 380 | const baf = try io.BufferedAtomicFile.create(fmt.allocator, real_path); | |
| 380 | const baf = try io.BufferedAtomicFile.create(fmt.allocator, fs.cwd(), real_path, .{}); | |
| 381 | 381 | defer baf.destroy(); |
| 382 | 382 | |
| 383 | 383 | const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree); |