| ... | ... | @@ -855,14 +855,20 @@ pub const AtomicFile = struct { |
| 855 | 855 | const dirname = os.path.dirname(dest_path); |
| 856 | 856 | |
| 857 | 857 | var rand_buf: [12]u8 = undefined; |
| 858 | | const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64.Base64Encoder.calcSize(rand_buf.len)); |
| 858 | |
| 859 | const dirname_component_len = if (dirname.len == 0) 0 else dirname.len + 1; |
| 860 | const tmp_path = try allocator.alloc(u8, dirname_component_len + |
| 861 | base64.Base64Encoder.calcSize(rand_buf.len)); |
| 859 | 862 | errdefer allocator.free(tmp_path); |
| 860 | | mem.copy(u8, tmp_path[0..], dirname); |
| 861 | | tmp_path[dirname.len] = os.path.sep; |
| 863 | |
| 864 | if (dirname.len != 0) { |
| 865 | mem.copy(u8, tmp_path[0..], dirname); |
| 866 | tmp_path[dirname.len] = os.path.sep; |
| 867 | } |
| 862 | 868 | |
| 863 | 869 | while (true) { |
| 864 | 870 | try getRandomBytes(rand_buf[0..]); |
| 865 | | b64_fs_encoder.encode(tmp_path[dirname.len + 1..], rand_buf); |
| 871 | b64_fs_encoder.encode(tmp_path[dirname_component_len..], rand_buf); |
| 866 | 872 | |
| 867 | 873 | const file = os.File.openWriteNoClobber(allocator, tmp_path, mode) catch |err| switch (err) { |
| 868 | 874 | error.PathAlreadyExists => continue, |