| ... | @@ -2416,15 +2416,21 @@ fn copy_file(fd_in: posix.fd_t, fd_out: posix.fd_t, maybe_size: ?u64) CopyFileRa | ... | @@ -2416,15 +2416,21 @@ fn copy_file(fd_in: posix.fd_t, fd_out: posix.fd_t, maybe_size: ?u64) CopyFileRa |
| 2416 | | 2416 | |
| 2417 | pub const AtomicFileOptions = struct { | 2417 | pub const AtomicFileOptions = struct { |
| 2418 | mode: File.Mode = File.default_mode, | 2418 | mode: File.Mode = File.default_mode, |
| | 2419 | make_path: bool = false, |
| 2419 | }; | 2420 | }; |
| 2420 | | 2421 | |
| 2421 | /// Directly access the `.file` field, and then call `AtomicFile.finish` | 2422 | /// Directly access the `.file` field, and then call `AtomicFile.finish` to |
| 2422 | /// to atomically replace `dest_path` with contents. | 2423 | /// atomically replace `dest_path` with contents. |
| 2423 | /// Always call `AtomicFile.deinit` to clean up, regardless of whether `AtomicFile.finish` succeeded. | 2424 | /// Always call `AtomicFile.deinit` to clean up, regardless of whether |
| 2424 | /// `dest_path` must remain valid until `AtomicFile.deinit` is called. | 2425 | /// `AtomicFile.finish` succeeded. `dest_path` must remain valid until |
| | 2426 | /// `AtomicFile.deinit` is called. |
| 2425 | pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile { | 2427 | pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile { |
| 2426 | if (fs.path.dirname(dest_path)) |dirname| { | 2428 | if (fs.path.dirname(dest_path)) |dirname| { |
| 2427 | const dir = try self.openDir(dirname, .{}); | 2429 | const dir = if (options.make_path) |
| | 2430 | try self.makeOpenPath(dirname, .{}) |
| | 2431 | else |
| | 2432 | try self.openDir(dirname, .{}); |
| | 2433 | |
| 2428 | return AtomicFile.init(fs.path.basename(dest_path), options.mode, dir, true); | 2434 | return AtomicFile.init(fs.path.basename(dest_path), options.mode, dir, true); |
| 2429 | } else { | 2435 | } else { |
| 2430 | return AtomicFile.init(dest_path, options.mode, self, false); | 2436 | return AtomicFile.init(dest_path, options.mode, self, false); |