Skip to content

Commit

Permalink
[v.1.2.6] Fixed misplaced if statements
Browse files Browse the repository at this point in the history
Updated `_read` behavior
  • Loading branch information
james-pre committed Oct 31, 2024
1 parent cb76959 commit 6975b73
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,8 @@ export class PreloadFile<FS extends FileSystem> extends File {
if (!isReadable(this.flag)) {
throw new ErrnoError(Errno.EPERM, 'File not opened with a readable mode.');
}
if (config.syncOnRead) {
this.dirty = true;
this.stats.atimeMs = Date.now();
}
this.dirty = true;
this.stats.atimeMs = Date.now();
position ??= this.position;
let end = position + length;
if (end > this.stats.size) {
Expand All @@ -549,7 +547,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
*/
public async read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{ bytesRead: number; buffer: TBuffer }> {
const bytesRead = this._read(buffer, offset, length, position);
await this.sync();
if (config.syncOnRead) await this.sync();
return { bytesRead, buffer };
}

Expand All @@ -564,7 +562,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
*/
public readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number {
const bytesRead = this._read(buffer, offset, length, position);
this.syncSync();
if (config.syncOnRead) this.syncSync();
return bytesRead;
}

Expand All @@ -573,35 +571,35 @@ export class PreloadFile<FS extends FileSystem> extends File {
throw ErrnoError.With('EBADF', this.path, 'File.chmod');
}
this.dirty = true;
if (config.syncOnWrite) this.stats.chmod(mode);
await this.sync();
this.stats.chmod(mode);
if (config.syncOnWrite) await this.sync();
}

public chmodSync(mode: number): void {
if (this.closed) {
throw ErrnoError.With('EBADF', this.path, 'File.chmod');
}
this.dirty = true;
if (config.syncOnWrite) this.stats.chmod(mode);
this.syncSync();
this.stats.chmod(mode);
if (config.syncOnWrite) this.syncSync();
}

public async chown(uid: number, gid: number): Promise<void> {
if (this.closed) {
throw ErrnoError.With('EBADF', this.path, 'File.chown');
}
this.dirty = true;
if (config.syncOnWrite) this.stats.chown(uid, gid);
await this.sync();
this.stats.chown(uid, gid);
if (config.syncOnWrite) await this.sync();
}

public chownSync(uid: number, gid: number): void {
if (this.closed) {
throw ErrnoError.With('EBADF', this.path, 'File.chown');
}
this.dirty = true;
if (config.syncOnWrite) this.stats.chown(uid, gid);
this.syncSync();
this.stats.chown(uid, gid);
if (config.syncOnWrite) this.syncSync();
}

public async utimes(atime: Date, mtime: Date): Promise<void> {
Expand Down

0 comments on commit 6975b73

Please sign in to comment.