Skip to content

Commit c276efd

Browse files
committed
Update to @zenfs/core 2.0
1 parent 5997159 commit c276efd

7 files changed

Lines changed: 125 additions & 128 deletions

File tree

.github/workflows/release.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ jobs:
1414
name: Release
1515
uses: zen-fs/core/.github/workflows/release-common.yaml@main
1616
needs: ci
17-
secrets: inherit
17+
secrets:
18+
npm_token: ${{ secrets.npm_token }}

package-lock.json

Lines changed: 28 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
"typescript-eslint": "^8.8.0"
6767
},
6868
"peerDependencies": {
69-
"@zenfs/core": "^1.9.0",
70-
"utilium": "^1.2.0"
69+
"@zenfs/core": "^2.0.0",
70+
"utilium": "^1.9.0"
7171
},
7272
"optionalDependencies": {
7373
"@aws-sdk/client-s3": "^3.679.0",

src/cloudfs.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { File, InodeLike } from '@zenfs/core';
2-
import { Async, ErrnoError, FileSystem, LazyFile, PreloadFile, Stats } from '@zenfs/core';
1+
import type { CreationOptions, InodeLike } from '@zenfs/core';
2+
import { Async, ErrnoError, FileSystem, Inode } from '@zenfs/core';
3+
import { dirname } from '@zenfs/core/path.js';
34
import { S_IFDIR, S_IFREG } from '@zenfs/core/vfs/constants.js';
4-
import { dirname } from '@zenfs/core/vfs/path.js';
55
import { extendBuffer } from 'utilium/buffer.js';
66

77
interface CacheEntry {
@@ -43,34 +43,28 @@ export abstract class CloudFS<TError> extends Async(FileSystem) {
4343
await this._move(oldPath, newPath).catch(this._convertAndThrow(oldPath, 'rename'));
4444
}
4545

46-
protected abstract _stat(path: string): Promise<Stats>;
46+
protected abstract _stat(path: string): Promise<InodeLike>;
4747

48-
public async stat(path: string): Promise<Stats> {
49-
if (path === '/') return new Stats({ mode: S_IFDIR | 0o755 });
48+
public async stat(path: string): Promise<InodeLike> {
49+
if (path === '/') return new Inode({ mode: S_IFDIR | 0o755 });
5050

5151
return await this._stat(path).catch(this._convertAndThrow(path, 'stat'));
5252
}
5353

54-
public async openFile(path: string, flag: string): Promise<File> {
55-
const stats = await this.stat(path).catch(this._convertAndThrow(path, 'openFile'));
56-
return new LazyFile(this, path, flag, stats);
57-
}
58-
59-
protected abstract _create(path: string, stats: Stats): Promise<void>;
60-
61-
public async createFile(path: string, flag: string, mode: number): Promise<File> {
62-
const stats = new Stats({ mode: mode | S_IFREG });
54+
protected abstract _create(path: string, inode: Inode): Promise<void>;
6355

64-
await this._create(path, stats).catch(this._convertAndThrow(path, 'createFile'));
56+
public async createFile(path: string, options: CreationOptions): Promise<Inode> {
57+
const inode = new Inode({ mode: options.mode | S_IFREG });
6558

66-
return new PreloadFile(this, path, flag, stats, new Uint8Array());
59+
await this._create(path, inode).catch(this._convertAndThrow(path, 'createFile'));
60+
return inode;
6761
}
6862

6963
protected abstract _delete(path: string, isDirectory: boolean): Promise<void>;
7064

7165
public async unlink(path: string): Promise<void> {
72-
const stats = await this.stat(path).catch(this._convertAndThrow(path, 'unlink'));
73-
if (stats.isDirectory()) throw ErrnoError.With('EISDIR', path, 'unlink');
66+
const inode = await this.stat(path).catch(this._convertAndThrow(path, 'unlink'));
67+
if (inode.mode & S_IFDIR) throw ErrnoError.With('EISDIR', path, 'unlink');
7468
await this._delete(path, false).catch(this._convertAndThrow(path, 'unlink'));
7569
}
7670

@@ -80,19 +74,26 @@ export abstract class CloudFS<TError> extends Async(FileSystem) {
8074
await this._delete(path, true).catch(this._convertAndThrow(path, 'rmdir'));
8175
}
8276

83-
public async mkdir(path: string, mode: number): Promise<void> {
77+
public async mkdir(path: string, options: CreationOptions): Promise<Inode> {
8478
// Dropbox's folder creations is recursive, so we check to make sure the parent exists
8579
const parent = dirname(path);
86-
const stats = await this.stat(parent).catch(this._convertAndThrow(path, 'mkdir'));
87-
if (stats && !stats.isDirectory()) throw ErrnoError.With('ENOTDIR', parent, 'mkdir');
80+
const parentInode = await this.stat(parent).catch(this._convertAndThrow(path, 'mkdir'));
81+
if (parentInode && !(parentInode.mode & S_IFDIR)) throw ErrnoError.With('ENOTDIR', parent, 'mkdir');
8882

89-
await this._create(path, new Stats({ mode: mode | S_IFDIR })).catch(this._convertAndThrow(path, 'mkdir'));
83+
await this._create(path, new Inode({ mode: options.mode | S_IFDIR })).catch(
84+
this._convertAndThrow(path, 'mkdir')
85+
);
86+
return new Inode({ mode: options.mode | S_IFDIR });
9087
}
9188

92-
public async sync(path: string, data: Uint8Array, stats: Partial<InodeLike> = {}): Promise<void> {
93-
await this._write(path, data, stats, 'sync').catch(this._convertAndThrow(path, 'sync'));
89+
protected _touch?(path: string, inode: Partial<InodeLike>): Promise<void>;
90+
91+
public async touch(path: string, metadata: Partial<InodeLike> = {}): Promise<void> {
92+
await this._touch?.(path, metadata).catch(this._convertAndThrow(path, 'touch'));
9493
}
9594

95+
public async sync(): Promise<void> {}
96+
9697
public link(target: string): Promise<void> {
9798
throw ErrnoError.With('ENOTSUP', target, 'link');
9899
}
@@ -104,17 +105,12 @@ export abstract class CloudFS<TError> extends Async(FileSystem) {
104105
buffer.set(data.subarray(offset, end));
105106
}
106107

107-
protected abstract _write(
108-
path: string,
109-
buffer: Uint8Array,
110-
stats: Partial<InodeLike>,
111-
syscall: string
112-
): Promise<void>;
108+
protected abstract _write(path: string, buffer: Uint8Array, syscall: string): Promise<void>;
113109

114110
public async write(path: string, data: Uint8Array, offset: number = 0): Promise<void> {
115111
const buffer = extendBuffer(await this.getValidContents(path, 'write'), offset + data.byteLength);
116112
buffer.set(data, offset);
117-
await this._write(path, buffer, {}, 'write').catch(this._convertAndThrow(path, 'write'));
113+
await this._write(path, buffer, 'write').catch(this._convertAndThrow(path, 'write'));
118114
}
119115

120116
protected partialCache = new Map<string, CacheEntry>();

src/dropbox.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Backend, InodeLike } from '@zenfs/core';
2-
import { Errno, ErrnoError, Stats } from '@zenfs/core';
1+
import type { Backend } from '@zenfs/core';
2+
import { Errno, ErrnoError, Inode } from '@zenfs/core';
33
import { S_IFDIR, S_IFLNK, S_IFREG } from '@zenfs/core/emulation/constants.js';
44
import type * as DB from 'dropbox';
55
import { CloudFS, type CloudFSOptions } from './cloudfs.js';
@@ -117,28 +117,28 @@ export class DropboxFS extends CloudFS<DBReject> {
117117
await this.client.filesMoveV2({ from_path: fixPath(from), to_path: fixPath(to) });
118118
}
119119

120-
public async _stat(path: string): Promise<Stats> {
120+
public async _stat(path: string): Promise<Inode> {
121121
const { result } = await this.client.filesGetMetadata({ path: fixPath(path) });
122122

123123
switch (result['.tag']) {
124124
case 'file':
125-
return new Stats({
125+
return new Inode({
126126
mode: (result.symlink_info ? S_IFLNK : S_IFREG) | 0o777,
127127
size: result.symlink_info?.target?.length || result.size,
128128
atimeMs: Date.now(),
129129
mtimeMs: Date.parse(result.server_modified),
130130
});
131131
case 'folder':
132-
return new Stats({ mode: S_IFDIR });
132+
return new Inode({ mode: S_IFDIR });
133133
case 'deleted':
134134
throw ErrnoError.With('ENOENT', path, 'stat');
135135
default:
136136
throw new ErrnoError(Errno.EINVAL, 'Invalid file type', path, 'stat');
137137
}
138138
}
139139

140-
protected async _create(path: string, stats: Stats): Promise<void> {
141-
if (stats.isDirectory()) {
140+
protected async _create(path: string, inode: Inode): Promise<void> {
141+
if (inode.mode & S_IFDIR) {
142142
await this.client.filesCreateFolderV2({ path: fixPath(path) });
143143
} else {
144144
await this.client.filesUpload({
@@ -185,7 +185,7 @@ export class DropboxFS extends CloudFS<DBReject> {
185185
return fileBinary;
186186
}
187187

188-
protected async _write(path: string, buffer: Uint8Array, stats: Partial<InodeLike>): Promise<void> {
188+
protected async _write(path: string, buffer: Uint8Array): Promise<void> {
189189
await this.client.filesUpload({
190190
contents: new Blob([buffer], { type: 'octet/stream' }),
191191
path: fixPath(path),

0 commit comments

Comments
 (0)