Skip to content

Commit

Permalink
Reduced max line length from 180 to 150 (formatting)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Jan 16, 2025
1 parent 7fc573f commit 4b70401
Show file tree
Hide file tree
Showing 15 changed files with 388 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"useTabs": true,
"trailingComma": "es5",
"tabWidth": 4,
"printWidth": 180,
"printWidth": 150,
"arrowParens": "avoid"
}
16 changes: 13 additions & 3 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,19 @@ for (const setupFile of positionals) {
const { pass, fail } = status(setupFile);

try {
execSync(['tsx', options.inspect ? 'inspect' : '', '--test --experimental-test-coverage', options.force ? '--test-force-exit' : '', testsGlob, process.env.CMD].join(' '), {
stdio: ['ignore', options.verbose ? 'inherit' : 'ignore', 'inherit'],
});
execSync(
[
'tsx',
options.inspect ? 'inspect' : '',
'--test --experimental-test-coverage',
options.force ? '--test-force-exit' : '',
testsGlob,
process.env.CMD,
].join(' '),
{
stdio: ['ignore', options.verbose ? 'inherit' : 'ignore', 'inherit'],
}
);
pass();
} catch {
fail();
Expand Down
11 changes: 10 additions & 1 deletion src/backends/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import type { Entries, RequiredKeys } from 'utilium';
import { Errno, ErrnoError } from '../error.js';
import type { FileSystem } from '../filesystem.js';

type OptionType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | (abstract new (...args: any[]) => any);
type OptionType =
| 'string'
| 'number'
| 'bigint'
| 'boolean'
| 'symbol'
| 'undefined'
| 'object'
| 'function'
| (abstract new (...args: any[]) => any);

/**
* Resolves the type of Backend.options from the options interface
Expand Down
6 changes: 4 additions & 2 deletions src/backends/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export class OverlayFS extends FileSystem {
}

public async read(path: string, buffer: Uint8Array, offset: number, end: number): Promise<void> {
return (await this.writable.exists(path)) ? await this.writable.read(path, buffer, offset, end) : await this.readable.read(path, buffer, offset, end);
return (await this.writable.exists(path))
? await this.writable.read(path, buffer, offset, end)
: await this.readable.read(path, buffer, offset, end);
}

public readSync(path: string, buffer: Uint8Array, offset: number, end: number): void {
Expand Down Expand Up @@ -415,7 +417,7 @@ export class OverlayFS extends FileSystem {

private checkInitialized(): void {
if (!this._isInitialized) {
throw new ErrnoError(Errno.EPERM, 'OverlayFS is not initialized. Please initialize OverlayFS using its initialize() method before using it.');
throw new ErrnoError(Errno.EPERM, 'Overlay is not initialized');
}

if (!this._deleteLogError) {
Expand Down
7 changes: 6 additions & 1 deletion src/backends/passthrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ class PassthroughFile extends File<PassthroughFS> {
return promise;
}

public readSync(buffer: ArrayBufferView & NodeJS.ArrayBufferView, offset: number = 0, length: number = this.statSync().size, position: number | null = null): number {
public readSync(
buffer: ArrayBufferView & NodeJS.ArrayBufferView,
offset: number = 0,
length: number = this.statSync().size,
position: number | null = null
): number {
return this.node.readSync(this.fd, buffer, offset, length, position);
}

Expand Down
5 changes: 4 additions & 1 deletion src/backends/port/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export class PortFS extends Async(FileSystem) {
}

protected rpc<const T extends FSMethod>(method: T, ...args: Parameters<FSMethods[T]>): Promise<Awaited<ReturnType<FSMethods[T]>>> {
return RPC.request<FSRequest<T>, Awaited<ReturnType<FSMethods[T]>>>({ method, args } as Omit<FSRequest<T>, 'id' | 'stack' | '_zenfs'>, { ...this.options, fs: this });
return RPC.request<FSRequest<T>, Awaited<ReturnType<FSMethods[T]>>>({ method, args } as Omit<FSRequest<T>, 'id' | 'stack' | '_zenfs'>, {
...this.options,
fs: this,
});
}

public async ready(): Promise<void> {
Expand Down
18 changes: 14 additions & 4 deletions src/backends/store/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export class StoreFS<T extends Store = Store> extends FileSystem {

// Prevent us from re-grabbing the same directory listing, which still contains `old_path.base.`
const newDirNode: Inode = sameParent ? oldDirNode : await this.findInode(tx, _new.dir, 'rename');
const newDirList: typeof oldDirList = sameParent ? oldDirList : decodeDirListing((await tx.get(newDirNode.data)) ?? _throw(ErrnoError.With('ENOENT', _new.dir, 'rename')));
const newDirList: typeof oldDirList = sameParent
? oldDirList
: decodeDirListing((await tx.get(newDirNode.data)) ?? _throw(ErrnoError.With('ENOENT', _new.dir, 'rename')));

if (newDirList[_new.base]) {
// If it's a file, delete it, if it's a directory, throw a permissions error.
Expand Down Expand Up @@ -236,7 +238,9 @@ export class StoreFS<T extends Store = Store> extends FileSystem {

// Prevent us from re-grabbing the same directory listing, which still contains `old_path.base.`
const newDirNode: Inode = sameParent ? oldDirNode : this.findInodeSync(tx, _new.dir, 'rename');
const newDirList: typeof oldDirList = sameParent ? oldDirList : decodeDirListing(tx.getSync(newDirNode.data) ?? _throw(ErrnoError.With('ENOENT', _new.dir, 'rename')));
const newDirList: typeof oldDirList = sameParent
? oldDirList
: decodeDirListing(tx.getSync(newDirNode.data) ?? _throw(ErrnoError.With('ENOENT', _new.dir, 'rename')));

if (newDirList[_new.base]) {
// If it's a file, delete it, if it's a directory, throw a permissions error.
Expand Down Expand Up @@ -498,7 +502,10 @@ export class StoreFS<T extends Store = Store> extends FileSystem {
}

const { dir: parent, base: filename } = parse(path);
const inode = parent == '/' ? new Inode((await tx.get(rootIno)) ?? _throw(ErrnoError.With('ENOENT', parent, syscall))) : await this.findInode(tx, parent, syscall, visited);
const inode =
parent == '/'
? new Inode((await tx.get(rootIno)) ?? _throw(ErrnoError.With('ENOENT', parent, syscall)))
: await this.findInode(tx, parent, syscall, visited);
const dirList = decodeDirListing((await tx.get(inode.data)) ?? _throw(ErrnoError.With('ENODATA', parent, syscall)));

if (!(filename in dirList)) {
Expand Down Expand Up @@ -527,7 +534,10 @@ export class StoreFS<T extends Store = Store> extends FileSystem {
}

const { dir: parent, base: filename } = parse(path);
const inode = parent == '/' ? new Inode(tx.getSync(rootIno) ?? _throw(ErrnoError.With('ENOENT', parent, syscall))) : this.findInodeSync(tx, parent, syscall, visited);
const inode =
parent == '/'
? new Inode(tx.getSync(rootIno) ?? _throw(ErrnoError.With('ENOENT', parent, syscall)))
: this.findInodeSync(tx, parent, syscall, visited);
const dir = decodeDirListing(tx.getSync(inode.data) ?? _throw(ErrnoError.With('ENODATA', parent, syscall)));

if (!(filename in dir)) {
Expand Down
7 changes: 6 additions & 1 deletion src/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ export class DeviceFile<TData = any> extends File {
return new Stats(this.stats);
}

public readSync(buffer: ArrayBufferView, offset: number = 0, length: number = buffer.byteLength - offset, position: number = this.position): number {
public readSync(
buffer: ArrayBufferView,
offset: number = 0,
length: number = buffer.byteLength - offset,
position: number = this.position
): number {
this.stats.atimeMs = Date.now();

const end = position + length;
Expand Down
28 changes: 24 additions & 4 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ export abstract class File<FS extends FileSystem = FileSystem> {
* If position is null, data will be read from the current file position.
* @returns Promise resolving to the new length of the buffer
*/
public abstract read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<FileReadResult<TBuffer>>;
public abstract read<TBuffer extends ArrayBufferView>(
buffer: TBuffer,
offset?: number,
length?: number,
position?: number
): Promise<FileReadResult<TBuffer>>;

/**
* Read data from the file.
Expand Down Expand Up @@ -477,7 +482,12 @@ export class PreloadFile<FS extends FileSystem> extends File<FS> {
* @param position An integer specifying where to begin reading from in the file.
* If position is null, data will be read from the current file position.
*/
public async read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{ bytesRead: number; buffer: TBuffer }> {
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);
if (config.syncImmediately) await this.sync();
return { bytesRead, buffer };
Expand Down Expand Up @@ -719,7 +729,12 @@ export class LazyFile<FS extends FileSystem> extends File<FS> {
* @param position Offset from the beginning of the file where this data should be written.
* If position is null, the data will be written at the current position.
*/
public async write(buffer: Uint8Array, offset: number = 0, length: number = buffer.byteLength - offset, position: number = this.position): Promise<number> {
public async write(
buffer: Uint8Array,
offset: number = 0,
length: number = buffer.byteLength - offset,
position: number = this.position
): Promise<number> {
const slice = this.prepareWrite(buffer, offset, length, position);
await this.fs.write(this.path, slice, position);
if (config.syncImmediately) await this.sync();
Expand Down Expand Up @@ -792,7 +807,12 @@ export class LazyFile<FS extends FileSystem> extends File<FS> {
* If position is null, data will be read from the current file position.
* @returns number of bytes written
*/
public readSync(buffer: ArrayBufferView, offset: number = 0, length: number = buffer.byteLength - offset, position: number = this.position): number {
public readSync(
buffer: ArrayBufferView,
offset: number = 0,
length: number = buffer.byteLength - offset,
position: number = this.position
): number {
const end = this.prepareRead(length, position);
const uint8 = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
this.fs.readSync(this.path, uint8.subarray(offset, offset + length), position, end);
Expand Down
14 changes: 13 additions & 1 deletion src/mixins/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,19 @@ export function Async<const T extends typeof FileSystem>(FS: T): Mixin<T, AsyncM
* Patch all async methods to also call their synchronous counterparts unless called from the queue
*/
private _patchAsync(): void {
const asyncFSMethodKeys = ['rename', 'stat', 'createFile', 'openFile', 'unlink', 'rmdir', 'mkdir', 'readdir', 'link', 'sync', 'exists'] as const;
const asyncFSMethodKeys = [
'rename',
'stat',
'createFile',
'openFile',
'unlink',
'rmdir',
'mkdir',
'readdir',
'link',
'sync',
'exists',
] as const;
for (const key of asyncFSMethodKeys) {
if (typeof this[key] !== 'function') continue;

Expand Down
8 changes: 7 additions & 1 deletion src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,13 @@ export class BigIntStats extends StatsCommon<bigint> implements Node.BigIntStats
* @internal
*/
export function isStatsEqual<T extends number | bigint>(left: StatsCommon<T>, right: StatsCommon<T>): boolean {
return left.size == right.size && +left.atime == +right.atime && +left.mtime == +right.mtime && +left.ctime == +right.ctime && left.mode == right.mode;
return (
left.size == right.size &&
+left.atime == +right.atime &&
+left.mtime == +right.mtime &&
+left.ctime == +right.ctime &&
left.mode == right.mode
);
}

/** @internal */
Expand Down
10 changes: 8 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export { /** @deprecated @hidden */ decodeUTF8 as decode };
* @hidden
*/
export function decodeDirListing(data: Uint8Array): Record<string, number> {
return JSON.parse(decodeUTF8(data), (k, v) => (k == '' ? v : typeof v == 'string' ? BigInt(v).toString(16).slice(0, Math.min(v.length, 8)) : (v as number)));
return JSON.parse(decodeUTF8(data), (k, v) =>
k == '' ? v : typeof v == 'string' ? BigInt(v).toString(16).slice(0, Math.min(v.length, 8)) : (v as number)
);
}

/**
Expand Down Expand Up @@ -203,7 +205,11 @@ interface ArrayBufferViewConstructor {
readonly prototype: ArrayBufferView<ArrayBufferLike>;
new (length: number): ArrayBufferView<ArrayBuffer>;
new (array: ArrayLike<number>): ArrayBufferView<ArrayBuffer>;
new <TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(buffer: TArrayBuffer, byteOffset?: number, length?: number): ArrayBufferView<TArrayBuffer>;
new <TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(
buffer: TArrayBuffer,
byteOffset?: number,
length?: number
): ArrayBufferView<TArrayBuffer>;
new (array: ArrayLike<number> | ArrayBuffer): ArrayBufferView<ArrayBuffer>;
}

Expand Down
Loading

0 comments on commit 4b70401

Please sign in to comment.