aboutsummaryrefslogtreecommitdiff
path: root/src/fs.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs.zig')
-rw-r--r--src/fs.zig8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/fs.zig b/src/fs.zig
index d3957ebe3..043a7bd19 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -759,17 +759,21 @@ pub const FileSystem = struct {
shared_buffer.reset();
try shared_buffer.growBy(size);
shared_buffer.list.expandToCapacity();
- var read_count = file.readAll(shared_buffer.list.items) catch |err| {
+ // We use pread to ensure if the file handle was open, it doesn't seek from the last position
+ var read_count = file.preadAll(shared_buffer.list.items, 0) catch |err| {
fs.readFileError(path, err);
return err;
};
shared_buffer.list.items = shared_buffer.list.items[0..read_count];
file_contents = shared_buffer.list.items;
} else {
- file_contents = file.readToEndAllocOptions(fs.allocator, size, size, @alignOf(u8), null) catch |err| {
+ // We use pread to ensure if the file handle was open, it doesn't seek from the last position
+ var buf = try fs.allocator.alloc(u8, size);
+ var read_count = file.preadAll(buf, 0) catch |err| {
fs.readFileError(path, err);
return err;
};
+ file_contents = buf[0..read_count];
}
if (fs.watcher) |*watcher| {