mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
update makeDir() sites to specify permissions
This commit is contained in:
@@ -92,9 +92,7 @@ pub fn main() !void {
|
||||
if (i >= args.len) fatal("expected 32-bit integer after {s}", .{arg});
|
||||
const next_arg = args[i];
|
||||
seed = std.fmt.parseUnsigned(u32, next_arg, 0) catch |err| {
|
||||
fatal("unable to parse seed '{s}' as 32-bit integer: {s}", .{
|
||||
next_arg, @errorName(err),
|
||||
});
|
||||
fatal("unable to parse seed '{s}' as 32-bit integer: {t}", .{ next_arg, err });
|
||||
};
|
||||
} else {
|
||||
fatal("unrecognized parameter: '{s}'", .{arg});
|
||||
@@ -125,7 +123,7 @@ pub fn main() !void {
|
||||
var astgen_input: std.Io.Writer.Allocating = .init(gpa);
|
||||
defer astgen_input.deinit();
|
||||
|
||||
var tree = try parse(gpa, root_source_file_path);
|
||||
var tree = try parse(gpa, io, root_source_file_path);
|
||||
defer {
|
||||
gpa.free(tree.source);
|
||||
tree.deinit(gpa);
|
||||
@@ -190,7 +188,7 @@ pub fn main() !void {
|
||||
std.debug.print("{s} ", .{@tagName(t)});
|
||||
}
|
||||
std.debug.print("\n", .{});
|
||||
try transformationsToFixups(gpa, arena, root_source_file_path, this_set, &fixups);
|
||||
try transformationsToFixups(gpa, arena, io, root_source_file_path, this_set, &fixups);
|
||||
|
||||
rendered.clearRetainingCapacity();
|
||||
try tree.render(gpa, &rendered.writer, fixups);
|
||||
@@ -246,7 +244,7 @@ pub fn main() !void {
|
||||
});
|
||||
switch (interestingness) {
|
||||
.interesting => {
|
||||
const new_tree = try parse(gpa, root_source_file_path);
|
||||
const new_tree = try parse(gpa, io, root_source_file_path);
|
||||
gpa.free(tree.source);
|
||||
tree.deinit(gpa);
|
||||
tree = new_tree;
|
||||
@@ -317,6 +315,7 @@ fn runCheck(arena: Allocator, io: Io, argv: []const []const u8) !Interestingness
|
||||
fn transformationsToFixups(
|
||||
gpa: Allocator,
|
||||
arena: Allocator,
|
||||
io: Io,
|
||||
root_source_file_path: []const u8,
|
||||
transforms: []const Walk.Transformation,
|
||||
fixups: *Ast.Render.Fixups,
|
||||
@@ -354,7 +353,7 @@ fn transformationsToFixups(
|
||||
inline_imported_file.imported_string,
|
||||
});
|
||||
defer gpa.free(full_imported_path);
|
||||
var other_file_ast = try parse(gpa, full_imported_path);
|
||||
var other_file_ast = try parse(gpa, io, full_imported_path);
|
||||
defer {
|
||||
gpa.free(other_file_ast.source);
|
||||
other_file_ast.deinit(gpa);
|
||||
@@ -398,8 +397,9 @@ fn transformationsToFixups(
|
||||
};
|
||||
}
|
||||
|
||||
fn parse(gpa: Allocator, file_path: []const u8) !Ast {
|
||||
fn parse(gpa: Allocator, io: Io, file_path: []const u8) !Ast {
|
||||
const source_code = Io.Dir.cwd().readFileAllocOptions(
|
||||
io,
|
||||
file_path,
|
||||
gpa,
|
||||
.limited(std.math.maxInt(u32)),
|
||||
|
||||
@@ -547,12 +547,14 @@ pub fn checkComputeCompare(
|
||||
fn make(step: *Step, make_options: Step.MakeOptions) !void {
|
||||
_ = make_options;
|
||||
const b = step.owner;
|
||||
const io = b.graph.io;
|
||||
const gpa = b.allocator;
|
||||
const check_object: *CheckObject = @fieldParentPtr("step", step);
|
||||
try step.singleUnchangingWatchInput(check_object.source);
|
||||
|
||||
const src_path = check_object.source.getPath3(b, step);
|
||||
const contents = src_path.root_dir.handle.readFileAllocOptions(
|
||||
io,
|
||||
src_path.sub_path,
|
||||
gpa,
|
||||
.limited(check_object.max_bytes),
|
||||
|
||||
@@ -27,6 +27,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
|
||||
_ = options;
|
||||
|
||||
const b = step.owner;
|
||||
const io = b.graph.io;
|
||||
const remove_dir: *RemoveDir = @fieldParentPtr("step", step);
|
||||
|
||||
step.clearWatchInputs();
|
||||
@@ -34,15 +35,11 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
|
||||
|
||||
const full_doomed_path = remove_dir.doomed_path.getPath2(b, step);
|
||||
|
||||
b.build_root.handle.deleteTree(full_doomed_path) catch |err| {
|
||||
b.build_root.handle.deleteTree(io, full_doomed_path) catch |err| {
|
||||
if (b.build_root.path) |base| {
|
||||
return step.fail("unable to recursively delete path '{s}/{s}': {s}", .{
|
||||
base, full_doomed_path, @errorName(err),
|
||||
});
|
||||
return step.fail("unable to recursively delete path '{s}/{s}': {t}", .{ base, full_doomed_path, err });
|
||||
} else {
|
||||
return step.fail("unable to recursively delete path '{s}': {s}", .{
|
||||
full_doomed_path, @errorName(err),
|
||||
});
|
||||
return step.fail("unable to recursively delete path '{s}': {t}", .{ full_doomed_path, err });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1044,7 +1044,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
|
||||
|
||||
b.cache_root.handle.rename(tmp_dir_path, b.cache_root.handle, o_sub_path, io) catch |err| {
|
||||
if (err == error.PathAlreadyExists) {
|
||||
b.cache_root.handle.deleteTree(o_sub_path) catch |del_err| {
|
||||
b.cache_root.handle.deleteTree(io, o_sub_path) catch |del_err| {
|
||||
return step.fail("unable to remove dir '{f}'{s}: {t}", .{
|
||||
b.cache_root, tmp_dir_path, del_err,
|
||||
});
|
||||
|
||||
+35
-35
@@ -186,7 +186,7 @@ test "Dir.readLink" {
|
||||
const file_target_path = try ctx.transformPath("file.txt");
|
||||
try ctx.dir.writeFile(io, .{ .sub_path = file_target_path, .data = "nonsense" });
|
||||
const dir_target_path = try ctx.transformPath("subdir");
|
||||
try ctx.dir.makeDir(dir_target_path);
|
||||
try ctx.dir.makeDir(io, dir_target_path, .default_dir);
|
||||
|
||||
// On Windows, symlink targets always use the canonical path separator
|
||||
const canonical_file_target_path = try ctx.toCanonicalPathSep(file_target_path);
|
||||
@@ -282,7 +282,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
|
||||
try testWithAllSupportedPathTypes(struct {
|
||||
fn impl(ctx: *TestContext) !void {
|
||||
const dir_target_path = try ctx.transformPath("subdir");
|
||||
try ctx.dir.makeDir(dir_target_path);
|
||||
try ctx.dir.makeDir(io, dir_target_path, .default_dir);
|
||||
|
||||
try setupSymlink(ctx.dir, dir_target_path, "symlink", .{ .is_directory = true });
|
||||
|
||||
@@ -363,7 +363,7 @@ test "openDir" {
|
||||
fn impl(ctx: *TestContext) !void {
|
||||
const allocator = ctx.arena.allocator();
|
||||
const subdir_path = try ctx.transformPath("subdir");
|
||||
try ctx.dir.makeDir(subdir_path);
|
||||
try ctx.dir.makeDir(io, subdir_path, .default_dir);
|
||||
|
||||
for ([_][]const u8{ "", ".", ".." }) |sub_path| {
|
||||
const dir_path = try fs.path.join(allocator, &.{ subdir_path, sub_path });
|
||||
@@ -398,7 +398,7 @@ test "openDirAbsolute" {
|
||||
|
||||
const tmp_ino = (try tmp.dir.stat(io)).inode;
|
||||
|
||||
try tmp.dir.makeDir("subdir");
|
||||
try tmp.dir.makeDir(io, "subdir", .default_dir);
|
||||
const sub_path = try tmp.dir.realpathAlloc(testing.allocator, "subdir");
|
||||
defer testing.allocator.free(sub_path);
|
||||
|
||||
@@ -494,7 +494,7 @@ test "readLinkAbsolute" {
|
||||
|
||||
// Create some targets
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
|
||||
try tmp.dir.makeDir("subdir");
|
||||
try tmp.dir.makeDir(io, "subdir", .default_dir);
|
||||
|
||||
// Get base abs path
|
||||
var arena = ArenaAllocator.init(testing.allocator);
|
||||
@@ -531,7 +531,7 @@ test "Dir.Iterator" {
|
||||
const file = try tmp_dir.dir.createFile(io, "some_file", .{});
|
||||
file.close(io);
|
||||
|
||||
try tmp_dir.dir.makeDir("some_dir");
|
||||
try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
|
||||
|
||||
var arena = ArenaAllocator.init(testing.allocator);
|
||||
defer arena.deinit();
|
||||
@@ -600,7 +600,7 @@ test "Dir.Iterator twice" {
|
||||
const file = try tmp_dir.dir.createFile(io, "some_file", .{});
|
||||
file.close(io);
|
||||
|
||||
try tmp_dir.dir.makeDir("some_dir");
|
||||
try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
|
||||
|
||||
var arena = ArenaAllocator.init(testing.allocator);
|
||||
defer arena.deinit();
|
||||
@@ -635,7 +635,7 @@ test "Dir.Iterator reset" {
|
||||
const file = try tmp_dir.dir.createFile(io, "some_file", .{});
|
||||
file.close(io);
|
||||
|
||||
try tmp_dir.dir.makeDir("some_dir");
|
||||
try tmp_dir.dir.makeDir(io, "some_dir", .default_dir);
|
||||
|
||||
var arena = ArenaAllocator.init(testing.allocator);
|
||||
defer arena.deinit();
|
||||
@@ -682,7 +682,7 @@ test "Dir.Iterator but dir is deleted during iteration" {
|
||||
// This is a contrived reproduction, but this could happen outside of the program, in another thread, etc.
|
||||
// If we get an error while trying to delete, we can skip this test (this will happen on platforms
|
||||
// like Windows which will give FileBusy if the directory is currently open for iteration).
|
||||
tmp.dir.deleteTree("subdir") catch return error.SkipZigTest;
|
||||
tmp.dir.deleteTree(io, "subdir") catch return error.SkipZigTest;
|
||||
|
||||
// Now, when we try to iterate, the next call should return null immediately.
|
||||
const entry = try iterator.next();
|
||||
@@ -724,7 +724,7 @@ test "Dir.realpath smoke test" {
|
||||
|
||||
// Now create the file and dir
|
||||
try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
|
||||
try ctx.dir.makeDir(test_dir_path);
|
||||
try ctx.dir.makeDir(io, test_dir_path, .default_dir);
|
||||
|
||||
const base_path = try ctx.transformPath(".");
|
||||
const base_realpath = try ctx.dir.realpathAlloc(allocator, base_path);
|
||||
@@ -842,7 +842,7 @@ test "directory operations on files" {
|
||||
var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });
|
||||
file.close(io);
|
||||
|
||||
try testing.expectError(error.PathAlreadyExists, ctx.dir.makeDir(test_file_name));
|
||||
try testing.expectError(error.PathAlreadyExists, ctx.dir.makeDir(io, test_file_name, .default_dir));
|
||||
try testing.expectError(error.NotDir, ctx.dir.openDir(io, test_file_name, .{}));
|
||||
try testing.expectError(error.NotDir, ctx.dir.deleteDir(test_file_name));
|
||||
|
||||
@@ -870,7 +870,7 @@ test "file operations on directories" {
|
||||
fn impl(ctx: *TestContext) !void {
|
||||
const test_dir_name = try ctx.transformPath("test_dir");
|
||||
|
||||
try ctx.dir.makeDir(test_dir_name);
|
||||
try ctx.dir.makeDir(io, test_dir_name, .default_dir);
|
||||
|
||||
try testing.expectError(error.IsDir, ctx.dir.createFile(io, test_dir_name, .{}));
|
||||
try testing.expectError(error.IsDir, ctx.dir.deleteFile(test_dir_name));
|
||||
@@ -937,7 +937,7 @@ test "deleteDir" {
|
||||
try testing.expectError(error.FileNotFound, ctx.dir.deleteDir(test_dir_path));
|
||||
|
||||
// deleting a non-empty directory
|
||||
try ctx.dir.makeDir(test_dir_path);
|
||||
try ctx.dir.makeDir(io, test_dir_path, .default_dir);
|
||||
try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
|
||||
try testing.expectError(error.DirNotEmpty, ctx.dir.deleteDir(test_dir_path));
|
||||
|
||||
@@ -1006,7 +1006,7 @@ test "Dir.rename directories" {
|
||||
const test_dir_renamed_path = try ctx.transformPath("test_dir_renamed");
|
||||
|
||||
// Renaming directories
|
||||
try ctx.dir.makeDir(test_dir_path);
|
||||
try ctx.dir.makeDir(io, test_dir_path, .default_dir);
|
||||
try ctx.dir.rename(test_dir_path, ctx.dir, test_dir_renamed_path, io);
|
||||
|
||||
// Ensure the directory was renamed
|
||||
@@ -1042,8 +1042,8 @@ test "Dir.rename directory onto empty dir" {
|
||||
const test_dir_path = try ctx.transformPath("test_dir");
|
||||
const target_dir_path = try ctx.transformPath("target_dir_path");
|
||||
|
||||
try ctx.dir.makeDir(test_dir_path);
|
||||
try ctx.dir.makeDir(target_dir_path);
|
||||
try ctx.dir.makeDir(io, test_dir_path, .default_dir);
|
||||
try ctx.dir.makeDir(io, target_dir_path, .default_dir);
|
||||
try ctx.dir.rename(test_dir_path, ctx.dir, target_dir_path, io);
|
||||
|
||||
// Ensure the directory was renamed
|
||||
@@ -1064,7 +1064,7 @@ test "Dir.rename directory onto non-empty dir" {
|
||||
const test_dir_path = try ctx.transformPath("test_dir");
|
||||
const target_dir_path = try ctx.transformPath("target_dir_path");
|
||||
|
||||
try ctx.dir.makeDir(test_dir_path);
|
||||
try ctx.dir.makeDir(io, test_dir_path, .default_dir);
|
||||
|
||||
var target_dir = try ctx.dir.makeOpenPath(target_dir_path, .{});
|
||||
var file = try target_dir.createFile(io, "test_file", .{ .read = true });
|
||||
@@ -1093,7 +1093,7 @@ test "Dir.rename file <-> dir" {
|
||||
|
||||
var file = try ctx.dir.createFile(io, test_file_path, .{ .read = true });
|
||||
file.close(io);
|
||||
try ctx.dir.makeDir(test_dir_path);
|
||||
try ctx.dir.makeDir(io, test_dir_path, .default_dir);
|
||||
try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, ctx.dir, test_dir_path, io));
|
||||
try testing.expectError(error.NotDir, ctx.dir.rename(test_dir_path, ctx.dir, test_file_path, io));
|
||||
}
|
||||
@@ -1163,7 +1163,7 @@ test "renameAbsolute" {
|
||||
// Renaming directories
|
||||
const test_dir_name = "test_dir";
|
||||
const renamed_test_dir_name = "test_dir_renamed";
|
||||
try tmp_dir.dir.makeDir(test_dir_name);
|
||||
try tmp_dir.dir.makeDir(io, test_dir_name, .default_dir);
|
||||
try fs.renameAbsolute(
|
||||
try fs.path.join(allocator, &.{ base_path, test_dir_name }),
|
||||
try fs.path.join(allocator, &.{ base_path, renamed_test_dir_name }),
|
||||
@@ -1209,7 +1209,7 @@ test "deleteTree does not follow symlinks" {
|
||||
try setupSymlink(a, "../b", "b", .{ .is_directory = true });
|
||||
}
|
||||
|
||||
try tmp.dir.deleteTree("a");
|
||||
try tmp.dir.deleteTree(io, "a");
|
||||
|
||||
try testing.expectError(error.FileNotFound, tmp.dir.access(io, "a", .{}));
|
||||
try tmp.dir.access(io, "b", .{});
|
||||
@@ -1225,7 +1225,7 @@ test "deleteTree on a symlink" {
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "file", .data = "" });
|
||||
try setupSymlink(tmp.dir, "file", "filelink", .{});
|
||||
|
||||
try tmp.dir.deleteTree("filelink");
|
||||
try tmp.dir.deleteTree(io, "filelink");
|
||||
try testing.expectError(error.FileNotFound, tmp.dir.access(io, "filelink", .{}));
|
||||
try tmp.dir.access(io, "file", .{});
|
||||
|
||||
@@ -1233,7 +1233,7 @@ test "deleteTree on a symlink" {
|
||||
try tmp.dir.makePath(io, "dir");
|
||||
try setupSymlink(tmp.dir, "dir", "dirlink", .{ .is_directory = true });
|
||||
|
||||
try tmp.dir.deleteTree("dirlink");
|
||||
try tmp.dir.deleteTree(io, "dirlink");
|
||||
try testing.expectError(error.FileNotFound, tmp.dir.access(io, "dirlink", .{}));
|
||||
try tmp.dir.access(io, "dir", .{});
|
||||
}
|
||||
@@ -1255,7 +1255,7 @@ test "makePath, put some files in it, deleteTree" {
|
||||
.data = "blah",
|
||||
});
|
||||
|
||||
try ctx.dir.deleteTree(dir_path);
|
||||
try ctx.dir.deleteTree(io, dir_path);
|
||||
try testing.expectError(error.FileNotFound, ctx.dir.openDir(io, dir_path, .{}));
|
||||
}
|
||||
}.impl);
|
||||
@@ -1291,7 +1291,7 @@ test "makePath in a directory that no longer exists" {
|
||||
|
||||
var tmp = tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
try tmp.parent_dir.deleteTree(&tmp.sub_path);
|
||||
try tmp.parent_dir.deleteTree(io, &tmp.sub_path);
|
||||
|
||||
try testing.expectError(error.FileNotFound, tmp.dir.makePath(io, "sub-path"));
|
||||
}
|
||||
@@ -1302,7 +1302,7 @@ test "makePath but sub_path contains pre-existing file" {
|
||||
var tmp = tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
|
||||
try tmp.dir.makeDir("foo");
|
||||
try tmp.dir.makeDir(io, "foo", .default_dir);
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "foo/bar", .data = "" });
|
||||
|
||||
try testing.expectError(error.NotDir, tmp.dir.makePath(io, "foo/bar/baz"));
|
||||
@@ -1319,10 +1319,10 @@ test "makepath existing directories" {
|
||||
var tmp = tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
|
||||
try tmp.dir.makeDir("A");
|
||||
try tmp.dir.makeDir(io, "A", .default_dir);
|
||||
var tmpA = try tmp.dir.openDir(io, "A", .{});
|
||||
defer tmpA.close(io);
|
||||
try tmpA.makeDir("B");
|
||||
try tmpA.makeDir(io, "B", .default_dir);
|
||||
|
||||
const testPath = "A" ++ fs.path.sep_str ++ "B" ++ fs.path.sep_str ++ "C";
|
||||
try tmp.dir.makePath(io, testPath);
|
||||
@@ -1336,7 +1336,7 @@ test "makepath through existing valid symlink" {
|
||||
var tmp = tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
|
||||
try tmp.dir.makeDir("realfolder");
|
||||
try tmp.dir.makeDir(io, "realfolder", .default_dir);
|
||||
try setupSymlink(tmp.dir, "." ++ fs.path.sep_str ++ "realfolder", "working-symlink", .{});
|
||||
|
||||
try tmp.dir.makePath(io, "working-symlink" ++ fs.path.sep_str ++ "in-realfolder");
|
||||
@@ -1419,7 +1419,7 @@ fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !vo
|
||||
}
|
||||
|
||||
// ensure that we can delete the tree
|
||||
try iterable_dir.deleteTree(maxed_filename);
|
||||
try iterable_dir.deleteTree(io, maxed_filename);
|
||||
}
|
||||
|
||||
test "max file name component lengths" {
|
||||
@@ -1570,7 +1570,7 @@ test "access file" {
|
||||
|
||||
try ctx.dir.writeFile(io, .{ .sub_path = file_path, .data = "" });
|
||||
try ctx.dir.access(io, file_path, .{});
|
||||
try ctx.dir.deleteTree(dir_path);
|
||||
try ctx.dir.deleteTree(io, dir_path);
|
||||
}
|
||||
}.impl);
|
||||
}
|
||||
@@ -2042,7 +2042,7 @@ test "'.' and '..' in Io.Dir functions" {
|
||||
const rename_path = try ctx.transformPath("./subdir/../rename");
|
||||
const update_path = try ctx.transformPath("./subdir/../update");
|
||||
|
||||
try ctx.dir.makeDir(subdir_path);
|
||||
try ctx.dir.makeDir(io, subdir_path, .default_dir);
|
||||
try ctx.dir.access(io, subdir_path, .{});
|
||||
var created_subdir = try ctx.dir.openDir(io, subdir_path, .{});
|
||||
created_subdir.close(io);
|
||||
@@ -2120,7 +2120,7 @@ test "chmod" {
|
||||
try file.chmod(0o644);
|
||||
try testing.expectEqual(@as(File.Mode, 0o644), (try file.stat(io)).mode & 0o7777);
|
||||
|
||||
try tmp.dir.makeDir("test_dir");
|
||||
try tmp.dir.makeDir(io, "test_dir", .default_dir);
|
||||
var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
|
||||
defer dir.close(io);
|
||||
|
||||
@@ -2141,7 +2141,7 @@ test "chown" {
|
||||
defer file.close(io);
|
||||
try file.chown(null, null);
|
||||
|
||||
try tmp.dir.makeDir("test_dir");
|
||||
try tmp.dir.makeDir(io, "test_dir", .default_dir);
|
||||
|
||||
var dir = try tmp.dir.openDir(io, "test_dir", .{ .iterate = true });
|
||||
defer dir.close(io);
|
||||
@@ -2165,7 +2165,7 @@ test "invalid UTF-8/WTF-8 paths" {
|
||||
|
||||
try testing.expectError(expected_err, ctx.dir.createFile(invalid_path, .{}));
|
||||
|
||||
try testing.expectError(expected_err, ctx.dir.makeDir(invalid_path));
|
||||
try testing.expectError(expected_err, ctx.dir.makeDir(invalid_path, .default_dir));
|
||||
|
||||
try testing.expectError(expected_err, ctx.dir.makePath(invalid_path));
|
||||
try testing.expectError(expected_err, ctx.dir.makeOpenPath(invalid_path, .{}));
|
||||
@@ -2191,7 +2191,7 @@ test "invalid UTF-8/WTF-8 paths" {
|
||||
try testing.expectError(expected_err, ctx.dir.readFile(invalid_path, &[_]u8{}));
|
||||
try testing.expectError(expected_err, ctx.dir.readFileAlloc(invalid_path, testing.allocator, .limited(0)));
|
||||
|
||||
try testing.expectError(expected_err, ctx.dir.deleteTree(invalid_path));
|
||||
try testing.expectError(expected_err, ctx.dir.deleteTree(io, invalid_path));
|
||||
try testing.expectError(expected_err, ctx.dir.deleteTreeMinStackSize(invalid_path));
|
||||
|
||||
try testing.expectError(expected_err, ctx.dir.writeFile(io, .{ .sub_path = invalid_path, .data = "" }));
|
||||
|
||||
+1
-1
@@ -616,7 +616,7 @@ pub const TmpDir = struct {
|
||||
|
||||
pub fn cleanup(self: *TmpDir) void {
|
||||
self.dir.close(io);
|
||||
self.parent_dir.deleteTree(&self.sub_path) catch {};
|
||||
self.parent_dir.deleteTree(io, &self.sub_path) catch {};
|
||||
self.parent_dir.close(io);
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
+8
-14
@@ -2823,12 +2823,9 @@ fn cleanupAfterUpdate(comp: *Compilation, tmp_dir_rand_int: u64) void {
|
||||
return;
|
||||
}
|
||||
const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
|
||||
comp.dirs.local_cache.handle.deleteTree(tmp_dir_sub_path) catch |err| {
|
||||
log.warn("failed to delete temporary directory '{s}{c}{s}': {s}", .{
|
||||
comp.dirs.local_cache.path orelse ".",
|
||||
fs.path.sep,
|
||||
tmp_dir_sub_path,
|
||||
@errorName(err),
|
||||
comp.dirs.local_cache.handle.deleteTree(io, tmp_dir_sub_path) catch |err| {
|
||||
log.warn("failed to delete temporary directory '{s}{c}{s}': {t}", .{
|
||||
comp.dirs.local_cache.path orelse ".", fs.path.sep, tmp_dir_sub_path, err,
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -2847,12 +2844,9 @@ fn cleanupAfterUpdate(comp: *Compilation, tmp_dir_rand_int: u64) void {
|
||||
tmp_dir.handle.close(io);
|
||||
whole.tmp_artifact_directory = null;
|
||||
const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
|
||||
comp.dirs.local_cache.handle.deleteTree(tmp_dir_sub_path) catch |err| {
|
||||
log.warn("failed to delete temporary directory '{s}{c}{s}': {s}", .{
|
||||
comp.dirs.local_cache.path orelse ".",
|
||||
fs.path.sep,
|
||||
tmp_dir_sub_path,
|
||||
@errorName(err),
|
||||
comp.dirs.local_cache.handle.deleteTree(io, tmp_dir_sub_path) catch |err| {
|
||||
log.warn("failed to delete temporary directory '{s}{c}{s}': {t}", .{
|
||||
comp.dirs.local_cache.path orelse ".", fs.path.sep, tmp_dir_sub_path, err,
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -3419,13 +3413,13 @@ fn renameTmpIntoCache(
|
||||
.windows => {
|
||||
if (seen_eaccess) return error.AccessDenied;
|
||||
seen_eaccess = true;
|
||||
try cache_directory.handle.deleteTree(o_sub_path);
|
||||
try cache_directory.handle.deleteTree(io, o_sub_path);
|
||||
continue;
|
||||
},
|
||||
else => return error.AccessDenied,
|
||||
},
|
||||
error.PathAlreadyExists => {
|
||||
try cache_directory.handle.deleteTree(o_sub_path);
|
||||
try cache_directory.handle.deleteTree(io, o_sub_path);
|
||||
continue;
|
||||
},
|
||||
error.FileNotFound => {
|
||||
|
||||
@@ -656,9 +656,11 @@ fn checkBuildFileExistence(f: *Fetch) RunError!void {
|
||||
|
||||
/// This function populates `f.manifest` or leaves it `null`.
|
||||
fn loadManifest(f: *Fetch, pkg_root: Cache.Path) RunError!void {
|
||||
const io = f.job_queue.io;
|
||||
const eb = &f.error_bundle;
|
||||
const arena = f.arena.allocator();
|
||||
const manifest_bytes = pkg_root.root_dir.handle.readFileAllocOptions(
|
||||
io,
|
||||
try fs.path.join(arena, &.{ pkg_root.sub_path, Manifest.basename }),
|
||||
arena,
|
||||
.limited(Manifest.max_bytes),
|
||||
@@ -1409,7 +1411,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
|
||||
}
|
||||
}
|
||||
|
||||
try out_dir.deleteTree(".git");
|
||||
try out_dir.deleteTree(io, ".git");
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1461,7 +1463,7 @@ pub fn renameTmpIntoCache(io: Io, cache_dir: Io.Dir, tmp_dir_sub_path: []const u
|
||||
cache_dir.rename(tmp_dir_sub_path, cache_dir, dest_dir_sub_path, io) catch |err| switch (err) {
|
||||
error.FileNotFound => {
|
||||
if (handled_missing_dir) return err;
|
||||
cache_dir.makeDir(dest_dir_sub_path[0..1]) catch |mkd_err| switch (mkd_err) {
|
||||
cache_dir.makeDir(io, dest_dir_sub_path[0..1], .default_dir) catch |mkd_err| switch (mkd_err) {
|
||||
error.PathAlreadyExists => handled_missing_dir = true,
|
||||
else => |e| return e,
|
||||
};
|
||||
@@ -1469,7 +1471,7 @@ pub fn renameTmpIntoCache(io: Io, cache_dir: Io.Dir, tmp_dir_sub_path: []const u
|
||||
},
|
||||
error.PathAlreadyExists, error.AccessDenied => {
|
||||
// Package has been already downloaded and may already be in use on the system.
|
||||
cache_dir.deleteTree(tmp_dir_sub_path) catch {
|
||||
cache_dir.deleteTree(io, tmp_dir_sub_path) catch {
|
||||
// Garbage files leftover in zig-cache/tmp/ is, as they say
|
||||
// on Star Trek, "operating within normal parameters".
|
||||
};
|
||||
|
||||
@@ -253,7 +253,7 @@ pub const Repository = struct {
|
||||
while (try tree_iter.next()) |entry| {
|
||||
switch (entry.type) {
|
||||
.directory => {
|
||||
try dir.makeDir(entry.name);
|
||||
try dir.makeDir(io, entry.name, .default_dir);
|
||||
var subdir = try dir.openDir(io, entry.name, .{});
|
||||
defer subdir.close(io);
|
||||
const sub_path = try std.fs.path.join(repository.odb.allocator, &.{ current_path, entry.name });
|
||||
@@ -296,7 +296,7 @@ pub const Repository = struct {
|
||||
.gitlink => {
|
||||
// Consistent with git archive behavior, create the directory but
|
||||
// do nothing else
|
||||
try dir.makeDir(entry.name);
|
||||
try dir.makeDir(io, entry.name, .default_dir);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7316,6 +7316,7 @@ fn loadManifest(
|
||||
) !struct { Package.Manifest, Ast } {
|
||||
const manifest_bytes = while (true) {
|
||||
break options.dir.readFileAllocOptions(
|
||||
io,
|
||||
Package.Manifest.basename,
|
||||
arena,
|
||||
.limited(Package.Manifest.max_bytes),
|
||||
|
||||
+3
-1
@@ -10,6 +10,7 @@ const ArrayList = std.ArrayList;
|
||||
|
||||
gpa: Allocator,
|
||||
arena: Allocator,
|
||||
io: Io,
|
||||
cases: std.array_list.Managed(Case),
|
||||
|
||||
pub const IncrementalCase = struct {
|
||||
@@ -334,6 +335,7 @@ fn addFromDirInner(
|
||||
current_file: *[]const u8,
|
||||
b: *std.Build,
|
||||
) !void {
|
||||
const io = ctx.io;
|
||||
var it = try iterable_dir.walk(ctx.arena);
|
||||
var filenames: ArrayList([]const u8) = .empty;
|
||||
|
||||
@@ -349,7 +351,7 @@ fn addFromDirInner(
|
||||
current_file.* = filename;
|
||||
|
||||
const max_file_size = 10 * 1024 * 1024;
|
||||
const src = try iterable_dir.readFileAllocOptions(filename, ctx.arena, .limited(max_file_size), .@"1", 0);
|
||||
const src = try iterable_dir.readFileAllocOptions(io, filename, ctx.arena, .limited(max_file_size), .@"1", 0);
|
||||
|
||||
// Parse the manifest
|
||||
var manifest = try TestManifest.parse(ctx.arena, src);
|
||||
|
||||
@@ -5,13 +5,14 @@ const builtin = @import("builtin");
|
||||
|
||||
const std = @import("std");
|
||||
const Io = std.Io;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
pub fn main() !void {
|
||||
if (builtin.target.os.tag == .wasi) return; // Can link, but can't change into tmpDir
|
||||
|
||||
var Allocator = std.heap.DebugAllocator(.{}){};
|
||||
const a = Allocator.allocator();
|
||||
defer std.debug.assert(Allocator.deinit() == .ok);
|
||||
var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
|
||||
const gpa = debug_allocator.allocator();
|
||||
defer std.debug.assert(debug_allocator.deinit() == .ok);
|
||||
|
||||
var threaded: std.Io.Threaded = .init_single_threaded;
|
||||
const io = threaded.io();
|
||||
@@ -24,22 +25,22 @@ pub fn main() !void {
|
||||
// Want to test relative paths, so cd into the tmpdir for these tests
|
||||
try tmp.dir.setAsCwd();
|
||||
|
||||
try test_symlink(a, tmp);
|
||||
try test_symlink(gpa, io, tmp);
|
||||
try test_link(io, tmp);
|
||||
}
|
||||
|
||||
fn test_symlink(a: std.mem.Allocator, tmp: std.testing.TmpDir) !void {
|
||||
fn test_symlink(gpa: Allocator, io: Io, tmp: std.testing.TmpDir) !void {
|
||||
const target_name = "symlink-target";
|
||||
const symlink_name = "symlinker";
|
||||
|
||||
// Create the target file
|
||||
try tmp.dir.writeFile(.{ .sub_path = target_name, .data = "nonsense" });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "nonsense" });
|
||||
|
||||
if (builtin.target.os.tag == .windows) {
|
||||
const wtarget_name = try std.unicode.wtf8ToWtf16LeAllocZ(a, target_name);
|
||||
const wsymlink_name = try std.unicode.wtf8ToWtf16LeAllocZ(a, symlink_name);
|
||||
defer a.free(wtarget_name);
|
||||
defer a.free(wsymlink_name);
|
||||
const wtarget_name = try std.unicode.wtf8ToWtf16LeAllocZ(gpa, target_name);
|
||||
const wsymlink_name = try std.unicode.wtf8ToWtf16LeAllocZ(gpa, symlink_name);
|
||||
defer gpa.free(wtarget_name);
|
||||
defer gpa.free(wsymlink_name);
|
||||
|
||||
std.os.windows.CreateSymbolicLink(tmp.dir.fd, wsymlink_name, wtarget_name, false) catch |err| switch (err) {
|
||||
// Symlink requires admin privileges on windows, so this test can legitimately fail.
|
||||
|
||||
@@ -9,6 +9,9 @@ pub fn main() anyerror!void {
|
||||
defer std.debug.assert(debug_alloc_inst.deinit() == .ok);
|
||||
const gpa = debug_alloc_inst.allocator();
|
||||
|
||||
var threaded: Io.Threaded = .init(gpa);
|
||||
const io = threaded.io();
|
||||
|
||||
var it = try std.process.argsWithAllocator(gpa);
|
||||
defer it.deinit();
|
||||
_ = it.next() orelse unreachable; // skip binary name
|
||||
@@ -58,15 +61,15 @@ pub fn main() anyerror!void {
|
||||
const preamble_len = buf.items.len;
|
||||
|
||||
try buf.appendSlice(gpa, " %*");
|
||||
try tmp.dir.writeFile(.{ .sub_path = "args1.bat", .data = buf.items });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "args1.bat", .data = buf.items });
|
||||
buf.shrinkRetainingCapacity(preamble_len);
|
||||
|
||||
try buf.appendSlice(gpa, " %1 %2 %3 %4 %5 %6 %7 %8 %9");
|
||||
try tmp.dir.writeFile(.{ .sub_path = "args2.bat", .data = buf.items });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "args2.bat", .data = buf.items });
|
||||
buf.shrinkRetainingCapacity(preamble_len);
|
||||
|
||||
try buf.appendSlice(gpa, " \"%~1\" \"%~2\" \"%~3\" \"%~4\" \"%~5\" \"%~6\" \"%~7\" \"%~8\" \"%~9\"");
|
||||
try tmp.dir.writeFile(.{ .sub_path = "args3.bat", .data = buf.items });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "args3.bat", .data = buf.items });
|
||||
buf.shrinkRetainingCapacity(preamble_len);
|
||||
|
||||
var i: u64 = 0;
|
||||
@@ -74,7 +77,7 @@ pub fn main() anyerror!void {
|
||||
const rand_arg = try randomArg(gpa, rand);
|
||||
defer gpa.free(rand_arg);
|
||||
|
||||
try testExec(gpa, &.{rand_arg}, null);
|
||||
try testExec(gpa, io, &.{rand_arg}, null);
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ pub fn main() anyerror!void {
|
||||
defer std.debug.assert(debug_alloc_inst.deinit() == .ok);
|
||||
const gpa = debug_alloc_inst.allocator();
|
||||
|
||||
var threaded: Io.Threaded = .init(gpa);
|
||||
const io = threaded.io();
|
||||
|
||||
var it = try std.process.argsWithAllocator(gpa);
|
||||
defer it.deinit();
|
||||
_ = it.next() orelse unreachable; // skip binary name
|
||||
@@ -32,15 +35,15 @@ pub fn main() anyerror!void {
|
||||
const preamble_len = buf.items.len;
|
||||
|
||||
try buf.appendSlice(gpa, " %*");
|
||||
try tmp.dir.writeFile(.{ .sub_path = "args1.bat", .data = buf.items });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "args1.bat", .data = buf.items });
|
||||
buf.shrinkRetainingCapacity(preamble_len);
|
||||
|
||||
try buf.appendSlice(gpa, " %1 %2 %3 %4 %5 %6 %7 %8 %9");
|
||||
try tmp.dir.writeFile(.{ .sub_path = "args2.bat", .data = buf.items });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "args2.bat", .data = buf.items });
|
||||
buf.shrinkRetainingCapacity(preamble_len);
|
||||
|
||||
try buf.appendSlice(gpa, " \"%~1\" \"%~2\" \"%~3\" \"%~4\" \"%~5\" \"%~6\" \"%~7\" \"%~8\" \"%~9\"");
|
||||
try tmp.dir.writeFile(.{ .sub_path = "args3.bat", .data = buf.items });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "args3.bat", .data = buf.items });
|
||||
buf.shrinkRetainingCapacity(preamble_len);
|
||||
|
||||
// Test cases are from https://github.com/rust-lang/rust/blob/master/tests/ui/std/windows-bat-args.rs
|
||||
|
||||
@@ -65,9 +65,9 @@ pub fn main() anyerror!void {
|
||||
try std.testing.expectError(error.FileNotFound, testExecWithCwd(gpa, io, "hello.exe", "missing_dir", ""));
|
||||
|
||||
// now add a .bat
|
||||
try tmp.dir.writeFile(.{ .sub_path = "hello.bat", .data = "@echo hello from bat" });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "hello.bat", .data = "@echo hello from bat" });
|
||||
// and a .cmd
|
||||
try tmp.dir.writeFile(.{ .sub_path = "hello.cmd", .data = "@echo hello from cmd" });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "hello.cmd", .data = "@echo hello from cmd" });
|
||||
|
||||
// with extension should find the .bat (case insensitive)
|
||||
try testExec(gpa, "heLLo.bat", "hello from bat\r\n");
|
||||
@@ -84,7 +84,7 @@ pub fn main() anyerror!void {
|
||||
// without extension should succeed (case insensitive)
|
||||
try testExec(gpa, "heLLo", "hello from exe\n");
|
||||
|
||||
try tmp.dir.makeDir("something");
|
||||
try tmp.dir.makeDir(io, "something", .default_dir);
|
||||
try renameExe(tmp.dir, "hello", "something/hello.exe");
|
||||
|
||||
const relative_path_no_ext = try std.fs.path.join(gpa, &.{ tmp_relative_path, "something/hello" });
|
||||
@@ -99,7 +99,7 @@ pub fn main() anyerror!void {
|
||||
try testExec(gpa, "heLLo", "hello from bat\r\n");
|
||||
|
||||
// Add a hello.exe that is not a valid executable
|
||||
try tmp.dir.writeFile(.{ .sub_path = "hello.exe", .data = "invalid" });
|
||||
try tmp.dir.writeFile(io, .{ .sub_path = "hello.exe", .data = "invalid" });
|
||||
|
||||
// Trying to execute it with extension will give InvalidExe. This is a special
|
||||
// case for .EXE extensions, where if they ever try to get executed but they are
|
||||
|
||||
+4
-4
@@ -2135,12 +2135,12 @@ pub fn addCliTests(b: *std.Build) *Step {
|
||||
|
||||
var dir = std.Io.Dir.cwd().openDir(io, tmp_path, .{}) catch @panic("unhandled");
|
||||
defer dir.close(io);
|
||||
dir.writeFile(.{ .sub_path = "fmt1.zig", .data = unformatted_code }) catch @panic("unhandled");
|
||||
dir.writeFile(.{ .sub_path = "fmt2.zig", .data = unformatted_code }) catch @panic("unhandled");
|
||||
dir.makeDir("subdir") catch @panic("unhandled");
|
||||
dir.writeFile(io, .{ .sub_path = "fmt1.zig", .data = unformatted_code }) catch @panic("unhandled");
|
||||
dir.writeFile(io, .{ .sub_path = "fmt2.zig", .data = unformatted_code }) catch @panic("unhandled");
|
||||
dir.makeDir(io, "subdir", .default_dir) catch @panic("unhandled");
|
||||
var subdir = dir.openDir(io, "subdir", .{}) catch @panic("unhandled");
|
||||
defer subdir.close(io);
|
||||
subdir.writeFile(.{ .sub_path = "fmt3.zig", .data = unformatted_code }) catch @panic("unhandled");
|
||||
subdir.writeFile(io, .{ .sub_path = "fmt3.zig", .data = unformatted_code }) catch @panic("unhandled");
|
||||
|
||||
// Test zig fmt affecting only the appropriate files.
|
||||
const run1 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "fmt1.zig" });
|
||||
|
||||
Reference in New Issue
Block a user