Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 17 additions & 26 deletions src/access.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Backend, CreationOptions, FileSystem, InodeLike } from '@zenfs/core';

Check warning on line 1 in src/access.ts

View workflow job for this annotation

GitHub Actions / CI

'InodeLike' is defined but never used

Check warning on line 1 in src/access.ts

View workflow job for this annotation

GitHub Actions / CI

'CreationOptions' is defined but never used
import { Async, constants, IndexFS, InMemory, Inode } from '@zenfs/core';
import { basename, dirname, join } from '@zenfs/core/path.js';
import { log, withErrno } from 'kerium';
Expand Down Expand Up @@ -106,35 +106,26 @@
}

async stat(path: string): Promise<Inode> {
try {
return await super.stat(path);
} catch (ex: any) {
if (ex.code != 'ENOENT') throw ex;

// This handle must have been created after initialization
// Try to add a new inode for the handle to the index
const handle = await this.get(null, path);
const inode = new Inode();

const handle = await this.get(null, path);
const inode = new Inode();

if (isKind(handle, 'file')) {
const file = await handle.getFile();
inode.update({
mode: 0o644 | constants.S_IFREG,
size: file.size,
mtimeMs: file.lastModified,
});
} else {
inode.update({
mode: constants.S_IFDIR | 0o777,
size: 0,
});
}
if (isKind(handle, 'file')) {
const file = await handle.getFile();
inode.update({
mode: 0o644 | constants.S_IFREG,
size: file.size,
mtimeMs: file.lastModified,
});
} else {
inode.update({
mode: constants.S_IFDIR | 0o777,
size: 0,
});
}

this.index.set(path, inode);
this.index.set(path, inode);

return inode;
}
return inode;
}

async readdir(path: string): Promise<string[]> {
Expand Down Expand Up @@ -256,7 +247,7 @@
const handle = await dir[kind == 'file' ? 'getFileHandle' : 'getDirectoryHandle'](parts.at(-1)!);
if (!this.disableHandleCache) this._handles.set(path, handle);
return handle as _Result;
} catch (ex: any) {

Check warning on line 250 in src/access.ts

View workflow job for this annotation

GitHub Actions / CI

Unexpected any. Specify a different type
if (ex.name != 'TypeMismatchError') throw convertException(ex, path);
else if (kind === null) {
const handle = await dir.getFileHandle(parts.at(-1)!).catch(ex => _throw(convertException(ex, path)));
Expand Down
Loading