tiny.sandbox.windows
Defined in tiny.sandbox.
API (3)
Actions
Public operations.
Source
Source: lib/sandbox/src/root.zig:44
zig
pub const windows = @import("windows.zig");Source: lib/sandbox/src/windows.zig
zig
const std = @import("std");const builtin = @import("builtin");const sys = @import("sys");const audit_data = @import("audit.zig");const change = @import("change.zig");const copied = @import("copied.zig");const plan_data = @import("plan.zig");const result_data = @import("result.zig");const Allocator = std.mem.Allocator;const fs_io = sys.fs.debugIo();pub fn available() bool { return builtin.os.tag == .windows;}pub fn audit(plan: plan_data.Plan) audit_data.Audit { return .{ .runner = .windows_staging, .filesystem = .copied, .process = .host, .network = .inherited, .environment = if (plan.environ_map == null) .inherited else .replaced, };}pub fn execute(allocator: Allocator, plan: plan_data.Plan) !result_data.Result { if (!available()) return error.UnsupportedRunner; return try copied.execute(allocator, plan, audit(plan));}test "windows backend is unavailable away from windows" { if (comptime builtin.os.tag == .windows) return error.SkipZigTest; var scratch = std.testing.tmpDir(.{}); defer scratch.cleanup(); const argv = [_][]const u8{ "bash", "-c", ":" }; try std.testing.expectError(error.UnsupportedRunner, execute(std.testing.allocator, .{ .scratch = scratch.dir, .argv = argv[0..], .runner = .windows_staging, .prefix = "windows-unavailable", .max_file_bytes = 1024, }));}test "windows backend keeps Plan Result contract on windows" { if (comptime builtin.os.tag != .windows) return error.SkipZigTest; var source = std.testing.tmpDir(.{}); defer source.cleanup(); var scratch = std.testing.tmpDir(.{}); defer scratch.cleanup(); try source.dir.writeFile(fs_io, .{ .sub_path = "a.txt", .data = "old" }); const argv = [_][]const u8{ "cmd.exe", "/C", "type a.txt > copy.txt" }; var result = try execute(std.testing.allocator, .{ .scratch = scratch.dir, .source = source.dir, .argv = argv[0..], .runner = .windows_staging, .prefix = "windows-contract", .max_file_bytes = 1024, }); defer result.deinit(); try std.testing.expectEqual(audit_data.Runner.windows_staging, result.audit.runner); try std.testing.expectEqual(audit_data.Filesystem.copied, result.audit.filesystem); try std.testing.expectEqual(audit_data.Process.host, result.audit.process); try std.testing.expectEqual(change.Operation.put, result.changes.find("copy.txt").?.operation);}Audit
| Definitions | 4 |
|---|---|
| Public names | 4 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |