about summary refs log tree commit diff
path: root/src/fs.zig
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/fs.zig7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/fs.zig b/src/fs.zig
index 4a3b049..08ad7ee 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -13,6 +13,7 @@ pub const FileSwapper = struct {
     target_path: []const u8,
     tmp_path: []const u8,
     tmp: std.fs.File,
+    swapped: *bool,
 
     pub fn createAt(alloc: std.mem.Allocator, path: []const u8) !FileSwapper {
         const target_dir = std.fs.path.dirname(path) orelse ".";
@@ -32,11 +33,15 @@ pub const FileSwapper = struct {
 
         const f = try std.fs.cwd().createFile(tmp_path, .{});
 
+        const swapped = try alloc.create(bool);
+        swapped.* = false;
+
         return .{
             .allocator = alloc,
             .target_path = path,
             .tmp_path = tmp_path,
             .tmp = f,
+            .swapped = swapped,
         };
     }
 
@@ -63,6 +68,8 @@ pub const FileSwapper = struct {
             std.fs.cwd(),
             self.target_path,
         );
+
+        self.swapped.* = true;
     }
 
     pub fn close(self: FileSwapper) void {