std.fs.File: flatten struct
This commit is contained in:
@@ -249,7 +249,7 @@ set(ZIG_STAGE2_SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/fs.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/fs/AtomicFile.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/fs/Dir.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/fs/file.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/fs/File.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/fs/get_app_data_dir.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/fs/path.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/hash.zig"
|
||||
|
||||
@@ -10,16 +10,16 @@ const assert = std.debug.assert;
|
||||
|
||||
const is_darwin = builtin.os.tag.isDarwin();
|
||||
|
||||
pub const Dir = @import("fs/Dir.zig");
|
||||
pub const AtomicFile = @import("fs/AtomicFile.zig");
|
||||
pub const Dir = @import("fs/Dir.zig");
|
||||
pub const File = @import("fs/File.zig");
|
||||
pub const path = @import("fs/path.zig");
|
||||
|
||||
pub const has_executable_bit = switch (builtin.os.tag) {
|
||||
.windows, .wasi => false,
|
||||
else => true,
|
||||
};
|
||||
|
||||
pub const path = @import("fs/path.zig");
|
||||
pub const File = @import("fs/file.zig").File;
|
||||
pub const wasi = @import("fs/wasi.zig");
|
||||
|
||||
// TODO audit these APIs with respect to Dir and absolute paths
|
||||
@@ -94,6 +94,7 @@ pub const need_async_thread = std.io.is_async and switch (builtin.os.tag) {
|
||||
};
|
||||
|
||||
/// TODO remove the allocator requirement from this API
|
||||
/// TODO move to Dir
|
||||
pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path: []const u8) !void {
|
||||
if (cwd().symLink(existing_path, new_path, .{})) {
|
||||
return;
|
||||
@@ -104,7 +105,7 @@ pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path:
|
||||
|
||||
const dirname = path.dirname(new_path) orelse ".";
|
||||
|
||||
var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined;
|
||||
var rand_buf: [AtomicFile.random_bytes_len]u8 = undefined;
|
||||
const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64_encoder.calcSize(rand_buf.len));
|
||||
defer allocator.free(tmp_path);
|
||||
@memcpy(tmp_path[0..dirname.len], dirname);
|
||||
@@ -634,8 +635,9 @@ test {
|
||||
_ = ©FileAbsolute;
|
||||
_ = &updateFileAbsolute;
|
||||
}
|
||||
_ = &File;
|
||||
_ = &AtomicFile;
|
||||
_ = &Dir;
|
||||
_ = &File;
|
||||
_ = &path;
|
||||
_ = @import("fs/test.zig");
|
||||
_ = @import("fs/get_app_data_dir.zig");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
file: File,
|
||||
// TODO either replace this with rand_buf or use []u16 on Windows
|
||||
tmp_path_buf: [TMP_PATH_LEN:0]u8,
|
||||
tmp_path_buf: [tmp_path_len:0]u8,
|
||||
dest_basename: []const u8,
|
||||
file_open: bool,
|
||||
file_exists: bool,
|
||||
@@ -9,8 +9,8 @@ dir: Dir,
|
||||
|
||||
pub const InitError = File.OpenError;
|
||||
|
||||
const RANDOM_BYTES = 12;
|
||||
const TMP_PATH_LEN = fs.base64_encoder.calcSize(RANDOM_BYTES);
|
||||
pub const random_bytes_len = 12;
|
||||
const tmp_path_len = fs.base64_encoder.calcSize(random_bytes_len);
|
||||
|
||||
/// Note that the `Dir.atomicFile` API may be more handy than this lower-level function.
|
||||
pub fn init(
|
||||
@@ -19,8 +19,8 @@ pub fn init(
|
||||
dir: Dir,
|
||||
close_dir_on_deinit: bool,
|
||||
) InitError!AtomicFile {
|
||||
var rand_buf: [RANDOM_BYTES]u8 = undefined;
|
||||
var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined;
|
||||
var rand_buf: [random_bytes_len]u8 = undefined;
|
||||
var tmp_path_buf: [tmp_path_len:0]u8 = undefined;
|
||||
|
||||
while (true) {
|
||||
std.crypto.random.bytes(rand_buf[0..]);
|
||||
@@ -81,4 +81,5 @@ const File = std.fs.File;
|
||||
const Dir = std.fs.Dir;
|
||||
const fs = std.fs;
|
||||
const assert = std.debug.assert;
|
||||
// https://github.com/ziglang/zig/issues/5019
|
||||
const posix = std.os;
|
||||
|
||||
@@ -2527,6 +2527,7 @@ const builtin = @import("builtin");
|
||||
const std = @import("../std.zig");
|
||||
const File = std.fs.File;
|
||||
const AtomicFile = std.fs.AtomicFile;
|
||||
// https://github.com/ziglang/zig/issues/5019
|
||||
const posix = std.os;
|
||||
const mem = std.mem;
|
||||
const fs = std.fs;
|
||||
|
||||
1624
lib/std/fs/File.zig
Normal file
1624
lib/std/fs/File.zig
Normal file
File diff suppressed because it is too large
Load Diff
1622
lib/std/fs/file.zig
1622
lib/std/fs/file.zig
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user