| author | |
| committer | |
| log | 8328de24f13e21e325207b19288a143854df50df |
| tree | ef7c9c46f969e31258a4c052c85f5a9ecfc34b80 |
| parent | dd1d15b72aa3bae4b38e2337609758ffb7a7b55a |
41 files changed, 124 insertions(+), 138 deletions(-)
lib/compiler/aro/aro/Compilation.zig+2-2| ... | @@ -1641,7 +1641,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin | ... | @@ -1641,7 +1641,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin |
| 1641 | 1641 | ||
| 1642 | const io = comp.io; | 1642 | const io = comp.io; |
| 1643 | 1643 | ||
| 1644 | const file = try comp.cwd.openFile(path, .{}); | 1644 | const file = try comp.cwd.openFile(io, path, .{}); |
| 1645 | defer file.close(io); | 1645 | defer file.close(io); |
| 1646 | return comp.addSourceFromFile(file, path, kind); | 1646 | return comp.addSourceFromFile(file, path, kind); |
| 1647 | } | 1647 | } |
| ... | @@ -1975,7 +1975,7 @@ fn getPathContents(comp: *Compilation, path: []const u8, limit: Io.Limit) ![]u8 | ... | @@ -1975,7 +1975,7 @@ fn getPathContents(comp: *Compilation, path: []const u8, limit: Io.Limit) ![]u8 |
| 1975 | 1975 | ||
| 1976 | const io = comp.io; | 1976 | const io = comp.io; |
| 1977 | 1977 | ||
| 1978 | const file = try comp.cwd.openFile(path, .{}); | 1978 | const file = try comp.cwd.openFile(io, path, .{}); |
| 1979 | defer file.close(io); | 1979 | defer file.close(io); |
| 1980 | return comp.getFileContents(file, limit); | 1980 | return comp.getFileContents(file, limit); |
| 1981 | } | 1981 | } |
lib/compiler/aro/aro/Driver/Filesystem.zig+1-1| ... | @@ -213,7 +213,7 @@ pub const Filesystem = union(enum) { | ... | @@ -213,7 +213,7 @@ pub const Filesystem = union(enum) { |
| 213 | pub fn readFile(fs: Filesystem, io: Io, path: []const u8, buf: []u8) ?[]const u8 { | 213 | pub fn readFile(fs: Filesystem, io: Io, path: []const u8, buf: []u8) ?[]const u8 { |
| 214 | return switch (fs) { | 214 | return switch (fs) { |
| 215 | .real => |cwd| { | 215 | .real => |cwd| { |
| 216 | const file = cwd.openFile(path, .{}) catch return null; | 216 | const file = cwd.openFile(io, path, .{}) catch return null; |
| 217 | defer file.close(io); | 217 | defer file.close(io); |
| 218 | 218 | ||
| 219 | const bytes_read = file.readAll(buf) catch return null; | 219 | const bytes_read = file.readAll(buf) catch return null; |
lib/compiler/aro/aro/Toolchain.zig+3-3| ... | @@ -524,12 +524,12 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void { | ... | @@ -524,12 +524,12 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void { |
| 524 | /// Otherwise returns a slice of `buf`. If the file is larger than `buf` partial contents are returned | 524 | /// Otherwise returns a slice of `buf`. If the file is larger than `buf` partial contents are returned |
| 525 | pub fn readFile(tc: *const Toolchain, path: []const u8, buf: []u8) ?[]const u8 { | 525 | pub fn readFile(tc: *const Toolchain, path: []const u8, buf: []u8) ?[]const u8 { |
| 526 | const comp = tc.driver.comp; | 526 | const comp = tc.driver.comp; |
| 527 | return comp.cwd.adaptToNewApi().readFile(comp.io, path, buf) catch null; | 527 | return comp.cwd.readFile(comp.io, path, buf) catch null; |
| 528 | } | 528 | } |
| 529 | 529 | ||
| 530 | pub fn exists(tc: *const Toolchain, path: []const u8) bool { | 530 | pub fn exists(tc: *const Toolchain, path: []const u8) bool { |
| 531 | const comp = tc.driver.comp; | 531 | const comp = tc.driver.comp; |
| 532 | comp.cwd.adaptToNewApi().access(comp.io, path, .{}) catch return false; | 532 | comp.cwd.access(comp.io, path, .{}) catch return false; |
| 533 | return true; | 533 | return true; |
| 534 | } | 534 | } |
| 535 | 535 | ||
| ... | @@ -547,7 +547,7 @@ pub fn canExecute(tc: *const Toolchain, path: []const u8) bool { | ... | @@ -547,7 +547,7 @@ pub fn canExecute(tc: *const Toolchain, path: []const u8) bool { |
| 547 | } | 547 | } |
| 548 | 548 | ||
| 549 | const comp = tc.driver.comp; | 549 | const comp = tc.driver.comp; |
| 550 | comp.cwd.adaptToNewApi().access(comp.io, path, .{ .execute = true }) catch return false; | 550 | comp.cwd.access(comp.io, path, .{ .execute = true }) catch return false; |
| 551 | // Todo: ensure path is not a directory | 551 | // Todo: ensure path is not a directory |
| 552 | return true; | 552 | return true; |
| 553 | } | 553 | } |
lib/compiler/objcopy.zig+1-1| ... | @@ -157,7 +157,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void | ... | @@ -157,7 +157,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void |
| 157 | 157 | ||
| 158 | const stat = input_file.stat() catch |err| fatal("failed to stat {s}: {t}", .{ input, err }); | 158 | const stat = input_file.stat() catch |err| fatal("failed to stat {s}: {t}", .{ input, err }); |
| 159 | 159 | ||
| 160 | var in: File.Reader = .initSize(input_file.adaptToNewApi(), io, &input_buffer, stat.size); | 160 | var in: File.Reader = .initSize(input_file, io, &input_buffer, stat.size); |
| 161 | 161 | ||
| 162 | const elf_hdr = std.elf.Header.read(&in.interface) catch |err| switch (err) { | 162 | const elf_hdr = std.elf.Header.read(&in.interface) catch |err| switch (err) { |
| 163 | error.ReadFailed => fatal("unable to read {s}: {t}", .{ input, in.err.? }), | 163 | error.ReadFailed => fatal("unable to read {s}: {t}", .{ input, in.err.? }), |
lib/compiler/std-docs.zig+1-1| ... | @@ -225,7 +225,7 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void { | ... | @@ -225,7 +225,7 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void { |
| 225 | }, | 225 | }, |
| 226 | else => continue, | 226 | else => continue, |
| 227 | } | 227 | } |
| 228 | var file = try entry.dir.openFile(entry.basename, .{}); | 228 | var file = try entry.dir.openFile(io, entry.basename, .{}); |
| 229 | defer file.close(io); | 229 | defer file.close(io); |
| 230 | const stat = try file.stat(); | 230 | const stat = try file.stat(); |
| 231 | var file_reader: std.Io.File.Reader = .{ | 231 | var file_reader: std.Io.File.Reader = .{ |
lib/std/Build/Cache.zig+5-3| ... | @@ -502,6 +502,8 @@ pub const Manifest = struct { | ... | @@ -502,6 +502,8 @@ pub const Manifest = struct { |
| 502 | @memcpy(manifest_file_path[0..self.hex_digest.len], &self.hex_digest); | 502 | @memcpy(manifest_file_path[0..self.hex_digest.len], &self.hex_digest); |
| 503 | manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*; | 503 | manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*; |
| 504 | 504 | ||
| 505 | const io = self.cache.io; | ||
| 506 | |||
| 505 | // We'll try to open the cache with an exclusive lock, but if that would block | 507 | // We'll try to open the cache with an exclusive lock, but if that would block |
| 506 | // and `want_shared_lock` is set, a shared lock might be sufficient, so we'll | 508 | // and `want_shared_lock` is set, a shared lock might be sufficient, so we'll |
| 507 | // open with a shared lock instead. | 509 | // open with a shared lock instead. |
| ... | @@ -517,7 +519,7 @@ pub const Manifest = struct { | ... | @@ -517,7 +519,7 @@ pub const Manifest = struct { |
| 517 | break; | 519 | break; |
| 518 | } else |err| switch (err) { | 520 | } else |err| switch (err) { |
| 519 | error.WouldBlock => { | 521 | error.WouldBlock => { |
| 520 | self.manifest_file = self.cache.manifest_dir.openFile(&manifest_file_path, .{ | 522 | self.manifest_file = self.cache.manifest_dir.openFile(io, &manifest_file_path, .{ |
| 521 | .mode = .read_write, | 523 | .mode = .read_write, |
| 522 | .lock = .shared, | 524 | .lock = .shared, |
| 523 | }) catch |e| { | 525 | }) catch |e| { |
| ... | @@ -757,7 +759,7 @@ pub const Manifest = struct { | ... | @@ -757,7 +759,7 @@ pub const Manifest = struct { |
| 757 | 759 | ||
| 758 | const pp = cache_hash_file.prefixed_path; | 760 | const pp = cache_hash_file.prefixed_path; |
| 759 | const dir = self.cache.prefixes()[pp.prefix].handle; | 761 | const dir = self.cache.prefixes()[pp.prefix].handle; |
| 760 | const this_file = dir.openFile(pp.sub_path, .{ .mode = .read_only }) catch |err| switch (err) { | 762 | const this_file = dir.openFile(io, pp.sub_path, .{ .mode = .read_only }) catch |err| switch (err) { |
| 761 | error.FileNotFound => { | 763 | error.FileNotFound => { |
| 762 | // Every digest before this one has been populated successfully. | 764 | // Every digest before this one has been populated successfully. |
| 763 | return .{ .miss = .{ .file_digests_populated = idx } }; | 765 | return .{ .miss = .{ .file_digests_populated = idx } }; |
| ... | @@ -900,7 +902,7 @@ pub const Manifest = struct { | ... | @@ -900,7 +902,7 @@ pub const Manifest = struct { |
| 900 | } else { | 902 | } else { |
| 901 | const pp = ch_file.prefixed_path; | 903 | const pp = ch_file.prefixed_path; |
| 902 | const dir = self.cache.prefixes()[pp.prefix].handle; | 904 | const dir = self.cache.prefixes()[pp.prefix].handle; |
| 903 | const handle = try dir.openFile(pp.sub_path, .{}); | 905 | const handle = try dir.openFile(io, pp.sub_path, .{}); |
| 904 | defer handle.close(io); | 906 | defer handle.close(io); |
| 905 | return populateFileHashHandle(self, ch_file, handle); | 907 | return populateFileHashHandle(self, ch_file, handle); |
| 906 | } | 908 | } |
lib/std/Build/Cache/Path.zig+2-6| ... | @@ -59,18 +59,14 @@ pub fn joinStringZ(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Erro | ... | @@ -59,18 +59,14 @@ pub fn joinStringZ(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Erro |
| 59 | return p.root_dir.joinZ(gpa, parts); | 59 | return p.root_dir.joinZ(gpa, parts); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | pub fn openFile( | 62 | pub fn openFile(p: Path, io: Io, sub_path: []const u8, flags: Io.File.OpenFlags) !Io.File { |
| 63 | p: Path, | ||
| 64 | sub_path: []const u8, | ||
| 65 | flags: Io.File.OpenFlags, | ||
| 66 | ) !Io.File { | ||
| 67 | var buf: [fs.max_path_bytes]u8 = undefined; | 63 | var buf: [fs.max_path_bytes]u8 = undefined; |
| 68 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { | 64 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 69 | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ | 65 | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 70 | p.sub_path, sub_path, | 66 | p.sub_path, sub_path, |
| 71 | }) catch return error.NameTooLong; | 67 | }) catch return error.NameTooLong; |
| 72 | }; | 68 | }; |
| 73 | return p.root_dir.handle.openFile(joined_path, flags); | 69 | return p.root_dir.handle.openFile(io, joined_path, flags); |
| 74 | } | 70 | } |
| 75 | 71 | ||
| 76 | pub fn openDir( | 72 | pub fn openDir( |
lib/std/Build/Fuzz.zig+2-2| ... | @@ -405,7 +405,7 @@ fn prepareTables(fuzz: *Fuzz, run_step: *Step.Run, coverage_id: u64) error{ OutO | ... | @@ -405,7 +405,7 @@ fn prepareTables(fuzz: *Fuzz, run_step: *Step.Run, coverage_id: u64) error{ OutO |
| 405 | .root_dir = run_step.step.owner.cache_root, | 405 | .root_dir = run_step.step.owner.cache_root, |
| 406 | .sub_path = "v/" ++ std.fmt.hex(coverage_id), | 406 | .sub_path = "v/" ++ std.fmt.hex(coverage_id), |
| 407 | }; | 407 | }; |
| 408 | var coverage_file = coverage_file_path.root_dir.handle.openFile(coverage_file_path.sub_path, .{}) catch |err| { | 408 | var coverage_file = coverage_file_path.root_dir.handle.openFile(io, coverage_file_path.sub_path, .{}) catch |err| { |
| 409 | log.err("step '{s}': failed to load coverage file '{f}': {t}", .{ | 409 | log.err("step '{s}': failed to load coverage file '{f}': {t}", .{ |
| 410 | run_step.step.name, coverage_file_path, err, | 410 | run_step.step.name, coverage_file_path, err, |
| 411 | }); | 411 | }); |
| ... | @@ -528,7 +528,7 @@ pub fn waitAndPrintReport(fuzz: *Fuzz) void { | ... | @@ -528,7 +528,7 @@ pub fn waitAndPrintReport(fuzz: *Fuzz) void { |
| 528 | .root_dir = cov.run.step.owner.cache_root, | 528 | .root_dir = cov.run.step.owner.cache_root, |
| 529 | .sub_path = "v/" ++ std.fmt.hex(cov.id), | 529 | .sub_path = "v/" ++ std.fmt.hex(cov.id), |
| 530 | }; | 530 | }; |
| 531 | var coverage_file = coverage_file_path.root_dir.handle.openFile(coverage_file_path.sub_path, .{}) catch |err| { | 531 | var coverage_file = coverage_file_path.root_dir.handle.openFile(io, coverage_file_path.sub_path, .{}) catch |err| { |
| 532 | fatal("step '{s}': failed to load coverage file '{f}': {t}", .{ | 532 | fatal("step '{s}': failed to load coverage file '{f}': {t}", .{ |
| 533 | cov.run.step.name, coverage_file_path, err, | 533 | cov.run.step.name, coverage_file_path, err, |
| 534 | }); | 534 | }); |
lib/std/Build/Step/Run.zig+3-3| ... | @@ -846,7 +846,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { | ... | @@ -846,7 +846,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 846 | errdefer result.deinit(); | 846 | errdefer result.deinit(); |
| 847 | result.writer.writeAll(file_plp.prefix) catch return error.OutOfMemory; | 847 | result.writer.writeAll(file_plp.prefix) catch return error.OutOfMemory; |
| 848 | 848 | ||
| 849 | const file = file_path.root_dir.handle.openFile(file_path.subPathOrDot(), .{}) catch |err| { | 849 | const file = file_path.root_dir.handle.openFile(io, file_path.subPathOrDot(), .{}) catch |err| { |
| 850 | return step.fail( | 850 | return step.fail( |
| 851 | "unable to open input file '{f}': {t}", | 851 | "unable to open input file '{f}': {t}", |
| 852 | .{ file_path, err }, | 852 | .{ file_path, err }, |
| ... | @@ -1111,7 +1111,7 @@ pub fn rerunInFuzzMode( | ... | @@ -1111,7 +1111,7 @@ pub fn rerunInFuzzMode( |
| 1111 | errdefer result.deinit(); | 1111 | errdefer result.deinit(); |
| 1112 | result.writer.writeAll(file_plp.prefix) catch return error.OutOfMemory; | 1112 | result.writer.writeAll(file_plp.prefix) catch return error.OutOfMemory; |
| 1113 | 1113 | ||
| 1114 | const file = try file_path.root_dir.handle.openFile(file_path.subPathOrDot(), .{}); | 1114 | const file = try file_path.root_dir.handle.openFile(io, file_path.subPathOrDot(), .{}); |
| 1115 | defer file.close(io); | 1115 | defer file.close(io); |
| 1116 | 1116 | ||
| 1117 | var buf: [1024]u8 = undefined; | 1117 | var buf: [1024]u8 = undefined; |
| ... | @@ -2185,7 +2185,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult { | ... | @@ -2185,7 +2185,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult { |
| 2185 | }, | 2185 | }, |
| 2186 | .lazy_path => |lazy_path| { | 2186 | .lazy_path => |lazy_path| { |
| 2187 | const path = lazy_path.getPath3(b, &run.step); | 2187 | const path = lazy_path.getPath3(b, &run.step); |
| 2188 | const file = path.root_dir.handle.openFile(path.subPathOrDot(), .{}) catch |err| { | 2188 | const file = path.root_dir.handle.openFile(io, path.subPathOrDot(), .{}) catch |err| { |
| 2189 | return run.step.fail("unable to open stdin file: {s}", .{@errorName(err)}); | 2189 | return run.step.fail("unable to open stdin file: {s}", .{@errorName(err)}); |
| 2190 | }; | 2190 | }; |
| 2191 | defer file.close(io); | 2191 | defer file.close(io); |
lib/std/Build/Step/UpdateSourceFiles.zig+1-1| ... | @@ -99,7 +99,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { | ... | @@ -99,7 +99,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 99 | .cwd(), | 99 | .cwd(), |
| 100 | io, | 100 | io, |
| 101 | source_path, | 101 | source_path, |
| 102 | b.build_root.handle.adaptToNewApi(), | 102 | b.build_root.handle, |
| 103 | output_source_file.sub_path, | 103 | output_source_file.sub_path, |
| 104 | .{}, | 104 | .{}, |
| 105 | ) catch |err| { | 105 | ) catch |err| { |
lib/std/Build/Step/WriteFile.zig+3-3| ... | @@ -284,7 +284,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { | ... | @@ -284,7 +284,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 284 | }, | 284 | }, |
| 285 | .copy => |file_source| { | 285 | .copy => |file_source| { |
| 286 | const source_path = file_source.getPath2(b, step); | 286 | const source_path = file_source.getPath2(b, step); |
| 287 | const prev_status = Io.Dir.updateFile(.cwd(), io, source_path, cache_dir.adaptToNewApi(), file.sub_path, .{}) catch |err| { | 287 | const prev_status = Io.Dir.updateFile(.cwd(), io, source_path, cache_dir, file.sub_path, .{}) catch |err| { |
| 288 | return step.fail("unable to update file from '{s}' to '{f}{s}{c}{s}': {t}", .{ | 288 | return step.fail("unable to update file from '{s}' to '{f}{s}{c}{s}': {t}", .{ |
| 289 | source_path, b.cache_root, cache_path, fs.path.sep, file.sub_path, err, | 289 | source_path, b.cache_root, cache_path, fs.path.sep, file.sub_path, err, |
| 290 | }); | 290 | }); |
| ... | @@ -321,10 +321,10 @@ fn make(step: *Step, options: Step.MakeOptions) !void { | ... | @@ -321,10 +321,10 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 321 | .directory => try cache_dir.makePath(dest_path), | 321 | .directory => try cache_dir.makePath(dest_path), |
| 322 | .file => { | 322 | .file => { |
| 323 | const prev_status = Io.Dir.updateFile( | 323 | const prev_status = Io.Dir.updateFile( |
| 324 | src_entry_path.root_dir.handle.adaptToNewApi(), | 324 | src_entry_path.root_dir.handle, |
| 325 | io, | 325 | io, |
| 326 | src_entry_path.sub_path, | 326 | src_entry_path.sub_path, |
| 327 | cache_dir.adaptToNewApi(), | 327 | cache_dir, |
| 328 | dest_path, | 328 | dest_path, |
| 329 | .{}, | 329 | .{}, |
| 330 | ) catch |err| { | 330 | ) catch |err| { |
lib/std/Build/WebServer.zig+2-2| ... | @@ -504,14 +504,14 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons | ... | @@ -504,14 +504,14 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons |
| 504 | var archiver: std.tar.Writer = .{ .underlying_writer = &response.writer }; | 504 | var archiver: std.tar.Writer = .{ .underlying_writer = &response.writer }; |
| 505 | 505 | ||
| 506 | for (paths) |path| { | 506 | for (paths) |path| { |
| 507 | var file = path.root_dir.handle.openFile(path.sub_path, .{}) catch |err| { | 507 | var file = path.root_dir.handle.openFile(io, path.sub_path, .{}) catch |err| { |
| 508 | log.err("failed to open '{f}': {s}", .{ path, @errorName(err) }); | 508 | log.err("failed to open '{f}': {s}", .{ path, @errorName(err) }); |
| 509 | continue; | 509 | continue; |
| 510 | }; | 510 | }; |
| 511 | defer file.close(io); | 511 | defer file.close(io); |
| 512 | const stat = try file.stat(); | 512 | const stat = try file.stat(); |
| 513 | var read_buffer: [1024]u8 = undefined; | 513 | var read_buffer: [1024]u8 = undefined; |
| 514 | var file_reader: Io.File.Reader = .initSize(file.adaptToNewApi(), io, &read_buffer, stat.size); | 514 | var file_reader: Io.File.Reader = .initSize(file, io, &read_buffer, stat.size); |
| 515 | 515 | ||
| 516 | // TODO: this logic is completely bogus -- obviously so, because `path.root_dir.path` can | 516 | // TODO: this logic is completely bogus -- obviously so, because `path.root_dir.path` can |
| 517 | // be cwd-relative. This is also related to why linkification doesn't work in the fuzzer UI: | 517 | // be cwd-relative. This is also related to why linkification doesn't work in the fuzzer UI: |
lib/std/Io/Dir.zig+1-1| ... | @@ -481,7 +481,7 @@ pub fn updateFile( | ... | @@ -481,7 +481,7 @@ pub fn updateFile( |
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | var buffer: [1000]u8 = undefined; // Used only when direct fd-to-fd is not available. | 483 | var buffer: [1000]u8 = undefined; // Used only when direct fd-to-fd is not available. |
| 484 | var atomic_file = try Dir.atomicFile(.adaptFromNewApi(dest_dir), dest_path, .{ | 484 | var atomic_file = try Dir.atomicFile(dest_dir, dest_path, .{ |
| 485 | .permissions = actual_permissions, | 485 | .permissions = actual_permissions, |
| 486 | .write_buffer = &buffer, | 486 | .write_buffer = &buffer, |
| 487 | }); | 487 | }); |
lib/std/Io/test.zig+1-1| ... | @@ -44,7 +44,7 @@ test "write a file, read it, then delete it" { | ... | @@ -44,7 +44,7 @@ test "write a file, read it, then delete it" { |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | { | 46 | { |
| 47 | var file = try tmp.dir.openFile(tmp_file_name, .{}); | 47 | var file = try tmp.dir.openFile(io, tmp_file_name, .{}); |
| 48 | defer file.close(io); | 48 | defer file.close(io); |
| 49 | 49 | ||
| 50 | const file_size = try file.getEndPos(); | 50 | const file_size = try file.getEndPos(); |
lib/std/Thread.zig+2-2| ... | @@ -208,7 +208,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void { | ... | @@ -208,7 +208,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void { |
| 208 | var buf: [32]u8 = undefined; | 208 | var buf: [32]u8 = undefined; |
| 209 | const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()}); | 209 | const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()}); |
| 210 | 210 | ||
| 211 | const file = try std.fs.cwd().openFile(path, .{ .mode = .write_only }); | 211 | const file = try std.fs.cwd().openFile(io, path, .{ .mode = .write_only }); |
| 212 | defer file.close(io); | 212 | defer file.close(io); |
| 213 | 213 | ||
| 214 | try file.writeAll(name); | 214 | try file.writeAll(name); |
| ... | @@ -325,7 +325,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co | ... | @@ -325,7 +325,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 325 | var threaded: std.Io.Threaded = .init_single_threaded; | 325 | var threaded: std.Io.Threaded = .init_single_threaded; |
| 326 | const io = threaded.ioBasic(); | 326 | const io = threaded.ioBasic(); |
| 327 | 327 | ||
| 328 | const file = try std.fs.cwd().openFile(path, .{}); | 328 | const file = try std.fs.cwd().openFile(io, path, .{}); |
| 329 | defer file.close(io); | 329 | defer file.close(io); |
| 330 | 330 | ||
| 331 | var file_reader = file.readerStreaming(io, &.{}); | 331 | var file_reader = file.readerStreaming(io, &.{}); |
lib/std/crypto/Certificate/Bundle.zig+1-1| ... | @@ -208,7 +208,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, i | ... | @@ -208,7 +208,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, i |
| 208 | else => continue, | 208 | else => continue, |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | try addCertsFromFilePath(cb, gpa, io, now, iterable_dir.adaptToNewApi(), entry.name); | 211 | try addCertsFromFilePath(cb, gpa, io, now, iterable_dir, entry.name); |
| 212 | } | 212 | } |
| 213 | } | 213 | } |
| 214 | 214 |
lib/std/debug/ElfFile.zig+1-1| ... | @@ -375,7 +375,7 @@ fn loadSeparateDebugFile( | ... | @@ -375,7 +375,7 @@ fn loadSeparateDebugFile( |
| 375 | args: anytype, | 375 | args: anytype, |
| 376 | ) Allocator.Error!?[]align(std.heap.page_size_min) const u8 { | 376 | ) Allocator.Error!?[]align(std.heap.page_size_min) const u8 { |
| 377 | const path = try std.fmt.allocPrint(arena, fmt, args); | 377 | const path = try std.fmt.allocPrint(arena, fmt, args); |
| 378 | const elf_file = std.fs.cwd().openFile(path, .{}) catch return null; | 378 | const elf_file = std.fs.cwd().openFile(io, path, .{}) catch return null; |
| 379 | defer elf_file.close(io); | 379 | defer elf_file.close(io); |
| 380 | 380 | ||
| 381 | const result = loadInner(arena, elf_file, opt_crc) catch |err| switch (err) { | 381 | const result = loadInner(arena, elf_file, opt_crc) catch |err| switch (err) { |
lib/std/debug/Info.zig+1-1| ... | @@ -39,7 +39,7 @@ pub fn load( | ... | @@ -39,7 +39,7 @@ pub fn load( |
| 39 | ) LoadError!Info { | 39 | ) LoadError!Info { |
| 40 | switch (format) { | 40 | switch (format) { |
| 41 | .elf => { | 41 | .elf => { |
| 42 | var file = try path.root_dir.handle.openFile(path.sub_path, .{}); | 42 | var file = try path.root_dir.handle.openFile(io, path.sub_path, .{}); |
| 43 | defer file.close(io); | 43 | defer file.close(io); |
| 44 | 44 | ||
| 45 | var elf_file: ElfFile = try .load(gpa, file, null, &.none); | 45 | var elf_file: ElfFile = try .load(gpa, file, null, &.none); |
lib/std/debug/MachOFile.zig+1-1| ... | @@ -512,7 +512,7 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile { | ... | @@ -512,7 +512,7 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile { |
| 512 | 512 | ||
| 513 | /// Uses `mmap` to map the file at `path` into memory. | 513 | /// Uses `mmap` to map the file at `path` into memory. |
| 514 | fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 { | 514 | fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 { |
| 515 | const file = std.fs.cwd().openFile(path, .{}) catch |err| switch (err) { | 515 | const file = std.fs.cwd().openFile(io, path, .{}) catch |err| switch (err) { |
| 516 | error.FileNotFound => return error.MissingDebugInfo, | 516 | error.FileNotFound => return error.MissingDebugInfo, |
| 517 | else => return error.ReadFailed, | 517 | else => return error.ReadFailed, |
| 518 | }; | 518 | }; |
lib/std/debug/SelfInfo/Elf.zig+2-2| ... | @@ -325,7 +325,7 @@ const Module = struct { | ... | @@ -325,7 +325,7 @@ const Module = struct { |
| 325 | } | 325 | } |
| 326 | fn loadElf(mod: *Module, gpa: Allocator, io: Io) Error!LoadedElf { | 326 | fn loadElf(mod: *Module, gpa: Allocator, io: Io) Error!LoadedElf { |
| 327 | const load_result = if (mod.name.len > 0) res: { | 327 | const load_result = if (mod.name.len > 0) res: { |
| 328 | var file = std.fs.cwd().openFile(mod.name, .{}) catch return error.MissingDebugInfo; | 328 | var file = std.fs.cwd().openFile(io, mod.name, .{}) catch return error.MissingDebugInfo; |
| 329 | defer file.close(io); | 329 | defer file.close(io); |
| 330 | break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(mod.name)); | 330 | break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(mod.name)); |
| 331 | } else res: { | 331 | } else res: { |
| ... | @@ -334,7 +334,7 @@ const Module = struct { | ... | @@ -334,7 +334,7 @@ const Module = struct { |
| 334 | else => return error.ReadFailed, | 334 | else => return error.ReadFailed, |
| 335 | }; | 335 | }; |
| 336 | defer gpa.free(path); | 336 | defer gpa.free(path); |
| 337 | var file = std.fs.cwd().openFile(path, .{}) catch return error.MissingDebugInfo; | 337 | var file = std.fs.cwd().openFile(io, path, .{}) catch return error.MissingDebugInfo; |
| 338 | defer file.close(io); | 338 | defer file.close(io); |
| 339 | break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(path)); | 339 | break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(path)); |
| 340 | }; | 340 | }; |
lib/std/debug/SelfInfo/MachO.zig+1-1| ... | @@ -616,7 +616,7 @@ test { | ... | @@ -616,7 +616,7 @@ test { |
| 616 | 616 | ||
| 617 | /// Uses `mmap` to map the file at `path` into memory. | 617 | /// Uses `mmap` to map the file at `path` into memory. |
| 618 | fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 { | 618 | fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 { |
| 619 | const file = std.fs.cwd().openFile(path, .{}) catch |err| switch (err) { | 619 | const file = std.fs.cwd().openFile(io, path, .{}) catch |err| switch (err) { |
| 620 | error.FileNotFound => return error.MissingDebugInfo, | 620 | error.FileNotFound => return error.MissingDebugInfo, |
| 621 | else => return error.ReadFailed, | 621 | else => return error.ReadFailed, |
| 622 | }; | 622 | }; |
lib/std/debug/SelfInfo/Windows.zig+3-3| ... | @@ -387,7 +387,7 @@ const Module = struct { | ... | @@ -387,7 +387,7 @@ const Module = struct { |
| 387 | const section_view = section_view_ptr.?[0..coff_len]; | 387 | const section_view = section_view_ptr.?[0..coff_len]; |
| 388 | coff_obj = coff.Coff.init(section_view, false) catch return error.InvalidDebugInfo; | 388 | coff_obj = coff.Coff.init(section_view, false) catch return error.InvalidDebugInfo; |
| 389 | break :mapped .{ | 389 | break :mapped .{ |
| 390 | .file = .adaptFromNewApi(coff_file), | 390 | .file = coff_file, |
| 391 | .section_handle = section_handle, | 391 | .section_handle = section_handle, |
| 392 | .section_view = section_view, | 392 | .section_view = section_view, |
| 393 | }; | 393 | }; |
| ... | @@ -432,7 +432,7 @@ const Module = struct { | ... | @@ -432,7 +432,7 @@ const Module = struct { |
| 432 | break :pdb null; | 432 | break :pdb null; |
| 433 | }; | 433 | }; |
| 434 | const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: { | 434 | const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: { |
| 435 | break :res std.fs.cwd().openFile(path, .{}); | 435 | break :res std.fs.cwd().openFile(io, path, .{}); |
| 436 | } else res: { | 436 | } else res: { |
| 437 | const self_dir = fs.selfExeDirPathAlloc(gpa) catch |err| switch (err) { | 437 | const self_dir = fs.selfExeDirPathAlloc(gpa) catch |err| switch (err) { |
| 438 | error.OutOfMemory, error.Unexpected => |e| return e, | 438 | error.OutOfMemory, error.Unexpected => |e| return e, |
| ... | @@ -441,7 +441,7 @@ const Module = struct { | ... | @@ -441,7 +441,7 @@ const Module = struct { |
| 441 | defer gpa.free(self_dir); | 441 | defer gpa.free(self_dir); |
| 442 | const abs_path = try fs.path.join(gpa, &.{ self_dir, path }); | 442 | const abs_path = try fs.path.join(gpa, &.{ self_dir, path }); |
| 443 | defer gpa.free(abs_path); | 443 | defer gpa.free(abs_path); |
| 444 | break :res std.fs.cwd().openFile(abs_path, .{}); | 444 | break :res std.fs.cwd().openFile(io, abs_path, .{}); |
| 445 | }; | 445 | }; |
| 446 | const pdb_file = pdb_file_open_result catch |err| switch (err) { | 446 | const pdb_file = pdb_file_open_result catch |err| switch (err) { |
| 447 | error.FileNotFound, error.IsDir => break :pdb null, | 447 | error.FileNotFound, error.IsDir => break :pdb null, |
lib/std/fs.zig-17| ... | @@ -287,23 +287,6 @@ pub fn symLinkAbsoluteW( | ... | @@ -287,23 +287,6 @@ pub fn symLinkAbsoluteW( |
| 287 | return windows.CreateSymbolicLink(null, mem.span(sym_link_path_w), mem.span(target_path_w), flags.is_directory); | 287 | return windows.CreateSymbolicLink(null, mem.span(sym_link_path_w), mem.span(target_path_w), flags.is_directory); |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | pub const OpenSelfExeError = Io.File.OpenSelfExeError; | ||
| 291 | |||
| 292 | /// Deprecated in favor of `Io.File.openSelfExe`. | ||
| 293 | pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File { | ||
| 294 | if (native_os == .linux or native_os == .serenity or native_os == .windows) { | ||
| 295 | var threaded: Io.Threaded = .init_single_threaded; | ||
| 296 | const io = threaded.ioBasic(); | ||
| 297 | return .adaptFromNewApi(try Io.File.openSelfExe(io, flags)); | ||
| 298 | } | ||
| 299 | // Use of max_path_bytes here is valid as the resulting path is immediately | ||
| 300 | // opened with no modification. | ||
| 301 | var buf: [max_path_bytes]u8 = undefined; | ||
| 302 | const self_exe_path = try selfExePath(&buf); | ||
| 303 | buf[self_exe_path.len] = 0; | ||
| 304 | return openFileAbsolute(buf[0..self_exe_path.len :0], flags); | ||
| 305 | } | ||
| 306 | |||
| 307 | // This is `posix.ReadLinkError || posix.RealPathError` with impossible errors excluded | 290 | // This is `posix.ReadLinkError || posix.RealPathError` with impossible errors excluded |
| 308 | pub const SelfExePathError = error{ | 291 | pub const SelfExePathError = error{ |
| 309 | FileNotFound, | 292 | FileNotFound, |
lib/std/fs/test.zig+23-23| ... | @@ -855,7 +855,7 @@ test "directory operations on files" { | ... | @@ -855,7 +855,7 @@ test "directory operations on files" { |
| 855 | } | 855 | } |
| 856 | 856 | ||
| 857 | // ensure the file still exists and is a file as a sanity check | 857 | // ensure the file still exists and is a file as a sanity check |
| 858 | file = try ctx.dir.openFile(test_file_name, .{}); | 858 | file = try ctx.dir.openFile(io, test_file_name, .{}); |
| 859 | const stat = try file.stat(); | 859 | const stat = try file.stat(); |
| 860 | try testing.expectEqual(File.Kind.file, stat.kind); | 860 | try testing.expectEqual(File.Kind.file, stat.kind); |
| 861 | file.close(io); | 861 | file.close(io); |
| ... | @@ -895,12 +895,12 @@ test "file operations on directories" { | ... | @@ -895,12 +895,12 @@ test "file operations on directories" { |
| 895 | 895 | ||
| 896 | if (native_os == .wasi and builtin.link_libc) { | 896 | if (native_os == .wasi and builtin.link_libc) { |
| 897 | // wasmtime unexpectedly succeeds here, see https://github.com/ziglang/zig/issues/20747 | 897 | // wasmtime unexpectedly succeeds here, see https://github.com/ziglang/zig/issues/20747 |
| 898 | const handle = try ctx.dir.openFile(test_dir_name, .{ .mode = .read_write }); | 898 | const handle = try ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write }); |
| 899 | handle.close(io); | 899 | handle.close(io); |
| 900 | } else { | 900 | } else { |
| 901 | // Note: The `.mode = .read_write` is necessary to ensure the error occurs on all platforms. | 901 | // Note: The `.mode = .read_write` is necessary to ensure the error occurs on all platforms. |
| 902 | // TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732 | 902 | // TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732 |
| 903 | try testing.expectError(error.IsDir, ctx.dir.openFile(test_dir_name, .{ .mode = .read_write })); | 903 | try testing.expectError(error.IsDir, ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write })); |
| 904 | } | 904 | } |
| 905 | 905 | ||
| 906 | if (ctx.path_type == .absolute and comptime PathType.absolute.isSupported(builtin.os)) { | 906 | if (ctx.path_type == .absolute and comptime PathType.absolute.isSupported(builtin.os)) { |
| ... | @@ -973,8 +973,8 @@ test "Dir.rename files" { | ... | @@ -973,8 +973,8 @@ test "Dir.rename files" { |
| 973 | try ctx.dir.rename(test_file_name, renamed_test_file_name); | 973 | try ctx.dir.rename(test_file_name, renamed_test_file_name); |
| 974 | 974 | ||
| 975 | // Ensure the file was renamed | 975 | // Ensure the file was renamed |
| 976 | try testing.expectError(error.FileNotFound, ctx.dir.openFile(test_file_name, .{})); | 976 | try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, test_file_name, .{})); |
| 977 | file = try ctx.dir.openFile(renamed_test_file_name, .{}); | 977 | file = try ctx.dir.openFile(io, renamed_test_file_name, .{}); |
| 978 | file.close(io); | 978 | file.close(io); |
| 979 | 979 | ||
| 980 | // Rename to self succeeds | 980 | // Rename to self succeeds |
| ... | @@ -986,8 +986,8 @@ test "Dir.rename files" { | ... | @@ -986,8 +986,8 @@ test "Dir.rename files" { |
| 986 | existing_file.close(io); | 986 | existing_file.close(io); |
| 987 | try ctx.dir.rename(renamed_test_file_name, existing_file_path); | 987 | try ctx.dir.rename(renamed_test_file_name, existing_file_path); |
| 988 | 988 | ||
| 989 | try testing.expectError(error.FileNotFound, ctx.dir.openFile(renamed_test_file_name, .{})); | 989 | try testing.expectError(error.FileNotFound, ctx.dir.openFile(io, renamed_test_file_name, .{})); |
| 990 | file = try ctx.dir.openFile(existing_file_path, .{}); | 990 | file = try ctx.dir.openFile(io, existing_file_path, .{}); |
| 991 | file.close(io); | 991 | file.close(io); |
| 992 | } | 992 | } |
| 993 | }.impl); | 993 | }.impl); |
| ... | @@ -1026,7 +1026,7 @@ test "Dir.rename directories" { | ... | @@ -1026,7 +1026,7 @@ test "Dir.rename directories" { |
| 1026 | // Ensure the directory was renamed and the file still exists in it | 1026 | // Ensure the directory was renamed and the file still exists in it |
| 1027 | try testing.expectError(error.FileNotFound, ctx.dir.openDir(test_dir_renamed_path, .{})); | 1027 | try testing.expectError(error.FileNotFound, ctx.dir.openDir(test_dir_renamed_path, .{})); |
| 1028 | dir = try ctx.dir.openDir(test_dir_renamed_again_path, .{}); | 1028 | dir = try ctx.dir.openDir(test_dir_renamed_again_path, .{}); |
| 1029 | file = try dir.openFile("test_file", .{}); | 1029 | file = try dir.openFile(io, "test_file", .{}); |
| 1030 | file.close(io); | 1030 | file.close(io); |
| 1031 | dir.close(io); | 1031 | dir.close(io); |
| 1032 | } | 1032 | } |
| ... | @@ -1119,8 +1119,8 @@ test "rename" { | ... | @@ -1119,8 +1119,8 @@ test "rename" { |
| 1119 | try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name); | 1119 | try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name); |
| 1120 | 1120 | ||
| 1121 | // ensure the file was renamed | 1121 | // ensure the file was renamed |
| 1122 | try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{})); | 1122 | try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(io, test_file_name, .{})); |
| 1123 | file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{}); | 1123 | file = try tmp_dir2.dir.openFile(io, renamed_test_file_name, .{}); |
| 1124 | file.close(io); | 1124 | file.close(io); |
| 1125 | } | 1125 | } |
| 1126 | 1126 | ||
| ... | @@ -1156,8 +1156,8 @@ test "renameAbsolute" { | ... | @@ -1156,8 +1156,8 @@ test "renameAbsolute" { |
| 1156 | ); | 1156 | ); |
| 1157 | 1157 | ||
| 1158 | // ensure the file was renamed | 1158 | // ensure the file was renamed |
| 1159 | try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{})); | 1159 | try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(io, test_file_name, .{})); |
| 1160 | file = try tmp_dir.dir.openFile(renamed_test_file_name, .{}); | 1160 | file = try tmp_dir.dir.openFile(io, renamed_test_file_name, .{}); |
| 1161 | const stat = try file.stat(); | 1161 | const stat = try file.stat(); |
| 1162 | try testing.expectEqual(File.Kind.file, stat.kind); | 1162 | try testing.expectEqual(File.Kind.file, stat.kind); |
| 1163 | file.close(io); | 1163 | file.close(io); |
| ... | @@ -1512,7 +1512,7 @@ test "setEndPos" { | ... | @@ -1512,7 +1512,7 @@ test "setEndPos" { |
| 1512 | 1512 | ||
| 1513 | const file_name = "afile.txt"; | 1513 | const file_name = "afile.txt"; |
| 1514 | try tmp.dir.writeFile(.{ .sub_path = file_name, .data = "ninebytes" }); | 1514 | try tmp.dir.writeFile(.{ .sub_path = file_name, .data = "ninebytes" }); |
| 1515 | const f = try tmp.dir.openFile(file_name, .{ .mode = .read_write }); | 1515 | const f = try tmp.dir.openFile(io, file_name, .{ .mode = .read_write }); |
| 1516 | defer f.close(io); | 1516 | defer f.close(io); |
| 1517 | 1517 | ||
| 1518 | const initial_size = try f.getEndPos(); | 1518 | const initial_size = try f.getEndPos(); |
| ... | @@ -1856,7 +1856,7 @@ test "read from locked file" { | ... | @@ -1856,7 +1856,7 @@ test "read from locked file" { |
| 1856 | .lock = .exclusive, | 1856 | .lock = .exclusive, |
| 1857 | }); | 1857 | }); |
| 1858 | defer f.close(io); | 1858 | defer f.close(io); |
| 1859 | const f2 = try ctx.dir.openFile(filename, .{}); | 1859 | const f2 = try ctx.dir.openFile(io, filename, .{}); |
| 1860 | defer f2.close(io); | 1860 | defer f2.close(io); |
| 1861 | var buffer: [1]u8 = undefined; | 1861 | var buffer: [1]u8 = undefined; |
| 1862 | if (builtin.os.tag == .windows) { | 1862 | if (builtin.os.tag == .windows) { |
| ... | @@ -2041,12 +2041,12 @@ test "'.' and '..' in Io.Dir functions" { | ... | @@ -2041,12 +2041,12 @@ test "'.' and '..' in Io.Dir functions" { |
| 2041 | 2041 | ||
| 2042 | try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{}); | 2042 | try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{}); |
| 2043 | try ctx.dir.rename(copy_path, rename_path); | 2043 | try ctx.dir.rename(copy_path, rename_path); |
| 2044 | const renamed_file = try ctx.dir.openFile(rename_path, .{}); | 2044 | const renamed_file = try ctx.dir.openFile(io, rename_path, .{}); |
| 2045 | renamed_file.close(io); | 2045 | renamed_file.close(io); |
| 2046 | try ctx.dir.deleteFile(rename_path); | 2046 | try ctx.dir.deleteFile(rename_path); |
| 2047 | 2047 | ||
| 2048 | try ctx.dir.writeFile(.{ .sub_path = update_path, .data = "something" }); | 2048 | try ctx.dir.writeFile(.{ .sub_path = update_path, .data = "something" }); |
| 2049 | var dir = ctx.dir.adaptToNewApi(); | 2049 | var dir = ctx.dir; |
| 2050 | const prev_status = try dir.updateFile(io, file_path, dir, update_path, .{}); | 2050 | const prev_status = try dir.updateFile(io, file_path, dir, update_path, .{}); |
| 2051 | try testing.expectEqual(Io.Dir.PrevStatus.stale, prev_status); | 2051 | try testing.expectEqual(Io.Dir.PrevStatus.stale, prev_status); |
| 2052 | 2052 | ||
| ... | @@ -2186,7 +2186,7 @@ test "invalid UTF-8/WTF-8 paths" { | ... | @@ -2186,7 +2186,7 @@ test "invalid UTF-8/WTF-8 paths" { |
| 2186 | 2186 | ||
| 2187 | try testing.expectError(expected_err, ctx.dir.access(invalid_path, .{})); | 2187 | try testing.expectError(expected_err, ctx.dir.access(invalid_path, .{})); |
| 2188 | 2188 | ||
| 2189 | var dir = ctx.dir.adaptToNewApi(); | 2189 | var dir = ctx.dir; |
| 2190 | try testing.expectError(expected_err, dir.updateFile(io, invalid_path, dir, invalid_path, .{})); | 2190 | try testing.expectError(expected_err, dir.updateFile(io, invalid_path, dir, invalid_path, .{})); |
| 2191 | try testing.expectError(expected_err, ctx.dir.copyFile(invalid_path, ctx.dir, invalid_path, .{})); | 2191 | try testing.expectError(expected_err, ctx.dir.copyFile(invalid_path, ctx.dir, invalid_path, .{})); |
| 2192 | 2192 | ||
| ... | @@ -2235,7 +2235,7 @@ test "read file non vectored" { | ... | @@ -2235,7 +2235,7 @@ test "read file non vectored" { |
| 2235 | try file_writer.interface.flush(); | 2235 | try file_writer.interface.flush(); |
| 2236 | } | 2236 | } |
| 2237 | 2237 | ||
| 2238 | var file_reader: std.Io.File.Reader = .initAdapted(file, io, &.{}); | 2238 | var file_reader: std.Io.File.Reader = .init(file, io, &.{}); |
| 2239 | 2239 | ||
| 2240 | var write_buffer: [100]u8 = undefined; | 2240 | var write_buffer: [100]u8 = undefined; |
| 2241 | var w: std.Io.Writer = .fixed(&write_buffer); | 2241 | var w: std.Io.Writer = .fixed(&write_buffer); |
| ... | @@ -2268,7 +2268,7 @@ test "seek keeping partial buffer" { | ... | @@ -2268,7 +2268,7 @@ test "seek keeping partial buffer" { |
| 2268 | } | 2268 | } |
| 2269 | 2269 | ||
| 2270 | var read_buffer: [3]u8 = undefined; | 2270 | var read_buffer: [3]u8 = undefined; |
| 2271 | var file_reader: Io.File.Reader = .initAdapted(file, io, &read_buffer); | 2271 | var file_reader: Io.File.Reader = .init(file, io, &read_buffer); |
| 2272 | 2272 | ||
| 2273 | try testing.expectEqual(0, file_reader.logicalPos()); | 2273 | try testing.expectEqual(0, file_reader.logicalPos()); |
| 2274 | 2274 | ||
| ... | @@ -2301,7 +2301,7 @@ test "seekBy" { | ... | @@ -2301,7 +2301,7 @@ test "seekBy" { |
| 2301 | defer tmp_dir.cleanup(); | 2301 | defer tmp_dir.cleanup(); |
| 2302 | 2302 | ||
| 2303 | try tmp_dir.dir.writeFile(.{ .sub_path = "blah.txt", .data = "let's test seekBy" }); | 2303 | try tmp_dir.dir.writeFile(.{ .sub_path = "blah.txt", .data = "let's test seekBy" }); |
| 2304 | const f = try tmp_dir.dir.openFile("blah.txt", .{ .mode = .read_only }); | 2304 | const f = try tmp_dir.dir.openFile(io, "blah.txt", .{ .mode = .read_only }); |
| 2305 | defer f.close(io); | 2305 | defer f.close(io); |
| 2306 | var reader = f.readerStreaming(io, &.{}); | 2306 | var reader = f.readerStreaming(io, &.{}); |
| 2307 | try reader.seekBy(2); | 2307 | try reader.seekBy(2); |
| ... | @@ -2332,7 +2332,7 @@ test "seekTo flushes buffered data" { | ... | @@ -2332,7 +2332,7 @@ test "seekTo flushes buffered data" { |
| 2332 | } | 2332 | } |
| 2333 | 2333 | ||
| 2334 | var read_buffer: [16]u8 = undefined; | 2334 | var read_buffer: [16]u8 = undefined; |
| 2335 | var file_reader: std.Io.File.Reader = .initAdapted(file, io, &read_buffer); | 2335 | var file_reader: std.Io.File.Reader = .init(file, io, &read_buffer); |
| 2336 | 2336 | ||
| 2337 | var buf: [4]u8 = undefined; | 2337 | var buf: [4]u8 = undefined; |
| 2338 | try file_reader.interface.readSliceAll(&buf); | 2338 | try file_reader.interface.readSliceAll(&buf); |
| ... | @@ -2347,7 +2347,7 @@ test "File.Writer sendfile with buffered contents" { | ... | @@ -2347,7 +2347,7 @@ test "File.Writer sendfile with buffered contents" { |
| 2347 | 2347 | ||
| 2348 | { | 2348 | { |
| 2349 | try tmp_dir.dir.writeFile(.{ .sub_path = "a", .data = "bcd" }); | 2349 | try tmp_dir.dir.writeFile(.{ .sub_path = "a", .data = "bcd" }); |
| 2350 | const in = try tmp_dir.dir.openFile("a", .{}); | 2350 | const in = try tmp_dir.dir.openFile(io, "a", .{}); |
| 2351 | defer in.close(io); | 2351 | defer in.close(io); |
| 2352 | const out = try tmp_dir.dir.createFile("b", .{}); | 2352 | const out = try tmp_dir.dir.createFile("b", .{}); |
| 2353 | defer out.close(io); | 2353 | defer out.close(io); |
| ... | @@ -2364,7 +2364,7 @@ test "File.Writer sendfile with buffered contents" { | ... | @@ -2364,7 +2364,7 @@ test "File.Writer sendfile with buffered contents" { |
| 2364 | try out_w.interface.flush(); | 2364 | try out_w.interface.flush(); |
| 2365 | } | 2365 | } |
| 2366 | 2366 | ||
| 2367 | var check = try tmp_dir.dir.openFile("b", .{}); | 2367 | var check = try tmp_dir.dir.openFile(io, "b", .{}); |
| 2368 | defer check.close(io); | 2368 | defer check.close(io); |
| 2369 | var check_buf: [4]u8 = undefined; | 2369 | var check_buf: [4]u8 = undefined; |
| 2370 | var check_r = check.reader(io, &check_buf); | 2370 | var check_r = check.reader(io, &check_buf); |
lib/std/os/linux/IoUring.zig+3-3| ... | @@ -3002,7 +3002,7 @@ test "renameat" { | ... | @@ -3002,7 +3002,7 @@ test "renameat" { |
| 3002 | }, cqe); | 3002 | }, cqe); |
| 3003 | 3003 | ||
| 3004 | // Validate that the old file doesn't exist anymore | 3004 | // Validate that the old file doesn't exist anymore |
| 3005 | try testing.expectError(error.FileNotFound, tmp.dir.openFile(old_path, .{})); | 3005 | try testing.expectError(error.FileNotFound, tmp.dir.openFile(io, old_path, .{})); |
| 3006 | 3006 | ||
| 3007 | // Validate that the new file exists with the proper content | 3007 | // Validate that the new file exists with the proper content |
| 3008 | var new_file_data: [16]u8 = undefined; | 3008 | var new_file_data: [16]u8 = undefined; |
| ... | @@ -3057,7 +3057,7 @@ test "unlinkat" { | ... | @@ -3057,7 +3057,7 @@ test "unlinkat" { |
| 3057 | }, cqe); | 3057 | }, cqe); |
| 3058 | 3058 | ||
| 3059 | // Validate that the file doesn't exist anymore | 3059 | // Validate that the file doesn't exist anymore |
| 3060 | _ = tmp.dir.openFile(path, .{}) catch |err| switch (err) { | 3060 | _ = tmp.dir.openFile(io, path, .{}) catch |err| switch (err) { |
| 3061 | error.FileNotFound => {}, | 3061 | error.FileNotFound => {}, |
| 3062 | else => std.debug.panic("unexpected error: {}", .{err}), | 3062 | else => std.debug.panic("unexpected error: {}", .{err}), |
| 3063 | }; | 3063 | }; |
| ... | @@ -3154,7 +3154,7 @@ test "symlinkat" { | ... | @@ -3154,7 +3154,7 @@ test "symlinkat" { |
| 3154 | }, cqe); | 3154 | }, cqe); |
| 3155 | 3155 | ||
| 3156 | // Validate that the symlink exist | 3156 | // Validate that the symlink exist |
| 3157 | _ = try tmp.dir.openFile(link_path, .{}); | 3157 | _ = try tmp.dir.openFile(io, link_path, .{}); |
| 3158 | } | 3158 | } |
| 3159 | 3159 | ||
| 3160 | test "linkat" { | 3160 | test "linkat" { |
lib/std/posix/test.zig+4-4| ... | @@ -164,10 +164,10 @@ test "linkat with different directories" { | ... | @@ -164,10 +164,10 @@ test "linkat with different directories" { |
| 164 | // Test 1: link from file in subdir back up to target in parent directory | 164 | // Test 1: link from file in subdir back up to target in parent directory |
| 165 | try posix.linkat(tmp.dir.fd, target_name, subdir.fd, link_name, 0); | 165 | try posix.linkat(tmp.dir.fd, target_name, subdir.fd, link_name, 0); |
| 166 | 166 | ||
| 167 | const efd = try tmp.dir.openFile(target_name, .{}); | 167 | const efd = try tmp.dir.openFile(io, target_name, .{}); |
| 168 | defer efd.close(io); | 168 | defer efd.close(io); |
| 169 | 169 | ||
| 170 | const nfd = try subdir.openFile(link_name, .{}); | 170 | const nfd = try subdir.openFile(io, link_name, .{}); |
| 171 | defer nfd.close(io); | 171 | defer nfd.close(io); |
| 172 | 172 | ||
| 173 | { | 173 | { |
| ... | @@ -429,7 +429,7 @@ test "mmap" { | ... | @@ -429,7 +429,7 @@ test "mmap" { |
| 429 | 429 | ||
| 430 | // Map the whole file | 430 | // Map the whole file |
| 431 | { | 431 | { |
| 432 | const file = try tmp.dir.openFile(test_out_file, .{}); | 432 | const file = try tmp.dir.openFile(io, test_out_file, .{}); |
| 433 | defer file.close(io); | 433 | defer file.close(io); |
| 434 | 434 | ||
| 435 | const data = try posix.mmap( | 435 | const data = try posix.mmap( |
| ... | @@ -454,7 +454,7 @@ test "mmap" { | ... | @@ -454,7 +454,7 @@ test "mmap" { |
| 454 | 454 | ||
| 455 | // Map the upper half of the file | 455 | // Map the upper half of the file |
| 456 | { | 456 | { |
| 457 | const file = try tmp.dir.openFile(test_out_file, .{}); | 457 | const file = try tmp.dir.openFile(io, test_out_file, .{}); |
| 458 | defer file.close(io); | 458 | defer file.close(io); |
| 459 | 459 | ||
| 460 | const data = try posix.mmap( | 460 | const data = try posix.mmap( |
lib/std/zig/system.zig+3-3| ... | @@ -817,7 +817,7 @@ fn glibcVerFromRPath(io: Io, rpath: []const u8) !std.SemanticVersion { | ... | @@ -817,7 +817,7 @@ fn glibcVerFromRPath(io: Io, rpath: []const u8) !std.SemanticVersion { |
| 817 | // .dynstr section, and finding the max version number of symbols | 817 | // .dynstr section, and finding the max version number of symbols |
| 818 | // that start with "GLIBC_2.". | 818 | // that start with "GLIBC_2.". |
| 819 | const glibc_so_basename = "libc.so.6"; | 819 | const glibc_so_basename = "libc.so.6"; |
| 820 | var file = dir.openFile(glibc_so_basename, .{}) catch |err| switch (err) { | 820 | var file = dir.openFile(io, glibc_so_basename, .{}) catch |err| switch (err) { |
| 821 | error.NameTooLong => return error.Unexpected, | 821 | error.NameTooLong => return error.Unexpected, |
| 822 | error.BadPathName => return error.Unexpected, | 822 | error.BadPathName => return error.Unexpected, |
| 823 | error.PipeBusy => return error.Unexpected, // Windows-only | 823 | error.PipeBusy => return error.Unexpected, // Windows-only |
| ... | @@ -851,7 +851,7 @@ fn glibcVerFromRPath(io: Io, rpath: []const u8) !std.SemanticVersion { | ... | @@ -851,7 +851,7 @@ fn glibcVerFromRPath(io: Io, rpath: []const u8) !std.SemanticVersion { |
| 851 | 851 | ||
| 852 | // Empirically, glibc 2.34 libc.so .dynstr section is 32441 bytes on my system. | 852 | // Empirically, glibc 2.34 libc.so .dynstr section is 32441 bytes on my system. |
| 853 | var buffer: [8000]u8 = undefined; | 853 | var buffer: [8000]u8 = undefined; |
| 854 | var file_reader: Io.File.Reader = .initAdapted(file, io, &buffer); | 854 | var file_reader: Io.File.Reader = .init(file, io, &buffer); |
| 855 | 855 | ||
| 856 | return glibcVerFromSoFile(&file_reader) catch |err| switch (err) { | 856 | return glibcVerFromSoFile(&file_reader) catch |err| switch (err) { |
| 857 | error.InvalidElfMagic, | 857 | error.InvalidElfMagic, |
| ... | @@ -1053,7 +1053,7 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ | ... | @@ -1053,7 +1053,7 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ |
| 1053 | var is_elf_file = false; | 1053 | var is_elf_file = false; |
| 1054 | defer if (!is_elf_file) file.close(io); | 1054 | defer if (!is_elf_file) file.close(io); |
| 1055 | 1055 | ||
| 1056 | file_reader = .initAdapted(file, io, &file_reader_buffer); | 1056 | file_reader = .init(file, io, &file_reader_buffer); |
| 1057 | file_name = undefined; // it aliases file_reader_buffer | 1057 | file_name = undefined; // it aliases file_reader_buffer |
| 1058 | 1058 | ||
| 1059 | const header = elf.Header.read(&file_reader.interface) catch |hdr_err| switch (hdr_err) { | 1059 | const header = elf.Header.read(&file_reader.interface) catch |hdr_err| switch (hdr_err) { |
src/Compilation.zig+4-4| ... | @@ -1104,7 +1104,7 @@ pub const CObject = struct { | ... | @@ -1104,7 +1104,7 @@ pub const CObject = struct { |
| 1104 | const source_line = source_line: { | 1104 | const source_line = source_line: { |
| 1105 | if (diag.src_loc.offset == 0 or diag.src_loc.column == 0) break :source_line 0; | 1105 | if (diag.src_loc.offset == 0 or diag.src_loc.column == 0) break :source_line 0; |
| 1106 | 1106 | ||
| 1107 | const file = fs.cwd().openFile(file_name, .{}) catch break :source_line 0; | 1107 | const file = fs.cwd().openFile(io, file_name, .{}) catch break :source_line 0; |
| 1108 | defer file.close(io); | 1108 | defer file.close(io); |
| 1109 | var buffer: [1024]u8 = undefined; | 1109 | var buffer: [1024]u8 = undefined; |
| 1110 | var file_reader = file.reader(io, &buffer); | 1110 | var file_reader = file.reader(io, &buffer); |
| ... | @@ -1179,7 +1179,7 @@ pub const CObject = struct { | ... | @@ -1179,7 +1179,7 @@ pub const CObject = struct { |
| 1179 | }; | 1179 | }; |
| 1180 | 1180 | ||
| 1181 | var buffer: [1024]u8 = undefined; | 1181 | var buffer: [1024]u8 = undefined; |
| 1182 | const file = try fs.cwd().openFile(path, .{}); | 1182 | const file = try fs.cwd().openFile(io, path, .{}); |
| 1183 | defer file.close(io); | 1183 | defer file.close(io); |
| 1184 | var file_reader = file.reader(io, &buffer); | 1184 | var file_reader = file.reader(io, &buffer); |
| 1185 | var bc = std.zig.llvm.BitcodeReader.init(gpa, .{ .reader = &file_reader.interface }); | 1185 | var bc = std.zig.llvm.BitcodeReader.init(gpa, .{ .reader = &file_reader.interface }); |
| ... | @@ -5354,14 +5354,14 @@ fn docsCopyModule( | ... | @@ -5354,14 +5354,14 @@ fn docsCopyModule( |
| 5354 | }, | 5354 | }, |
| 5355 | else => continue, | 5355 | else => continue, |
| 5356 | } | 5356 | } |
| 5357 | var file = mod_dir.openFile(entry.path, .{}) catch |err| { | 5357 | var file = mod_dir.openFile(io, entry.path, .{}) catch |err| { |
| 5358 | return comp.lockAndSetMiscFailure(.docs_copy, "unable to open {f}{s}: {t}", .{ | 5358 | return comp.lockAndSetMiscFailure(.docs_copy, "unable to open {f}{s}: {t}", .{ |
| 5359 | root.fmt(comp), entry.path, err, | 5359 | root.fmt(comp), entry.path, err, |
| 5360 | }); | 5360 | }); |
| 5361 | }; | 5361 | }; |
| 5362 | defer file.close(io); | 5362 | defer file.close(io); |
| 5363 | const stat = try file.stat(); | 5363 | const stat = try file.stat(); |
| 5364 | var file_reader: Io.File.Reader = .initSize(file.adaptToNewApi(), io, &buffer, stat.size); | 5364 | var file_reader: Io.File.Reader = .initSize(file, io, &buffer, stat.size); |
| 5365 | 5365 | ||
| 5366 | archiver.writeFileTimestamp(entry.path, &file_reader, stat.mtime) catch |err| { | 5366 | archiver.writeFileTimestamp(entry.path, &file_reader, stat.mtime) catch |err| { |
| 5367 | return comp.lockAndSetMiscFailure(.docs_copy, "unable to archive {f}{s}: {t}", .{ | 5367 | return comp.lockAndSetMiscFailure(.docs_copy, "unable to archive {f}{s}: {t}", .{ |
src/Package/Fetch.zig+3-3| ... | @@ -390,7 +390,7 @@ pub fn run(f: *Fetch) RunError!void { | ... | @@ -390,7 +390,7 @@ pub fn run(f: *Fetch) RunError!void { |
| 390 | var server_header_buffer: [init_resource_buffer_size]u8 = undefined; | 390 | var server_header_buffer: [init_resource_buffer_size]u8 = undefined; |
| 391 | 391 | ||
| 392 | const file_err = if (dir_err == error.NotDir) e: { | 392 | const file_err = if (dir_err == error.NotDir) e: { |
| 393 | if (fs.cwd().openFile(path_or_url, .{})) |file| { | 393 | if (fs.cwd().openFile(io, path_or_url, .{})) |file| { |
| 394 | var resource: Resource = .{ .file = file.reader(io, &server_header_buffer) }; | 394 | var resource: Resource = .{ .file = file.reader(io, &server_header_buffer) }; |
| 395 | return f.runResource(path_or_url, &resource, null); | 395 | return f.runResource(path_or_url, &resource, null); |
| 396 | } else |err| break :e err; | 396 | } else |err| break :e err; |
| ... | @@ -995,7 +995,7 @@ fn initResource(f: *Fetch, uri: std.Uri, resource: *Resource, reader_buffer: []u | ... | @@ -995,7 +995,7 @@ fn initResource(f: *Fetch, uri: std.Uri, resource: *Resource, reader_buffer: []u |
| 995 | 995 | ||
| 996 | if (ascii.eqlIgnoreCase(uri.scheme, "file")) { | 996 | if (ascii.eqlIgnoreCase(uri.scheme, "file")) { |
| 997 | const path = try uri.path.toRawMaybeAlloc(arena); | 997 | const path = try uri.path.toRawMaybeAlloc(arena); |
| 998 | const file = f.parent_package_root.openFile(path, .{}) catch |err| { | 998 | const file = f.parent_package_root.openFile(io, path, .{}) catch |err| { |
| 999 | return f.fail(f.location_tok, try eb.printString("unable to open '{f}{s}': {t}", .{ | 999 | return f.fail(f.location_tok, try eb.printString("unable to open '{f}{s}': {t}", .{ |
| 1000 | f.parent_package_root, path, err, | 1000 | f.parent_package_root, path, err, |
| 1001 | })); | 1001 | })); |
| ... | @@ -1677,7 +1677,7 @@ fn hashFileFallible(io: Io, dir: Io.Dir, hashed_file: *HashedFile) HashedFile.Er | ... | @@ -1677,7 +1677,7 @@ fn hashFileFallible(io: Io, dir: Io.Dir, hashed_file: *HashedFile) HashedFile.Er |
| 1677 | 1677 | ||
| 1678 | switch (hashed_file.kind) { | 1678 | switch (hashed_file.kind) { |
| 1679 | .file => { | 1679 | .file => { |
| 1680 | var file = try dir.openFile(hashed_file.fs_path, .{}); | 1680 | var file = try dir.openFile(io, hashed_file.fs_path, .{}); |
| 1681 | defer file.close(io); | 1681 | defer file.close(io); |
| 1682 | // Hard-coded false executable bit: https://github.com/ziglang/zig/issues/17463 | 1682 | // Hard-coded false executable bit: https://github.com/ziglang/zig/issues/17463 |
| 1683 | hasher.update(&.{ 0, 0 }); | 1683 | hasher.update(&.{ 0, 0 }); |
src/Package/Fetch/git.zig+1-1| ... | @@ -1714,7 +1714,7 @@ pub fn main() !void { | ... | @@ -1714,7 +1714,7 @@ pub fn main() !void { |
| 1714 | 1714 | ||
| 1715 | const format = std.meta.stringToEnum(Oid.Format, args[1]) orelse return error.InvalidFormat; | 1715 | const format = std.meta.stringToEnum(Oid.Format, args[1]) orelse return error.InvalidFormat; |
| 1716 | 1716 | ||
| 1717 | var pack_file = try std.fs.cwd().openFile(args[2], .{}); | 1717 | var pack_file = try std.fs.cwd().openFile(io, args[2], .{}); |
| 1718 | defer pack_file.close(io); | 1718 | defer pack_file.close(io); |
| 1719 | var pack_file_buffer: [4096]u8 = undefined; | 1719 | var pack_file_buffer: [4096]u8 = undefined; |
| 1720 | var pack_file_reader = pack_file.reader(io, &pack_file_buffer); | 1720 | var pack_file_reader = pack_file.reader(io, &pack_file_buffer); |
src/Zcu.zig+1-1| ... | @@ -1076,7 +1076,7 @@ pub const File = struct { | ... | @@ -1076,7 +1076,7 @@ pub const File = struct { |
| 1076 | 1076 | ||
| 1077 | var f = f: { | 1077 | var f = f: { |
| 1078 | const dir, const sub_path = file.path.openInfo(zcu.comp.dirs); | 1078 | const dir, const sub_path = file.path.openInfo(zcu.comp.dirs); |
| 1079 | break :f try dir.openFile(sub_path, .{}); | 1079 | break :f try dir.openFile(io, sub_path, .{}); |
| 1080 | }; | 1080 | }; |
| 1081 | defer f.close(io); | 1081 | defer f.close(io); |
| 1082 | 1082 |
src/Zcu/PerThread.zig+2-2| ... | @@ -94,7 +94,7 @@ pub fn updateFile( | ... | @@ -94,7 +94,7 @@ pub fn updateFile( |
| 94 | // In any case we need to examine the stat of the file to determine the course of action. | 94 | // In any case we need to examine the stat of the file to determine the course of action. |
| 95 | var source_file = f: { | 95 | var source_file = f: { |
| 96 | const dir, const sub_path = file.path.openInfo(comp.dirs); | 96 | const dir, const sub_path = file.path.openInfo(comp.dirs); |
| 97 | break :f try dir.openFile(sub_path, .{}); | 97 | break :f try dir.openFile(io, sub_path, .{}); |
| 98 | }; | 98 | }; |
| 99 | defer source_file.close(io); | 99 | defer source_file.close(io); |
| 100 | 100 | ||
| ... | @@ -2466,7 +2466,7 @@ fn updateEmbedFileInner( | ... | @@ -2466,7 +2466,7 @@ fn updateEmbedFileInner( |
| 2466 | 2466 | ||
| 2467 | var file = f: { | 2467 | var file = f: { |
| 2468 | const dir, const sub_path = ef.path.openInfo(zcu.comp.dirs); | 2468 | const dir, const sub_path = ef.path.openInfo(zcu.comp.dirs); |
| 2469 | break :f try dir.openFile(sub_path, .{}); | 2469 | break :f try dir.openFile(io, sub_path, .{}); |
| 2470 | }; | 2470 | }; |
| 2471 | defer file.close(io); | 2471 | defer file.close(io); |
| 2472 | 2472 |
src/fmt.zig+1-1| ... | @@ -262,7 +262,7 @@ fn fmtPathFile( | ... | @@ -262,7 +262,7 @@ fn fmtPathFile( |
| 262 | ) !void { | 262 | ) !void { |
| 263 | const io = fmt.io; | 263 | const io = fmt.io; |
| 264 | 264 | ||
| 265 | const source_file = try dir.openFile(sub_path, .{}); | 265 | const source_file = try dir.openFile(io, sub_path, .{}); |
| 266 | var file_closed = false; | 266 | var file_closed = false; |
| 267 | errdefer if (!file_closed) source_file.close(io); | 267 | errdefer if (!file_closed) source_file.close(io); |
| 268 | 268 |
src/introspect.zig+2-2| ... | @@ -22,7 +22,7 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory { | ... | @@ -22,7 +22,7 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory { |
| 22 | // Try lib/zig/std/std.zig | 22 | // Try lib/zig/std/std.zig |
| 23 | const lib_zig = "lib" ++ fs.path.sep_str ++ "zig"; | 23 | const lib_zig = "lib" ++ fs.path.sep_str ++ "zig"; |
| 24 | var test_zig_dir = base_dir.openDir(lib_zig, .{}) catch break :zig_dir; | 24 | var test_zig_dir = base_dir.openDir(lib_zig, .{}) catch break :zig_dir; |
| 25 | const file = test_zig_dir.openFile(test_index_file, .{}) catch { | 25 | const file = test_zig_dir.openFile(io, test_index_file, .{}) catch { |
| 26 | test_zig_dir.close(io); | 26 | test_zig_dir.close(io); |
| 27 | break :zig_dir; | 27 | break :zig_dir; |
| 28 | }; | 28 | }; |
| ... | @@ -32,7 +32,7 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory { | ... | @@ -32,7 +32,7 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory { |
| 32 | 32 | ||
| 33 | // Try lib/std/std.zig | 33 | // Try lib/std/std.zig |
| 34 | var test_zig_dir = base_dir.openDir("lib", .{}) catch return null; | 34 | var test_zig_dir = base_dir.openDir("lib", .{}) catch return null; |
| 35 | const file = test_zig_dir.openFile(test_index_file, .{}) catch { | 35 | const file = test_zig_dir.openFile(io, test_index_file, .{}) catch { |
| 36 | test_zig_dir.close(io); | 36 | test_zig_dir.close(io); |
| 37 | return null; | 37 | return null; |
| 38 | }; | 38 | }; |
src/link.zig+12-12| ... | @@ -637,7 +637,7 @@ pub const File = struct { | ... | @@ -637,7 +637,7 @@ pub const File = struct { |
| 637 | } | 637 | } |
| 638 | } | 638 | } |
| 639 | } | 639 | } |
| 640 | base.file = try emit.root_dir.handle.openFile(emit.sub_path, .{ .mode = .read_write }); | 640 | base.file = try emit.root_dir.handle.openFile(io, emit.sub_path, .{ .mode = .read_write }); |
| 641 | }, | 641 | }, |
| 642 | .elf2, .coff2 => if (base.file == null) { | 642 | .elf2, .coff2 => if (base.file == null) { |
| 643 | const mf = if (base.cast(.elf2)) |elf| | 643 | const mf = if (base.cast(.elf2)) |elf| |
| ... | @@ -646,10 +646,10 @@ pub const File = struct { | ... | @@ -646,10 +646,10 @@ pub const File = struct { |
| 646 | &coff.mf | 646 | &coff.mf |
| 647 | else | 647 | else |
| 648 | unreachable; | 648 | unreachable; |
| 649 | mf.file = try base.emit.root_dir.handle.adaptToNewApi().openFile(io, base.emit.sub_path, .{ | 649 | mf.file = try base.emit.root_dir.handle.openFile(io, base.emit.sub_path, .{ |
| 650 | .mode = .read_write, | 650 | .mode = .read_write, |
| 651 | }); | 651 | }); |
| 652 | base.file = .adaptFromNewApi(mf.file); | 652 | base.file = mf.file; |
| 653 | try mf.ensureTotalCapacity(@intCast(mf.nodes.items[0].location().resolve(mf)[1])); | 653 | try mf.ensureTotalCapacity(@intCast(mf.nodes.items[0].location().resolve(mf)[1])); |
| 654 | }, | 654 | }, |
| 655 | .c, .spirv => dev.checkAny(&.{ .c_linker, .spirv_linker }), | 655 | .c, .spirv => dev.checkAny(&.{ .c_linker, .spirv_linker }), |
| ... | @@ -2007,7 +2007,7 @@ fn resolveLibInput( | ... | @@ -2007,7 +2007,7 @@ fn resolveLibInput( |
| 2007 | .sub_path = try std.fmt.allocPrint(arena, "lib{s}.tbd", .{lib_name}), | 2007 | .sub_path = try std.fmt.allocPrint(arena, "lib{s}.tbd", .{lib_name}), |
| 2008 | }; | 2008 | }; |
| 2009 | try checked_paths.print(gpa, "\n {f}", .{test_path}); | 2009 | try checked_paths.print(gpa, "\n {f}", .{test_path}); |
| 2010 | var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) { | 2010 | var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) { |
| 2011 | error.FileNotFound => break :tbd, | 2011 | error.FileNotFound => break :tbd, |
| 2012 | else => |e| fatal("unable to search for tbd library '{f}': {s}", .{ test_path, @errorName(e) }), | 2012 | else => |e| fatal("unable to search for tbd library '{f}': {s}", .{ test_path, @errorName(e) }), |
| 2013 | }; | 2013 | }; |
| ... | @@ -2043,7 +2043,7 @@ fn resolveLibInput( | ... | @@ -2043,7 +2043,7 @@ fn resolveLibInput( |
| 2043 | .sub_path = try std.fmt.allocPrint(arena, "lib{s}.so", .{lib_name}), | 2043 | .sub_path = try std.fmt.allocPrint(arena, "lib{s}.so", .{lib_name}), |
| 2044 | }; | 2044 | }; |
| 2045 | try checked_paths.print(gpa, "\n {f}", .{test_path}); | 2045 | try checked_paths.print(gpa, "\n {f}", .{test_path}); |
| 2046 | var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) { | 2046 | var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) { |
| 2047 | error.FileNotFound => break :so, | 2047 | error.FileNotFound => break :so, |
| 2048 | else => |e| fatal("unable to search for so library '{f}': {s}", .{ | 2048 | else => |e| fatal("unable to search for so library '{f}': {s}", .{ |
| 2049 | test_path, @errorName(e), | 2049 | test_path, @errorName(e), |
| ... | @@ -2061,7 +2061,7 @@ fn resolveLibInput( | ... | @@ -2061,7 +2061,7 @@ fn resolveLibInput( |
| 2061 | .sub_path = try std.fmt.allocPrint(arena, "lib{s}.a", .{lib_name}), | 2061 | .sub_path = try std.fmt.allocPrint(arena, "lib{s}.a", .{lib_name}), |
| 2062 | }; | 2062 | }; |
| 2063 | try checked_paths.print(gpa, "\n {f}", .{test_path}); | 2063 | try checked_paths.print(gpa, "\n {f}", .{test_path}); |
| 2064 | var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) { | 2064 | var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) { |
| 2065 | error.FileNotFound => break :mingw, | 2065 | error.FileNotFound => break :mingw, |
| 2066 | else => |e| fatal("unable to search for static library '{f}': {s}", .{ test_path, @errorName(e) }), | 2066 | else => |e| fatal("unable to search for static library '{f}': {s}", .{ test_path, @errorName(e) }), |
| 2067 | }; | 2067 | }; |
| ... | @@ -2115,7 +2115,7 @@ fn resolvePathInput( | ... | @@ -2115,7 +2115,7 @@ fn resolvePathInput( |
| 2115 | .static_library => return try resolvePathInputLib(gpa, arena, io, unresolved_inputs, resolved_inputs, ld_script_bytes, target, pq, .static, color), | 2115 | .static_library => return try resolvePathInputLib(gpa, arena, io, unresolved_inputs, resolved_inputs, ld_script_bytes, target, pq, .static, color), |
| 2116 | .shared_library => return try resolvePathInputLib(gpa, arena, io, unresolved_inputs, resolved_inputs, ld_script_bytes, target, pq, .dynamic, color), | 2116 | .shared_library => return try resolvePathInputLib(gpa, arena, io, unresolved_inputs, resolved_inputs, ld_script_bytes, target, pq, .dynamic, color), |
| 2117 | .object => { | 2117 | .object => { |
| 2118 | var file = pq.path.root_dir.handle.openFile(pq.path.sub_path, .{}) catch |err| | 2118 | var file = pq.path.root_dir.handle.openFile(io, pq.path.sub_path, .{}) catch |err| |
| 2119 | fatal("failed to open object {f}: {s}", .{ pq.path, @errorName(err) }); | 2119 | fatal("failed to open object {f}: {s}", .{ pq.path, @errorName(err) }); |
| 2120 | errdefer file.close(io); | 2120 | errdefer file.close(io); |
| 2121 | try resolved_inputs.append(gpa, .{ .object = .{ | 2121 | try resolved_inputs.append(gpa, .{ .object = .{ |
| ... | @@ -2127,7 +2127,7 @@ fn resolvePathInput( | ... | @@ -2127,7 +2127,7 @@ fn resolvePathInput( |
| 2127 | return null; | 2127 | return null; |
| 2128 | }, | 2128 | }, |
| 2129 | .res => { | 2129 | .res => { |
| 2130 | var file = pq.path.root_dir.handle.openFile(pq.path.sub_path, .{}) catch |err| | 2130 | var file = pq.path.root_dir.handle.openFile(io, pq.path.sub_path, .{}) catch |err| |
| 2131 | fatal("failed to open windows resource {f}: {s}", .{ pq.path, @errorName(err) }); | 2131 | fatal("failed to open windows resource {f}: {s}", .{ pq.path, @errorName(err) }); |
| 2132 | errdefer file.close(io); | 2132 | errdefer file.close(io); |
| 2133 | try resolved_inputs.append(gpa, .{ .res = .{ | 2133 | try resolved_inputs.append(gpa, .{ .res = .{ |
| ... | @@ -2164,7 +2164,7 @@ fn resolvePathInputLib( | ... | @@ -2164,7 +2164,7 @@ fn resolvePathInputLib( |
| 2164 | .static_library, .shared_library => true, | 2164 | .static_library, .shared_library => true, |
| 2165 | else => false, | 2165 | else => false, |
| 2166 | }) { | 2166 | }) { |
| 2167 | var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) { | 2167 | var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) { |
| 2168 | error.FileNotFound => return .no_match, | 2168 | error.FileNotFound => return .no_match, |
| 2169 | else => |e| fatal("unable to search for {s} library '{f}': {s}", .{ | 2169 | else => |e| fatal("unable to search for {s} library '{f}': {s}", .{ |
| 2170 | @tagName(link_mode), std.fmt.alt(test_path, .formatEscapeChar), @errorName(e), | 2170 | @tagName(link_mode), std.fmt.alt(test_path, .formatEscapeChar), @errorName(e), |
| ... | @@ -2242,7 +2242,7 @@ fn resolvePathInputLib( | ... | @@ -2242,7 +2242,7 @@ fn resolvePathInputLib( |
| 2242 | return .ok; | 2242 | return .ok; |
| 2243 | } | 2243 | } |
| 2244 | 2244 | ||
| 2245 | var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) { | 2245 | var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) { |
| 2246 | error.FileNotFound => return .no_match, | 2246 | error.FileNotFound => return .no_match, |
| 2247 | else => |e| fatal("unable to search for {s} library {f}: {s}", .{ | 2247 | else => |e| fatal("unable to search for {s} library {f}: {s}", .{ |
| 2248 | @tagName(link_mode), test_path, @errorName(e), | 2248 | @tagName(link_mode), test_path, @errorName(e), |
| ... | @@ -2253,7 +2253,7 @@ fn resolvePathInputLib( | ... | @@ -2253,7 +2253,7 @@ fn resolvePathInputLib( |
| 2253 | } | 2253 | } |
| 2254 | 2254 | ||
| 2255 | pub fn openObject(io: Io, path: Path, must_link: bool, hidden: bool) !Input.Object { | 2255 | pub fn openObject(io: Io, path: Path, must_link: bool, hidden: bool) !Input.Object { |
| 2256 | var file = try path.root_dir.handle.openFile(path.sub_path, .{}); | 2256 | var file = try path.root_dir.handle.openFile(io, path.sub_path, .{}); |
| 2257 | errdefer file.close(io); | 2257 | errdefer file.close(io); |
| 2258 | return .{ | 2258 | return .{ |
| 2259 | .path = path, | 2259 | .path = path, |
| ... | @@ -2264,7 +2264,7 @@ pub fn openObject(io: Io, path: Path, must_link: bool, hidden: bool) !Input.Obje | ... | @@ -2264,7 +2264,7 @@ pub fn openObject(io: Io, path: Path, must_link: bool, hidden: bool) !Input.Obje |
| 2264 | } | 2264 | } |
| 2265 | 2265 | ||
| 2266 | pub fn openDso(io: Io, path: Path, needed: bool, weak: bool, reexport: bool) !Input.Dso { | 2266 | pub fn openDso(io: Io, path: Path, needed: bool, weak: bool, reexport: bool) !Input.Dso { |
| 2267 | var file = try path.root_dir.handle.openFile(path.sub_path, .{}); | 2267 | var file = try path.root_dir.handle.openFile(io, path.sub_path, .{}); |
| 2268 | errdefer file.close(io); | 2268 | errdefer file.close(io); |
| 2269 | return .{ | 2269 | return .{ |
| 2270 | .path = path, | 2270 | .path = path, |
src/link/Coff.zig+2-2| ... | @@ -632,7 +632,7 @@ fn create( | ... | @@ -632,7 +632,7 @@ fn create( |
| 632 | }; | 632 | }; |
| 633 | 633 | ||
| 634 | const coff = try arena.create(Coff); | 634 | const coff = try arena.create(Coff); |
| 635 | const file = try path.root_dir.handle.adaptToNewApi().createFile(comp.io, path.sub_path, .{ | 635 | const file = try path.root_dir.handle.createFile(comp.io, path.sub_path, .{ |
| 636 | .read = true, | 636 | .read = true, |
| 637 | .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode), | 637 | .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode), |
| 638 | }); | 638 | }); |
| ... | @@ -644,7 +644,7 @@ fn create( | ... | @@ -644,7 +644,7 @@ fn create( |
| 644 | .comp = comp, | 644 | .comp = comp, |
| 645 | .emit = path, | 645 | .emit = path, |
| 646 | 646 | ||
| 647 | .file = .adaptFromNewApi(file), | 647 | .file = file, |
| 648 | .gc_sections = false, | 648 | .gc_sections = false, |
| 649 | .print_gc_sections = false, | 649 | .print_gc_sections = false, |
| 650 | .build_id = .none, | 650 | .build_id = .none, |
src/link/Elf2.zig+8-6| ... | @@ -928,6 +928,7 @@ fn create( | ... | @@ -928,6 +928,7 @@ fn create( |
| 928 | path: std.Build.Cache.Path, | 928 | path: std.Build.Cache.Path, |
| 929 | options: link.File.OpenOptions, | 929 | options: link.File.OpenOptions, |
| 930 | ) !*Elf { | 930 | ) !*Elf { |
| 931 | const io = comp.io; | ||
| 931 | const target = &comp.root_mod.resolved_target.result; | 932 | const target = &comp.root_mod.resolved_target.result; |
| 932 | assert(target.ofmt == .elf); | 933 | assert(target.ofmt == .elf); |
| 933 | const class: std.elf.CLASS = switch (target.ptrBitWidth()) { | 934 | const class: std.elf.CLASS = switch (target.ptrBitWidth()) { |
| ... | @@ -973,11 +974,11 @@ fn create( | ... | @@ -973,11 +974,11 @@ fn create( |
| 973 | }; | 974 | }; |
| 974 | 975 | ||
| 975 | const elf = try arena.create(Elf); | 976 | const elf = try arena.create(Elf); |
| 976 | const file = try path.root_dir.handle.adaptToNewApi().createFile(comp.io, path.sub_path, .{ | 977 | const file = try path.root_dir.handle.createFile(io, path.sub_path, .{ |
| 977 | .read = true, | 978 | .read = true, |
| 978 | .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode), | 979 | .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode), |
| 979 | }); | 980 | }); |
| 980 | errdefer file.close(comp.io); | 981 | errdefer file.close(io); |
| 981 | elf.* = .{ | 982 | elf.* = .{ |
| 982 | .base = .{ | 983 | .base = .{ |
| 983 | .tag = .elf2, | 984 | .tag = .elf2, |
| ... | @@ -985,7 +986,7 @@ fn create( | ... | @@ -985,7 +986,7 @@ fn create( |
| 985 | .comp = comp, | 986 | .comp = comp, |
| 986 | .emit = path, | 987 | .emit = path, |
| 987 | 988 | ||
| 988 | .file = .adaptFromNewApi(file), | 989 | .file = file, |
| 989 | .gc_sections = false, | 990 | .gc_sections = false, |
| 990 | .print_gc_sections = false, | 991 | .print_gc_sections = false, |
| 991 | .build_id = .none, | 992 | .build_id = .none, |
| ... | @@ -3325,12 +3326,13 @@ fn flushInputSection(elf: *Elf, isi: Node.InputSectionIndex) !void { | ... | @@ -3325,12 +3326,13 @@ fn flushInputSection(elf: *Elf, isi: Node.InputSectionIndex) !void { |
| 3325 | const file_loc = isi.fileLocation(elf); | 3326 | const file_loc = isi.fileLocation(elf); |
| 3326 | if (file_loc.size == 0) return; | 3327 | if (file_loc.size == 0) return; |
| 3327 | const comp = elf.base.comp; | 3328 | const comp = elf.base.comp; |
| 3329 | const io = comp.io; | ||
| 3328 | const gpa = comp.gpa; | 3330 | const gpa = comp.gpa; |
| 3329 | const ii = isi.input(elf); | 3331 | const ii = isi.input(elf); |
| 3330 | const path = ii.path(elf); | 3332 | const path = ii.path(elf); |
| 3331 | const file = try path.root_dir.handle.adaptToNewApi().openFile(comp.io, path.sub_path, .{}); | 3333 | const file = try path.root_dir.handle.openFile(io, path.sub_path, .{}); |
| 3332 | defer file.close(comp.io); | 3334 | defer file.close(io); |
| 3333 | var fr = file.reader(comp.io, &.{}); | 3335 | var fr = file.reader(io, &.{}); |
| 3334 | try fr.seekTo(file_loc.offset); | 3336 | try fr.seekTo(file_loc.offset); |
| 3335 | var nw: MappedFile.Node.Writer = undefined; | 3337 | var nw: MappedFile.Node.Writer = undefined; |
| 3336 | const si = isi.symbol(elf); | 3338 | const si = isi.symbol(elf); |
src/link/MachO.zig+5-3| ... | @@ -1126,7 +1126,9 @@ fn parseDependentDylibs(self: *MachO) !void { | ... | @@ -1126,7 +1126,9 @@ fn parseDependentDylibs(self: *MachO) !void { |
| 1126 | 1126 | ||
| 1127 | if (self.dylibs.items.len == 0) return; | 1127 | if (self.dylibs.items.len == 0) return; |
| 1128 | 1128 | ||
| 1129 | const gpa = self.base.comp.gpa; | 1129 | const comp = self.base.comp; |
| 1130 | const gpa = comp.gpa; | ||
| 1131 | const io = comp.io; | ||
| 1130 | const framework_dirs = self.framework_dirs; | 1132 | const framework_dirs = self.framework_dirs; |
| 1131 | 1133 | ||
| 1132 | // TODO delete this, directories must instead be resolved by the frontend | 1134 | // TODO delete this, directories must instead be resolved by the frontend |
| ... | @@ -1183,7 +1185,7 @@ fn parseDependentDylibs(self: *MachO) !void { | ... | @@ -1183,7 +1185,7 @@ fn parseDependentDylibs(self: *MachO) !void { |
| 1183 | const path = if (existing_ext.len > 0) id.name[0 .. id.name.len - existing_ext.len] else id.name; | 1185 | const path = if (existing_ext.len > 0) id.name[0 .. id.name.len - existing_ext.len] else id.name; |
| 1184 | for (&[_][]const u8{ ".tbd", ".dylib", "" }) |ext| { | 1186 | for (&[_][]const u8{ ".tbd", ".dylib", "" }) |ext| { |
| 1185 | test_path.clearRetainingCapacity(); | 1187 | test_path.clearRetainingCapacity(); |
| 1186 | if (self.base.comp.sysroot) |root| { | 1188 | if (comp.sysroot) |root| { |
| 1187 | try test_path.print("{s}" ++ fs.path.sep_str ++ "{s}{s}", .{ root, path, ext }); | 1189 | try test_path.print("{s}" ++ fs.path.sep_str ++ "{s}{s}", .{ root, path, ext }); |
| 1188 | } else { | 1190 | } else { |
| 1189 | try test_path.print("{s}{s}", .{ path, ext }); | 1191 | try test_path.print("{s}{s}", .{ path, ext }); |
| ... | @@ -1235,7 +1237,7 @@ fn parseDependentDylibs(self: *MachO) !void { | ... | @@ -1235,7 +1237,7 @@ fn parseDependentDylibs(self: *MachO) !void { |
| 1235 | .path = Path.initCwd(full_path), | 1237 | .path = Path.initCwd(full_path), |
| 1236 | .weak = is_weak, | 1238 | .weak = is_weak, |
| 1237 | }; | 1239 | }; |
| 1238 | const file = try lib.path.root_dir.handle.openFile(lib.path.sub_path, .{}); | 1240 | const file = try lib.path.root_dir.handle.openFile(io, lib.path.sub_path, .{}); |
| 1239 | const fh = try self.addFileHandle(file); | 1241 | const fh = try self.addFileHandle(file); |
| 1240 | const fat_arch = try self.parseFatFile(file, lib.path); | 1242 | const fat_arch = try self.parseFatFile(file, lib.path); |
| 1241 | const offset = if (fat_arch) |fa| fa.offset else 0; | 1243 | const offset = if (fat_arch) |fa| fa.offset else 0; |
src/link/MachO/relocatable.zig+4-3| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?Path) link.File.FlushError!void { | 1 | pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?Path) link.File.FlushError!void { |
| 2 | const gpa = macho_file.base.comp.gpa; | 2 | const gpa = comp.gpa; |
| 3 | const diags = &macho_file.base.comp.link_diags; | 3 | const io = comp.io; |
| 4 | const diags = &comp.link_diags; | ||
| 4 | 5 | ||
| 5 | // TODO: "positional arguments" is a CLI concept, not a linker concept. Delete this unnecessary array list. | 6 | // TODO: "positional arguments" is a CLI concept, not a linker concept. Delete this unnecessary array list. |
| 6 | var positionals = std.array_list.Managed(link.Input).init(gpa); | 7 | var positionals = std.array_list.Managed(link.Input).init(gpa); |
| ... | @@ -19,7 +20,7 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?Pat | ... | @@ -19,7 +20,7 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?Pat |
| 19 | // debug info segments/sections (this is apparently by design by Apple), we copy | 20 | // debug info segments/sections (this is apparently by design by Apple), we copy |
| 20 | // the *only* input file over. | 21 | // the *only* input file over. |
| 21 | const path = positionals.items[0].path().?; | 22 | const path = positionals.items[0].path().?; |
| 22 | const in_file = path.root_dir.handle.openFile(path.sub_path, .{}) catch |err| | 23 | const in_file = path.root_dir.handle.openFile(io, path.sub_path, .{}) catch |err| |
| 23 | return diags.fail("failed to open {f}: {s}", .{ path, @errorName(err) }); | 24 | return diags.fail("failed to open {f}: {s}", .{ path, @errorName(err) }); |
| 24 | const stat = in_file.stat() catch |err| | 25 | const stat = in_file.stat() catch |err| |
| 25 | return diags.fail("failed to stat {f}: {s}", .{ path, @errorName(err) }); | 26 | return diags.fail("failed to stat {f}: {s}", .{ path, @errorName(err) }); |
src/link/MappedFile.zig+1-1| ... | @@ -630,7 +630,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested | ... | @@ -630,7 +630,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested |
| 630 | // Resize the entire file | 630 | // Resize the entire file |
| 631 | if (ni == Node.Index.root) { | 631 | if (ni == Node.Index.root) { |
| 632 | try mf.ensureCapacityForSetLocation(gpa); | 632 | try mf.ensureCapacityForSetLocation(gpa); |
| 633 | try Io.File.adaptFromNewApi(mf.file).setEndPos(new_size); | 633 | try mf.file.setEndPos(new_size); |
| 634 | try mf.ensureTotalCapacity(@intCast(new_size)); | 634 | try mf.ensureTotalCapacity(@intCast(new_size)); |
| 635 | ni.setLocationAssumeCapacity(mf, old_offset, new_size); | 635 | ni.setLocationAssumeCapacity(mf, old_offset, new_size); |
| 636 | return; | 636 | return; |
src/main.zig+5-5| ... | @@ -4681,7 +4681,7 @@ fn cmdTranslateC( | ... | @@ -4681,7 +4681,7 @@ fn cmdTranslateC( |
| 4681 | } else { | 4681 | } else { |
| 4682 | const hex_digest = Cache.binToHex(result.digest); | 4682 | const hex_digest = Cache.binToHex(result.digest); |
| 4683 | const out_zig_path = try fs.path.join(arena, &.{ "o", &hex_digest, translated_basename }); | 4683 | const out_zig_path = try fs.path.join(arena, &.{ "o", &hex_digest, translated_basename }); |
| 4684 | const zig_file = comp.dirs.local_cache.handle.openFile(out_zig_path, .{}) catch |err| { | 4684 | const zig_file = comp.dirs.local_cache.handle.openFile(io, out_zig_path, .{}) catch |err| { |
| 4685 | const path = comp.dirs.local_cache.path orelse "."; | 4685 | const path = comp.dirs.local_cache.path orelse "."; |
| 4686 | fatal("unable to open cached translated zig file '{s}{s}{s}': {s}", .{ | 4686 | fatal("unable to open cached translated zig file '{s}{s}{s}': {s}", .{ |
| 4687 | path, | 4687 | path, |
| ... | @@ -6187,7 +6187,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void { | ... | @@ -6187,7 +6187,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6187 | const display_path = zig_source_path orelse "<stdin>"; | 6187 | const display_path = zig_source_path orelse "<stdin>"; |
| 6188 | const source: [:0]const u8 = s: { | 6188 | const source: [:0]const u8 = s: { |
| 6189 | var f = if (zig_source_path) |p| file: { | 6189 | var f = if (zig_source_path) |p| file: { |
| 6190 | break :file fs.cwd().openFile(p, .{}) catch |err| { | 6190 | break :file fs.cwd().openFile(io, p, .{}) catch |err| { |
| 6191 | fatal("unable to open file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) }); | 6191 | fatal("unable to open file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) }); |
| 6192 | }; | 6192 | }; |
| 6193 | } else Io.File.stdin(); | 6193 | } else Io.File.stdin(); |
| ... | @@ -6494,7 +6494,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void { | ... | @@ -6494,7 +6494,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6494 | 6494 | ||
| 6495 | const cache_file = args[0]; | 6495 | const cache_file = args[0]; |
| 6496 | 6496 | ||
| 6497 | var f = fs.cwd().openFile(cache_file, .{}) catch |err| { | 6497 | var f = fs.cwd().openFile(io, cache_file, .{}) catch |err| { |
| 6498 | fatal("unable to open zir cache file for dumping '{s}': {s}", .{ cache_file, @errorName(err) }); | 6498 | fatal("unable to open zir cache file for dumping '{s}': {s}", .{ cache_file, @errorName(err) }); |
| 6499 | }; | 6499 | }; |
| 6500 | defer f.close(io); | 6500 | defer f.close(io); |
| ... | @@ -6541,7 +6541,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void { | ... | @@ -6541,7 +6541,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6541 | const new_source_path = args[1]; | 6541 | const new_source_path = args[1]; |
| 6542 | 6542 | ||
| 6543 | const old_source = source: { | 6543 | const old_source = source: { |
| 6544 | var f = fs.cwd().openFile(old_source_path, .{}) catch |err| | 6544 | var f = fs.cwd().openFile(io, old_source_path, .{}) catch |err| |
| 6545 | fatal("unable to open old source file '{s}': {s}", .{ old_source_path, @errorName(err) }); | 6545 | fatal("unable to open old source file '{s}': {s}", .{ old_source_path, @errorName(err) }); |
| 6546 | defer f.close(io); | 6546 | defer f.close(io); |
| 6547 | var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer); | 6547 | var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer); |
| ... | @@ -6549,7 +6549,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void { | ... | @@ -6549,7 +6549,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6549 | fatal("unable to read old source file '{s}': {s}", .{ old_source_path, @errorName(err) }); | 6549 | fatal("unable to read old source file '{s}': {s}", .{ old_source_path, @errorName(err) }); |
| 6550 | }; | 6550 | }; |
| 6551 | const new_source = source: { | 6551 | const new_source = source: { |
| 6552 | var f = fs.cwd().openFile(new_source_path, .{}) catch |err| | 6552 | var f = fs.cwd().openFile(io, new_source_path, .{}) catch |err| |
| 6553 | fatal("unable to open new source file '{s}': {s}", .{ new_source_path, @errorName(err) }); | 6553 | fatal("unable to open new source file '{s}': {s}", .{ new_source_path, @errorName(err) }); |
| 6554 | defer f.close(io); | 6554 | defer f.close(io); |
| 6555 | var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer); | 6555 | var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer); |