diff options
Diffstat (limited to '')
-rw-r--r-- | src/cache.zig | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/cache.zig b/src/cache.zig index d77c5c6b2..88cf19025 100644 --- a/src/cache.zig +++ b/src/cache.zig @@ -143,6 +143,18 @@ pub const Fs = struct { comptime use_shared_buffer: bool, _file_handle: ?StoredFileDescriptorType, ) !Entry { + return c.readFileWithAllocator(bun.fs_allocator, _fs, path, dirname_fd, use_shared_buffer, _file_handle); + } + + pub fn readFileWithAllocator( + c: *Fs, + allocator: std.mem.Allocator, + _fs: *fs.FileSystem, + path: string, + dirname_fd: StoredFileDescriptorType, + comptime use_shared_buffer: bool, + _file_handle: ?StoredFileDescriptorType, + ) !Entry { var rfs = _fs.fs; var file_handle: std.fs.File = if (_file_handle) |__file| std.fs.File{ .handle = __file } else undefined; @@ -167,21 +179,22 @@ pub const Fs = struct { } } + const will_close = rfs.needToCloseFiles() and _file_handle == null; defer { - if (rfs.needToCloseFiles() and _file_handle == null) { + if (will_close) { file_handle.close(); } } const file = if (c.stream) - rfs.readFileWithHandle(path, null, file_handle, use_shared_buffer, c.sharedBuffer(), true) catch |err| { + rfs.readFileWithHandleAndAllocator(allocator, path, null, file_handle, use_shared_buffer, c.sharedBuffer(), true) catch |err| { if (Environment.isDebug) { Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); } return err; } else - rfs.readFileWithHandle(path, null, file_handle, use_shared_buffer, c.sharedBuffer(), false) catch |err| { + rfs.readFileWithHandleAndAllocator(allocator, path, null, file_handle, use_shared_buffer, c.sharedBuffer(), false) catch |err| { if (Environment.isDebug) { Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); } @@ -190,7 +203,7 @@ pub const Fs = struct { return Entry{ .contents = file.contents, - .fd = if (FeatureFlags.store_file_descriptors) file_handle.handle else 0, + .fd = if (FeatureFlags.store_file_descriptors and !will_close) file_handle.handle else 0, }; } }; |