diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-01-02 14:11:27 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-02 14:11:27 -0800 |
| commit | 289ae45c1b58e952867c4fa1e246d0ef7bc2ff64 (patch) | |
| tree | 5dd034143a2354b7b44496e684f1c764e2f9664c /lib/std/fs | |
| parent | c89bb3e141ee215add0b52930d48bffd8dae8342 (diff) | |
| parent | c546ddb3edc557fae4b932e5239b9dcb66117832 (diff) | |
| download | zig-289ae45c1b58e952867c4fa1e246d0ef7bc2ff64.tar.gz zig-289ae45c1b58e952867c4fa1e246d0ef7bc2ff64.zip | |
Merge pull request #18160 from ziglang/std-build-module
Move many settings from being per-Compilation to being per-Module
Diffstat (limited to 'lib/std/fs')
| -rw-r--r-- | lib/std/fs/AtomicFile.zig | 4 | ||||
| -rw-r--r-- | lib/std/fs/Dir.zig | 16 |
2 files changed, 15 insertions, 5 deletions
diff --git a/lib/std/fs/AtomicFile.zig b/lib/std/fs/AtomicFile.zig index b090bc9582..c95ae9bcf2 100644 --- a/lib/std/fs/AtomicFile.zig +++ b/lib/std/fs/AtomicFile.zig @@ -65,6 +65,10 @@ pub fn deinit(self: *AtomicFile) void { pub const FinishError = posix.RenameError; +/// On Windows, this function introduces a period of time where some file +/// system operations on the destination file will result in +/// `error.AccessDenied`, including rename operations (such as the one used in +/// this function). pub fn finish(self: *AtomicFile) FinishError!void { assert(self.file_exists); if (self.file_open) { diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index b637e664f1..4a45975ccc 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -2416,15 +2416,21 @@ fn copy_file(fd_in: posix.fd_t, fd_out: posix.fd_t, maybe_size: ?u64) CopyFileRa pub const AtomicFileOptions = struct { mode: File.Mode = File.default_mode, + make_path: bool = false, }; -/// Directly access the `.file` field, and then call `AtomicFile.finish` -/// to atomically replace `dest_path` with contents. -/// Always call `AtomicFile.deinit` to clean up, regardless of whether `AtomicFile.finish` succeeded. -/// `dest_path` must remain valid until `AtomicFile.deinit` is called. +/// Directly access the `.file` field, and then call `AtomicFile.finish` to +/// atomically replace `dest_path` with contents. +/// Always call `AtomicFile.deinit` to clean up, regardless of whether +/// `AtomicFile.finish` succeeded. `dest_path` must remain valid until +/// `AtomicFile.deinit` is called. pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile { if (fs.path.dirname(dest_path)) |dirname| { - const dir = try self.openDir(dirname, .{}); + const dir = if (options.make_path) + try self.makeOpenPath(dirname, .{}) + else + try self.openDir(dirname, .{}); + return AtomicFile.init(fs.path.basename(dest_path), options.mode, dir, true); } else { return AtomicFile.init(dest_path, options.mode, self, false); |
