@bendyline/docblocks 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-J32GU3F3.js → chunk-6IYMTYMQ.js} +249 -221
- package/dist/chunk-6IYMTYMQ.js.map +1 -0
- package/dist/{chunk-75UUF6C4.js → chunk-B56KWCSE.js} +2 -2
- package/dist/{chunk-RVQHY3XU.js → chunk-BNKV7MTO.js} +1 -1
- package/dist/{chunk-RVQHY3XU.js.map → chunk-BNKV7MTO.js.map} +1 -1
- package/dist/chunk-BXMF5YQJ.js +149 -0
- package/dist/chunk-BXMF5YQJ.js.map +1 -0
- package/dist/{chunk-PGR7LK6D.js → chunk-COYQXQK3.js} +14 -5
- package/dist/chunk-COYQXQK3.js.map +1 -0
- package/dist/{chunk-RQJRQF46.js → chunk-DN7A33LL.js} +42 -49
- package/dist/chunk-DN7A33LL.js.map +1 -0
- package/dist/chunk-FA7UNOXK.js +20 -0
- package/dist/chunk-FA7UNOXK.js.map +1 -0
- package/dist/chunk-GM5YXU4L.js +29 -0
- package/dist/chunk-GM5YXU4L.js.map +1 -0
- package/dist/{chunk-SI2LU2RP.js → chunk-JS6XFWQK.js} +2 -1
- package/dist/chunk-JS6XFWQK.js.map +1 -0
- package/dist/{chunk-EGNDADXB.js → chunk-MNSZ7EZN.js} +2 -2
- package/dist/chunk-P3DVZQ6S.js +228 -0
- package/dist/chunk-P3DVZQ6S.js.map +1 -0
- package/dist/chunk-P4WATND4.js +52 -0
- package/dist/chunk-P4WATND4.js.map +1 -0
- package/dist/chunk-RVPGQBWR.js +169 -0
- package/dist/chunk-RVPGQBWR.js.map +1 -0
- package/dist/chunk-U722UUFN.js +9 -0
- package/dist/chunk-U722UUFN.js.map +1 -0
- package/dist/{chunk-GCPBEMMH.js → chunk-VTCSF7VS.js} +11 -21
- package/dist/chunk-VTCSF7VS.js.map +1 -0
- package/dist/{chunk-2D7Y4IR3.js → chunk-WJKYY5QR.js} +123 -66
- package/dist/chunk-WJKYY5QR.js.map +1 -0
- package/dist/{chunk-5MYAICRE.js → chunk-XUML3MKV.js} +44 -56
- package/dist/chunk-XUML3MKV.js.map +1 -0
- package/dist/document/index.d.ts +358 -6
- package/dist/document/index.js +24 -3
- package/dist/document/index.js.map +1 -1
- package/dist/filesystem/electron.d.ts +73 -4
- package/dist/filesystem/electron.js +16 -3
- package/dist/filesystem/electron.js.map +1 -1
- package/dist/filesystem/index.d.ts +228 -22
- package/dist/filesystem/index.js +133 -19
- package/dist/filesystem/index.js.map +1 -1
- package/dist/filesystem/indexeddb.d.ts +284 -5
- package/dist/filesystem/indexeddb.js +22 -4
- package/dist/filesystem/indexeddb.js.map +1 -1
- package/dist/filesystem/memory.d.ts +152 -4
- package/dist/filesystem/memory.js +12 -3
- package/dist/filesystem/memory.js.map +1 -1
- package/dist/filesystem/native.d.ts +136 -4
- package/dist/filesystem/native.js +27 -3
- package/dist/filesystem/native.js.map +1 -1
- package/dist/host/index.d.ts +32 -9
- package/dist/host/index.js +26 -29
- package/dist/host/index.js.map +1 -1
- package/dist/index.d.ts +14 -10
- package/dist/index.js +204 -9
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +33 -4
- package/dist/mcp/index.js +31 -3
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/zod.d.ts +637 -635
- package/dist/mcp/zod.js +700 -884
- package/dist/mcp/zod.js.map +1 -1
- package/dist/share/index.d.ts +43 -0
- package/dist/share/index.js +13 -0
- package/dist/share/index.js.map +1 -0
- package/dist/{types-CsX6EN2t.d.ts → types-BEg5SQ1_.d.ts} +1 -1
- package/dist/{types-eOlt9J7n.d.ts → types-CueK0tvU.d.ts} +34 -11
- package/dist/vscode/index.d.ts +220 -3
- package/dist/vscode/index.js +382 -2
- package/dist/vscode/index.js.map +1 -1
- package/dist/workspace/index.d.ts +141 -4
- package/dist/workspace/index.js +28 -2
- package/dist/workspace/index.js.map +1 -1
- package/package.json +9 -5
- package/dist/chunk-2D7Y4IR3.js.map +0 -1
- package/dist/chunk-5MYAICRE.js.map +0 -1
- package/dist/chunk-AYZ4HN5M.js +0 -20
- package/dist/chunk-AYZ4HN5M.js.map +0 -1
- package/dist/chunk-GCPBEMMH.js.map +0 -1
- package/dist/chunk-J32GU3F3.js.map +0 -1
- package/dist/chunk-PGR7LK6D.js.map +0 -1
- package/dist/chunk-RQJRQF46.js.map +0 -1
- package/dist/chunk-SI2LU2RP.js.map +0 -1
- package/dist/chunk-W5UUUII5.js +0 -142
- package/dist/chunk-W5UUUII5.js.map +0 -1
- package/dist/document/document-session.d.ts +0 -127
- package/dist/document/document-session.d.ts.map +0 -1
- package/dist/document/document-session.js +0 -749
- package/dist/document/document-session.js.map +0 -1
- package/dist/document/filesystem-target.d.ts +0 -17
- package/dist/document/filesystem-target.d.ts.map +0 -1
- package/dist/document/filesystem-target.js +0 -70
- package/dist/document/filesystem-target.js.map +0 -1
- package/dist/document/index.d.ts.map +0 -1
- package/dist/document/recovery-journal.d.ts +0 -125
- package/dist/document/recovery-journal.d.ts.map +0 -1
- package/dist/document/recovery-journal.js +0 -385
- package/dist/document/recovery-journal.js.map +0 -1
- package/dist/document/types.d.ts +0 -89
- package/dist/document/types.d.ts.map +0 -1
- package/dist/document/types.js +0 -9
- package/dist/document/types.js.map +0 -1
- package/dist/filesystem/commit-lock.d.ts +0 -3
- package/dist/filesystem/commit-lock.d.ts.map +0 -1
- package/dist/filesystem/commit-lock.js +0 -20
- package/dist/filesystem/commit-lock.js.map +0 -1
- package/dist/filesystem/dbk-workspace.d.ts +0 -34
- package/dist/filesystem/dbk-workspace.d.ts.map +0 -1
- package/dist/filesystem/dbk-workspace.js +0 -85
- package/dist/filesystem/dbk-workspace.js.map +0 -1
- package/dist/filesystem/electron-provider-v2.d.ts +0 -36
- package/dist/filesystem/electron-provider-v2.d.ts.map +0 -1
- package/dist/filesystem/electron-provider-v2.js +0 -503
- package/dist/filesystem/electron-provider-v2.js.map +0 -1
- package/dist/filesystem/electron-provider.d.ts +0 -35
- package/dist/filesystem/electron-provider.d.ts.map +0 -1
- package/dist/filesystem/electron-provider.js +0 -69
- package/dist/filesystem/electron-provider.js.map +0 -1
- package/dist/filesystem/electron.d.ts.map +0 -1
- package/dist/filesystem/file-media-provider.d.ts +0 -23
- package/dist/filesystem/file-media-provider.d.ts.map +0 -1
- package/dist/filesystem/file-media-provider.js +0 -85
- package/dist/filesystem/file-media-provider.js.map +0 -1
- package/dist/filesystem/filesystem-content-container.d.ts +0 -24
- package/dist/filesystem/filesystem-content-container.d.ts.map +0 -1
- package/dist/filesystem/filesystem-content-container.js +0 -153
- package/dist/filesystem/filesystem-content-container.js.map +0 -1
- package/dist/filesystem/fs-error.d.ts +0 -46
- package/dist/filesystem/fs-error.d.ts.map +0 -1
- package/dist/filesystem/fs-error.js +0 -170
- package/dist/filesystem/fs-error.js.map +0 -1
- package/dist/filesystem/index.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-content-container.d.ts +0 -22
- package/dist/filesystem/indexeddb-content-container.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-content-container.js +0 -100
- package/dist/filesystem/indexeddb-content-container.js.map +0 -1
- package/dist/filesystem/indexeddb-provider-v2.d.ts +0 -96
- package/dist/filesystem/indexeddb-provider-v2.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-provider-v2.js +0 -1241
- package/dist/filesystem/indexeddb-provider-v2.js.map +0 -1
- package/dist/filesystem/indexeddb-provider.d.ts +0 -39
- package/dist/filesystem/indexeddb-provider.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-provider.js +0 -145
- package/dist/filesystem/indexeddb-provider.js.map +0 -1
- package/dist/filesystem/indexeddb-store.d.ts +0 -34
- package/dist/filesystem/indexeddb-store.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-store.js +0 -165
- package/dist/filesystem/indexeddb-store.js.map +0 -1
- package/dist/filesystem/indexeddb.d.ts.map +0 -1
- package/dist/filesystem/legacy-v2-adapter.d.ts +0 -62
- package/dist/filesystem/legacy-v2-adapter.d.ts.map +0 -1
- package/dist/filesystem/legacy-v2-adapter.js +0 -499
- package/dist/filesystem/legacy-v2-adapter.js.map +0 -1
- package/dist/filesystem/memory-provider-v2.d.ts +0 -92
- package/dist/filesystem/memory-provider-v2.d.ts.map +0 -1
- package/dist/filesystem/memory-provider-v2.js +0 -615
- package/dist/filesystem/memory-provider-v2.js.map +0 -1
- package/dist/filesystem/memory-provider.d.ts +0 -54
- package/dist/filesystem/memory-provider.d.ts.map +0 -1
- package/dist/filesystem/memory-provider.js +0 -132
- package/dist/filesystem/memory-provider.js.map +0 -1
- package/dist/filesystem/memory.d.ts.map +0 -1
- package/dist/filesystem/move-entry.d.ts +0 -9
- package/dist/filesystem/move-entry.d.ts.map +0 -1
- package/dist/filesystem/move-entry.js +0 -103
- package/dist/filesystem/move-entry.js.map +0 -1
- package/dist/filesystem/move-error.d.ts +0 -53
- package/dist/filesystem/move-error.d.ts.map +0 -1
- package/dist/filesystem/move-error.js +0 -99
- package/dist/filesystem/move-error.js.map +0 -1
- package/dist/filesystem/native-provider-v2.d.ts +0 -75
- package/dist/filesystem/native-provider-v2.d.ts.map +0 -1
- package/dist/filesystem/native-provider-v2.js +0 -849
- package/dist/filesystem/native-provider-v2.js.map +0 -1
- package/dist/filesystem/native-provider.d.ts +0 -53
- package/dist/filesystem/native-provider.d.ts.map +0 -1
- package/dist/filesystem/native-provider.js +0 -471
- package/dist/filesystem/native-provider.js.map +0 -1
- package/dist/filesystem/native.d.ts.map +0 -1
- package/dist/filesystem/types.d.ts +0 -83
- package/dist/filesystem/types.d.ts.map +0 -1
- package/dist/filesystem/types.js +0 -16
- package/dist/filesystem/types.js.map +0 -1
- package/dist/filesystem/v2.d.ts +0 -172
- package/dist/filesystem/v2.d.ts.map +0 -1
- package/dist/filesystem/v2.js +0 -16
- package/dist/filesystem/v2.js.map +0 -1
- package/dist/filesystem/workspace-path.d.ts +0 -21
- package/dist/filesystem/workspace-path.d.ts.map +0 -1
- package/dist/filesystem/workspace-path.js +0 -80
- package/dist/filesystem/workspace-path.js.map +0 -1
- package/dist/host/filesystem-v2.d.ts +0 -45
- package/dist/host/filesystem-v2.d.ts.map +0 -1
- package/dist/host/filesystem-v2.js +0 -13
- package/dist/host/filesystem-v2.js.map +0 -1
- package/dist/host/git.d.ts +0 -200
- package/dist/host/git.d.ts.map +0 -1
- package/dist/host/git.js +0 -15
- package/dist/host/git.js.map +0 -1
- package/dist/host/index.d.ts.map +0 -1
- package/dist/host/types.d.ts +0 -232
- package/dist/host/types.d.ts.map +0 -1
- package/dist/host/types.js +0 -10
- package/dist/host/types.js.map +0 -1
- package/dist/host/wire-policy.d.ts +0 -22
- package/dist/host/wire-policy.d.ts.map +0 -1
- package/dist/host/wire-policy.js +0 -92
- package/dist/host/wire-policy.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/types.d.ts +0 -466
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/mcp/types.js +0 -25
- package/dist/mcp/types.js.map +0 -1
- package/dist/mcp/wire.d.ts +0 -29
- package/dist/mcp/wire.d.ts.map +0 -1
- package/dist/mcp/wire.js +0 -1046
- package/dist/mcp/wire.js.map +0 -1
- package/dist/mcp/zod.d.ts.map +0 -1
- package/dist/vscode/index.d.ts.map +0 -1
- package/dist/vscode/messages.d.ts +0 -204
- package/dist/vscode/messages.d.ts.map +0 -1
- package/dist/vscode/messages.js +0 -494
- package/dist/vscode/messages.js.map +0 -1
- package/dist/workspace/index.d.ts.map +0 -1
- package/dist/workspace/reconcile-electron.d.ts +0 -19
- package/dist/workspace/reconcile-electron.d.ts.map +0 -1
- package/dist/workspace/reconcile-electron.js +0 -42
- package/dist/workspace/reconcile-electron.js.map +0 -1
- package/dist/workspace/types.d.ts +0 -69
- package/dist/workspace/types.d.ts.map +0 -1
- package/dist/workspace/types.js +0 -2
- package/dist/workspace/types.js.map +0 -1
- package/dist/workspace/workspace-manager.d.ts +0 -47
- package/dist/workspace/workspace-manager.d.ts.map +0 -1
- package/dist/workspace/workspace-manager.js +0 -126
- package/dist/workspace/workspace-manager.js.map +0 -1
- package/src/document/document-session.ts +0 -834
- package/src/document/filesystem-target.ts +0 -109
- package/src/document/index.ts +0 -41
- package/src/document/recovery-journal.ts +0 -536
- package/src/document/types.ts +0 -116
- package/src/filesystem/commit-lock.ts +0 -29
- package/src/filesystem/dbk-workspace.ts +0 -135
- package/src/filesystem/electron-provider-v2.ts +0 -630
- package/src/filesystem/electron-provider.ts +0 -99
- package/src/filesystem/electron.ts +0 -3
- package/src/filesystem/file-media-provider.ts +0 -103
- package/src/filesystem/filesystem-content-container.ts +0 -164
- package/src/filesystem/fs-error.ts +0 -234
- package/src/filesystem/index.ts +0 -143
- package/src/filesystem/indexeddb-content-container.ts +0 -112
- package/src/filesystem/indexeddb-provider-v2.ts +0 -1740
- package/src/filesystem/indexeddb-provider.ts +0 -171
- package/src/filesystem/indexeddb-store.ts +0 -207
- package/src/filesystem/indexeddb.ts +0 -12
- package/src/filesystem/legacy-v2-adapter.ts +0 -779
- package/src/filesystem/memory-provider-v2.ts +0 -896
- package/src/filesystem/memory-provider.ts +0 -180
- package/src/filesystem/memory.ts +0 -15
- package/src/filesystem/move-entry.ts +0 -142
- package/src/filesystem/move-error.ts +0 -159
- package/src/filesystem/native-provider-v2.ts +0 -1165
- package/src/filesystem/native-provider.ts +0 -537
- package/src/filesystem/native.ts +0 -16
- package/src/filesystem/types.ts +0 -114
- package/src/filesystem/v2.ts +0 -231
- package/src/filesystem/workspace-path.ts +0 -92
- package/src/host/filesystem-v2.ts +0 -104
- package/src/host/git.ts +0 -246
- package/src/host/index.ts +0 -93
- package/src/host/types.ts +0 -274
- package/src/host/wire-policy.ts +0 -103
- package/src/index.ts +0 -10
- package/src/mcp/index.ts +0 -3
- package/src/mcp/types.ts +0 -594
- package/src/mcp/wire.ts +0 -1280
- package/src/mcp/zod.ts +0 -1000
- package/src/vscode/index.ts +0 -2
- package/src/vscode/messages.ts +0 -704
- package/src/workspace/index.ts +0 -17
- package/src/workspace/reconcile-electron.ts +0 -65
- package/src/workspace/types.ts +0 -67
- package/src/workspace/workspace-manager.ts +0 -151
- /package/dist/{chunk-75UUF6C4.js.map → chunk-B56KWCSE.js.map} +0 -0
- /package/dist/{chunk-EGNDADXB.js.map → chunk-MNSZ7EZN.js.map} +0 -0
|
@@ -1,1165 +0,0 @@
|
|
|
1
|
-
import { withFileCommitLock } from './commit-lock.js';
|
|
2
|
-
import { FsError, fsErrorFromUnknown, type FsOperation } from './fs-error.js';
|
|
3
|
-
import {
|
|
4
|
-
parseFileSystemVersion,
|
|
5
|
-
type FileSystemCreateDirectoryOptions,
|
|
6
|
-
type FileSystemDirectorySnapshot,
|
|
7
|
-
type FileSystemEntrySnapshot,
|
|
8
|
-
type FileSystemFileRead,
|
|
9
|
-
type FileSystemFileSnapshot,
|
|
10
|
-
type FileSystemMoveOptions,
|
|
11
|
-
type FileSystemProviderCapabilities,
|
|
12
|
-
type FileSystemProviderV2,
|
|
13
|
-
type FileSystemRemoveOptions,
|
|
14
|
-
type FileSystemRemoveResult,
|
|
15
|
-
type FileSystemSnapshot,
|
|
16
|
-
type FileSystemSnapshotEntry,
|
|
17
|
-
type FileSystemSnapshotFile,
|
|
18
|
-
type FileSystemVersion,
|
|
19
|
-
type FileSystemWatchListener,
|
|
20
|
-
type FileSystemWatchOptions,
|
|
21
|
-
type FileSystemWatchSubscription,
|
|
22
|
-
type FileSystemWriteOptions,
|
|
23
|
-
} from './v2.js';
|
|
24
|
-
import {
|
|
25
|
-
WORKSPACE_ROOT,
|
|
26
|
-
parseWorkspacePath,
|
|
27
|
-
workspacePathBasename,
|
|
28
|
-
workspacePathContains,
|
|
29
|
-
workspacePathDirname,
|
|
30
|
-
workspacePathJoin,
|
|
31
|
-
type WorkspacePath,
|
|
32
|
-
} from './workspace-path.js';
|
|
33
|
-
|
|
34
|
-
interface ScannedEntry<TFile extends FileSystemFileSnapshot> {
|
|
35
|
-
readonly root: FileSystemDirectorySnapshot | TFile;
|
|
36
|
-
readonly entries: readonly (FileSystemDirectorySnapshot | TFile)[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type MetadataScan = ScannedEntry<FileSystemFileSnapshot>;
|
|
40
|
-
type SnapshotScan = ScannedEntry<FileSystemSnapshotFile>;
|
|
41
|
-
|
|
42
|
-
export type NativeFileSystemMovePathState = 'present' | 'missing' | 'unknown';
|
|
43
|
-
|
|
44
|
-
export interface NativeFileSystemMoveRecoveryState {
|
|
45
|
-
readonly source: NativeFileSystemMovePathState;
|
|
46
|
-
readonly destination: NativeFileSystemMovePathState;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* A copy/delete move failed and the provider could not prove that rollback
|
|
51
|
-
* restored the source-only state. Callers must inspect `state` before retrying.
|
|
52
|
-
*/
|
|
53
|
-
export class NativeFileSystemMoveRecoveryError extends FsError {
|
|
54
|
-
public readonly primaryError: FsError;
|
|
55
|
-
public readonly recoveryErrors: readonly FsError[];
|
|
56
|
-
public readonly state: NativeFileSystemMoveRecoveryState;
|
|
57
|
-
|
|
58
|
-
public constructor(
|
|
59
|
-
sourcePath: WorkspacePath,
|
|
60
|
-
destinationPath: WorkspacePath,
|
|
61
|
-
primaryError: FsError,
|
|
62
|
-
recoveryErrors: readonly FsError[],
|
|
63
|
-
state: NativeFileSystemMoveRecoveryState,
|
|
64
|
-
) {
|
|
65
|
-
super(
|
|
66
|
-
'io',
|
|
67
|
-
`Native move recovery is incomplete (source: ${state.source}, destination: ${state.destination}).`,
|
|
68
|
-
{
|
|
69
|
-
operation: 'move',
|
|
70
|
-
path: sourcePath,
|
|
71
|
-
destinationPath,
|
|
72
|
-
retryable: false,
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
this.name = 'NativeFileSystemMoveRecoveryError';
|
|
76
|
-
this.primaryError = primaryError;
|
|
77
|
-
this.recoveryErrors = Object.freeze([...recoveryErrors]);
|
|
78
|
-
this.state = Object.freeze({ ...state });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const EPOCH = new Date(0).toISOString();
|
|
83
|
-
|
|
84
|
-
const NATIVE_V2_CAPABILITIES: FileSystemProviderCapabilities = Object.freeze({
|
|
85
|
-
writeAtomicity: 'none',
|
|
86
|
-
moveAtomicity: 'none',
|
|
87
|
-
snapshotAtomicity: 'none',
|
|
88
|
-
conditionalWrite: 'process',
|
|
89
|
-
recursiveRemove: true,
|
|
90
|
-
watch: false,
|
|
91
|
-
caseSensitivity: 'platform',
|
|
92
|
-
symlinkPolicy: 'unsupported',
|
|
93
|
-
durability: 'best-effort',
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
/** Direct File System Access API implementation of FileSystemProviderV2. */
|
|
97
|
-
export class NativeFileSystemProviderV2 implements FileSystemProviderV2 {
|
|
98
|
-
public readonly id: string;
|
|
99
|
-
public readonly label: string;
|
|
100
|
-
public readonly capabilities = NATIVE_V2_CAPABILITIES;
|
|
101
|
-
|
|
102
|
-
private readonly root: FileSystemDirectoryHandle;
|
|
103
|
-
private readonly lockKey: string;
|
|
104
|
-
private readonly subscriptions = new Set<FileSystemWatchSubscription>();
|
|
105
|
-
private readonly inFlight = new Set<Promise<unknown>>();
|
|
106
|
-
private disposed = false;
|
|
107
|
-
private disposePromise: Promise<void> | null = null;
|
|
108
|
-
|
|
109
|
-
public constructor(id: string, root: FileSystemDirectoryHandle) {
|
|
110
|
-
this.id = id;
|
|
111
|
-
this.label = root.name;
|
|
112
|
-
this.root = root;
|
|
113
|
-
this.lockKey = `native:${id}:workspace`;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public async stat(path: WorkspacePath): Promise<FileSystemEntrySnapshot | null> {
|
|
117
|
-
const canonical = this.canonical(path);
|
|
118
|
-
return this.execute('stat', canonical, null, async () => {
|
|
119
|
-
const scanned = await this.tryScanMetadata(canonical, 'stat');
|
|
120
|
-
return scanned ? withoutData(scanned.root) : null;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public async readFile(path: WorkspacePath): Promise<FileSystemFileRead | null> {
|
|
125
|
-
const canonical = this.canonical(path);
|
|
126
|
-
return this.execute('read', canonical, null, async () => {
|
|
127
|
-
const handle = await this.getHandle(canonical);
|
|
128
|
-
if (!handle) return null;
|
|
129
|
-
if (handle.kind !== 'file') {
|
|
130
|
-
throw this.error('type-mismatch', 'read', canonical, 'Expected a file, found a directory.');
|
|
131
|
-
}
|
|
132
|
-
const scanned = await this.scanSnapshotHandle(canonical, handle, 'read');
|
|
133
|
-
if (scanned.root.kind !== 'file') {
|
|
134
|
-
throw this.error('io', 'read', canonical, 'Native file handle changed kind during read.');
|
|
135
|
-
}
|
|
136
|
-
return Object.freeze({
|
|
137
|
-
entry: withoutData(scanned.root) as FileSystemFileSnapshot,
|
|
138
|
-
data: scanned.root.data.slice(0),
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
public async readDirectory(path: WorkspacePath): Promise<readonly FileSystemEntrySnapshot[]> {
|
|
144
|
-
const canonical = this.canonical(path);
|
|
145
|
-
return this.execute('list', canonical, null, async () => {
|
|
146
|
-
const handle = await this.getHandle(canonical);
|
|
147
|
-
if (!handle) throw this.error('not-found', 'list', canonical, 'Directory does not exist.');
|
|
148
|
-
if (handle.kind !== 'directory') {
|
|
149
|
-
throw this.error('type-mismatch', 'list', canonical, 'Expected a directory, found a file.');
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const children: FileSystemEntrySnapshot[] = [];
|
|
153
|
-
for (const [name, childHandle] of await listDirectory(
|
|
154
|
-
handle as FileSystemDirectoryHandle,
|
|
155
|
-
'list',
|
|
156
|
-
canonical,
|
|
157
|
-
)) {
|
|
158
|
-
const childPath = workspacePathJoin(canonical, name);
|
|
159
|
-
children.push(
|
|
160
|
-
withoutData((await this.scanMetadataHandle(childPath, childHandle, 'list')).root),
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
children.sort(compareSnapshots);
|
|
164
|
-
return Object.freeze(children);
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
public async writeFile(
|
|
169
|
-
path: WorkspacePath,
|
|
170
|
-
data: ArrayBuffer | Uint8Array,
|
|
171
|
-
options: FileSystemWriteOptions = {},
|
|
172
|
-
): Promise<FileSystemFileSnapshot> {
|
|
173
|
-
const canonical = this.canonicalNonRoot(path, 'write');
|
|
174
|
-
const ownedData = copyBytes(data);
|
|
175
|
-
return this.mutate('write', canonical, null, async () => {
|
|
176
|
-
const mode = options.mode ?? 'upsert';
|
|
177
|
-
if (mode !== 'upsert' && mode !== 'create' && mode !== 'replace') {
|
|
178
|
-
throw this.error('invalid-path', 'write', canonical, 'Invalid write mode.');
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const existing = await this.tryScanMetadata(canonical, 'write');
|
|
182
|
-
if (existing?.root.kind === 'directory') {
|
|
183
|
-
throw this.error(
|
|
184
|
-
'type-mismatch',
|
|
185
|
-
'write',
|
|
186
|
-
canonical,
|
|
187
|
-
'Cannot replace a directory with a file.',
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
if (mode === 'create' && existing) {
|
|
191
|
-
throw this.error('already-exists', 'write', canonical, 'File already exists.');
|
|
192
|
-
}
|
|
193
|
-
if (mode === 'replace' && !existing) {
|
|
194
|
-
throw this.error('not-found', 'write', canonical, 'File does not exist.');
|
|
195
|
-
}
|
|
196
|
-
this.assertExpectedVersion(existing?.root, options.expectedVersion, 'write', canonical);
|
|
197
|
-
|
|
198
|
-
const missingParents = await this.planParents(
|
|
199
|
-
canonical,
|
|
200
|
-
options.createParents ?? false,
|
|
201
|
-
'write',
|
|
202
|
-
);
|
|
203
|
-
const createdParents = await this.createDirectories(missingParents);
|
|
204
|
-
let writeCompleted = false;
|
|
205
|
-
try {
|
|
206
|
-
await this.writeBytes(canonical, ownedData);
|
|
207
|
-
writeCompleted = true;
|
|
208
|
-
const written = await this.requireSnapshot(canonical, 'write');
|
|
209
|
-
if (written.root.kind !== 'file' || !equalBytes(written.root.data, ownedData)) {
|
|
210
|
-
throw this.error(
|
|
211
|
-
'conflict',
|
|
212
|
-
'write',
|
|
213
|
-
canonical,
|
|
214
|
-
'Stored bytes changed before the write could be verified.',
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
return withoutData(written.root) as FileSystemFileSnapshot;
|
|
218
|
-
} catch (error: unknown) {
|
|
219
|
-
if (!existing && !writeCompleted) {
|
|
220
|
-
await this.removeEmptyFileIfPresent(canonical).catch(() => undefined);
|
|
221
|
-
}
|
|
222
|
-
await this.rollbackDirectories(createdParents);
|
|
223
|
-
throw error;
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
public async createDirectory(
|
|
229
|
-
path: WorkspacePath,
|
|
230
|
-
options: FileSystemCreateDirectoryOptions = {},
|
|
231
|
-
): Promise<FileSystemDirectorySnapshot> {
|
|
232
|
-
const canonical = this.canonical(path);
|
|
233
|
-
return this.mutate('create-directory', canonical, null, async () => {
|
|
234
|
-
const mode = options.mode ?? 'ensure';
|
|
235
|
-
if (mode !== 'ensure' && mode !== 'create') {
|
|
236
|
-
throw this.error('invalid-path', 'create-directory', canonical, 'Invalid directory mode.');
|
|
237
|
-
}
|
|
238
|
-
const existing = await this.tryScanMetadata(canonical, 'create-directory');
|
|
239
|
-
if (existing) {
|
|
240
|
-
if (existing.root.kind !== 'directory') {
|
|
241
|
-
throw this.error(
|
|
242
|
-
'type-mismatch',
|
|
243
|
-
'create-directory',
|
|
244
|
-
canonical,
|
|
245
|
-
'Cannot replace a file with a directory.',
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
if (mode === 'create') {
|
|
249
|
-
throw this.error(
|
|
250
|
-
'already-exists',
|
|
251
|
-
'create-directory',
|
|
252
|
-
canonical,
|
|
253
|
-
'Directory already exists.',
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
return withoutData(existing.root) as FileSystemDirectorySnapshot;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const missingParents = await this.planParents(
|
|
260
|
-
canonical,
|
|
261
|
-
options.createParents ?? false,
|
|
262
|
-
'create-directory',
|
|
263
|
-
);
|
|
264
|
-
const planned = [...missingParents, canonical];
|
|
265
|
-
const created = await this.createDirectories(planned);
|
|
266
|
-
try {
|
|
267
|
-
const scanned = await this.requireMetadata(canonical, 'create-directory');
|
|
268
|
-
if (scanned.root.kind !== 'directory') {
|
|
269
|
-
throw this.error(
|
|
270
|
-
'io',
|
|
271
|
-
'create-directory',
|
|
272
|
-
canonical,
|
|
273
|
-
'The native backend did not create a directory.',
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
return withoutData(scanned.root) as FileSystemDirectorySnapshot;
|
|
277
|
-
} catch (error: unknown) {
|
|
278
|
-
await this.rollbackDirectories(created);
|
|
279
|
-
throw error;
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
public async remove(
|
|
285
|
-
path: WorkspacePath,
|
|
286
|
-
options: FileSystemRemoveOptions = {},
|
|
287
|
-
): Promise<FileSystemRemoveResult> {
|
|
288
|
-
const canonical = this.canonicalNonRoot(path, 'remove');
|
|
289
|
-
return this.mutate('remove', canonical, null, async () => {
|
|
290
|
-
const existing = await this.tryScanMetadata(canonical, 'remove');
|
|
291
|
-
if (!existing) {
|
|
292
|
-
if ((options.missing ?? 'error') === 'ignore') {
|
|
293
|
-
return Object.freeze({
|
|
294
|
-
removed: false,
|
|
295
|
-
version: await this.currentTreeVersion('remove'),
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
throw this.error('not-found', 'remove', canonical, 'Entry does not exist.');
|
|
299
|
-
}
|
|
300
|
-
this.assertExpectedVersion(existing.root, options.expectedVersion, 'remove', canonical);
|
|
301
|
-
if (existing.root.kind === 'directory' && !options.recursive) {
|
|
302
|
-
const handle = await this.getHandle(canonical);
|
|
303
|
-
if (!handle || handle.kind !== 'directory') {
|
|
304
|
-
throw this.error('conflict', 'remove', canonical, 'Directory changed before removal.');
|
|
305
|
-
}
|
|
306
|
-
if (
|
|
307
|
-
(await listDirectory(handle as FileSystemDirectoryHandle, 'remove', canonical)).length > 0
|
|
308
|
-
) {
|
|
309
|
-
throw this.error('not-empty', 'remove', canonical, 'Directory is not empty.');
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
await this.removeEntry(canonical, existing.root.kind === 'directory' && !!options.recursive);
|
|
314
|
-
if (await this.getHandle(canonical)) {
|
|
315
|
-
throw this.error('conflict', 'remove', canonical, 'Entry was recreated during removal.');
|
|
316
|
-
}
|
|
317
|
-
return Object.freeze({
|
|
318
|
-
removed: true,
|
|
319
|
-
version: await this.currentTreeVersion('remove'),
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
public async move(
|
|
325
|
-
oldPath: WorkspacePath,
|
|
326
|
-
newPath: WorkspacePath,
|
|
327
|
-
options: FileSystemMoveOptions = {},
|
|
328
|
-
): Promise<FileSystemEntrySnapshot> {
|
|
329
|
-
const sourcePath = this.canonicalNonRoot(oldPath, 'move');
|
|
330
|
-
const destinationPath = this.canonicalNonRoot(newPath, 'move');
|
|
331
|
-
return this.mutate('move', sourcePath, destinationPath, async () => {
|
|
332
|
-
const sourceMetadata = await this.tryScanMetadata(sourcePath, 'move');
|
|
333
|
-
if (!sourceMetadata) {
|
|
334
|
-
throw this.error('not-found', 'move', sourcePath, 'Source does not exist.');
|
|
335
|
-
}
|
|
336
|
-
this.assertExpectedVersion(sourceMetadata.root, options.expectedVersion, 'move', sourcePath);
|
|
337
|
-
if (sourcePath === destinationPath) return withoutData(sourceMetadata.root);
|
|
338
|
-
if (
|
|
339
|
-
sourceMetadata.root.kind === 'directory' &&
|
|
340
|
-
workspacePathContains(sourcePath, destinationPath, false)
|
|
341
|
-
) {
|
|
342
|
-
throw new FsError('invalid-path', 'Cannot move a directory into itself.', {
|
|
343
|
-
operation: 'move',
|
|
344
|
-
path: sourcePath,
|
|
345
|
-
destinationPath,
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
if (await this.getHandle(destinationPath)) {
|
|
349
|
-
throw new FsError('already-exists', 'Destination already exists.', {
|
|
350
|
-
operation: 'move',
|
|
351
|
-
path: sourcePath,
|
|
352
|
-
destinationPath,
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const missingParents = await this.planParents(
|
|
357
|
-
destinationPath,
|
|
358
|
-
options.createParents ?? false,
|
|
359
|
-
'move',
|
|
360
|
-
);
|
|
361
|
-
const source = await this.tryScanSnapshot(sourcePath, 'move');
|
|
362
|
-
if (
|
|
363
|
-
!source ||
|
|
364
|
-
source.root.kind !== sourceMetadata.root.kind ||
|
|
365
|
-
source.root.version !== sourceMetadata.root.version
|
|
366
|
-
) {
|
|
367
|
-
throw new FsError('conflict', 'Source changed before the move could be copied.', {
|
|
368
|
-
operation: 'move',
|
|
369
|
-
path: sourcePath,
|
|
370
|
-
destinationPath,
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
const createdParents = await this.createDirectories(missingParents);
|
|
374
|
-
let destinationVersion: FileSystemVersion | null = null;
|
|
375
|
-
let sourceDeleted = false;
|
|
376
|
-
try {
|
|
377
|
-
await this.writeTree(source, sourcePath, destinationPath);
|
|
378
|
-
const copied = await this.requireSnapshot(destinationPath, 'move');
|
|
379
|
-
destinationVersion = copied.root.version;
|
|
380
|
-
if (!equalTreeContents(source, sourcePath, copied, destinationPath)) {
|
|
381
|
-
throw new FsError('conflict', 'Destination changed while the move was copied.', {
|
|
382
|
-
operation: 'move',
|
|
383
|
-
path: sourcePath,
|
|
384
|
-
destinationPath,
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const sourceBeforeDelete = await this.tryScanMetadata(sourcePath, 'move');
|
|
389
|
-
if (
|
|
390
|
-
!sourceBeforeDelete ||
|
|
391
|
-
sourceBeforeDelete.root.kind !== source.root.kind ||
|
|
392
|
-
sourceBeforeDelete.root.version !== source.root.version
|
|
393
|
-
) {
|
|
394
|
-
throw new FsError('conflict', 'Source changed while the move was copied.', {
|
|
395
|
-
operation: 'move',
|
|
396
|
-
path: sourcePath,
|
|
397
|
-
destinationPath,
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
await this.removeEntry(sourcePath, source.root.kind === 'directory');
|
|
402
|
-
sourceDeleted = true;
|
|
403
|
-
const [sourceAfter, destinationAfter] = await Promise.all([
|
|
404
|
-
this.tryScanMetadata(sourcePath, 'move'),
|
|
405
|
-
this.tryScanMetadata(destinationPath, 'move'),
|
|
406
|
-
]);
|
|
407
|
-
if (
|
|
408
|
-
sourceAfter ||
|
|
409
|
-
!destinationAfter ||
|
|
410
|
-
destinationAfter.root.kind !== source.root.kind ||
|
|
411
|
-
destinationAfter.root.version !== destinationVersion
|
|
412
|
-
) {
|
|
413
|
-
throw new FsError('conflict', 'Move state changed before it could be verified.', {
|
|
414
|
-
operation: 'move',
|
|
415
|
-
path: sourcePath,
|
|
416
|
-
destinationPath,
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
return withoutData(destinationAfter.root);
|
|
420
|
-
} catch (error: unknown) {
|
|
421
|
-
return await this.rollbackMoveAndThrow(
|
|
422
|
-
sourcePath,
|
|
423
|
-
destinationPath,
|
|
424
|
-
source,
|
|
425
|
-
createdParents,
|
|
426
|
-
destinationVersion,
|
|
427
|
-
sourceDeleted,
|
|
428
|
-
error,
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
public async snapshot(): Promise<FileSystemSnapshot> {
|
|
435
|
-
return this.mutate('snapshot', WORKSPACE_ROOT, null, async () => {
|
|
436
|
-
const scanned = await this.scanSnapshotHandle(WORKSPACE_ROOT, this.root, 'snapshot');
|
|
437
|
-
const entries = [...scanned.entries]
|
|
438
|
-
.sort((left, right) => compareText(left.path, right.path))
|
|
439
|
-
.map(copySnapshotEntry);
|
|
440
|
-
return Object.freeze({ version: scanned.root.version, entries: Object.freeze(entries) });
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
public watch(
|
|
445
|
-
_listener: FileSystemWatchListener,
|
|
446
|
-
options: FileSystemWatchOptions = {},
|
|
447
|
-
): FileSystemWatchSubscription {
|
|
448
|
-
this.assertOpen('watch');
|
|
449
|
-
const error = new FsError('not-supported', 'Native filesystem watching is unavailable.', {
|
|
450
|
-
operation: 'watch',
|
|
451
|
-
});
|
|
452
|
-
let closed = false;
|
|
453
|
-
let disposePromise: Promise<void> | null = null;
|
|
454
|
-
const ready = Promise.reject(error);
|
|
455
|
-
void ready.catch((caught: FsError) => {
|
|
456
|
-
try {
|
|
457
|
-
options.onError?.(caught);
|
|
458
|
-
} catch {
|
|
459
|
-
// Observers cannot change provider state.
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
const subscription: FileSystemWatchSubscription = {
|
|
463
|
-
get closed() {
|
|
464
|
-
return closed;
|
|
465
|
-
},
|
|
466
|
-
ready,
|
|
467
|
-
dispose: () => {
|
|
468
|
-
if (disposePromise) return disposePromise;
|
|
469
|
-
closed = true;
|
|
470
|
-
this.subscriptions.delete(subscription);
|
|
471
|
-
disposePromise = Promise.resolve();
|
|
472
|
-
return disposePromise;
|
|
473
|
-
},
|
|
474
|
-
};
|
|
475
|
-
this.subscriptions.add(subscription);
|
|
476
|
-
return subscription;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
public dispose(): Promise<void> {
|
|
480
|
-
if (this.disposePromise) return this.disposePromise;
|
|
481
|
-
this.disposed = true;
|
|
482
|
-
this.disposePromise = (async () => {
|
|
483
|
-
await Promise.allSettled([...this.inFlight]);
|
|
484
|
-
await Promise.all([...this.subscriptions].map((subscription) => subscription.dispose()));
|
|
485
|
-
})();
|
|
486
|
-
return this.disposePromise;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
private canonical(path: WorkspacePath): WorkspacePath {
|
|
490
|
-
return parseWorkspacePath(String(path));
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
private canonicalNonRoot(path: WorkspacePath, operation: FsOperation): WorkspacePath {
|
|
494
|
-
const canonical = this.canonical(path);
|
|
495
|
-
if (!canonical) {
|
|
496
|
-
throw this.error('invalid-path', operation, canonical, 'Workspace root cannot be mutated.');
|
|
497
|
-
}
|
|
498
|
-
return canonical;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
private execute<T>(
|
|
502
|
-
operation: FsOperation,
|
|
503
|
-
path: WorkspacePath | null,
|
|
504
|
-
destinationPath: WorkspacePath | null,
|
|
505
|
-
work: () => Promise<T>,
|
|
506
|
-
): Promise<T> {
|
|
507
|
-
this.assertOpen(operation);
|
|
508
|
-
const promise = (async () => {
|
|
509
|
-
try {
|
|
510
|
-
return await work();
|
|
511
|
-
} catch (error: unknown) {
|
|
512
|
-
throw this.translateError(error, operation, path, destinationPath);
|
|
513
|
-
}
|
|
514
|
-
})();
|
|
515
|
-
this.inFlight.add(promise);
|
|
516
|
-
void promise.then(
|
|
517
|
-
() => this.inFlight.delete(promise),
|
|
518
|
-
() => this.inFlight.delete(promise),
|
|
519
|
-
);
|
|
520
|
-
return promise;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
private mutate<T>(
|
|
524
|
-
operation: FsOperation,
|
|
525
|
-
path: WorkspacePath,
|
|
526
|
-
destinationPath: WorkspacePath | null,
|
|
527
|
-
work: () => Promise<T>,
|
|
528
|
-
): Promise<T> {
|
|
529
|
-
return this.execute(operation, path, destinationPath, () =>
|
|
530
|
-
withFileCommitLock(this.lockKey, work),
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
private assertOpen(operation: FsOperation): void {
|
|
535
|
-
if (!this.disposed) return;
|
|
536
|
-
throw new FsError('disposed', 'Filesystem provider is disposed.', { operation });
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
private translateError(
|
|
540
|
-
error: unknown,
|
|
541
|
-
operation: FsOperation,
|
|
542
|
-
path: WorkspacePath | null,
|
|
543
|
-
destinationPath: WorkspacePath | null,
|
|
544
|
-
): FsError {
|
|
545
|
-
if (error instanceof FsError) return error;
|
|
546
|
-
return fsErrorFromUnknown(error, {
|
|
547
|
-
operation,
|
|
548
|
-
path: path ?? undefined,
|
|
549
|
-
destinationPath: destinationPath ?? undefined,
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
private error(
|
|
554
|
-
code: ConstructorParameters<typeof FsError>[0],
|
|
555
|
-
operation: FsOperation,
|
|
556
|
-
path: WorkspacePath,
|
|
557
|
-
message: string,
|
|
558
|
-
): FsError {
|
|
559
|
-
return new FsError(code, message, { operation, path });
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
private assertExpectedVersion(
|
|
563
|
-
entry: FileSystemEntrySnapshot | undefined,
|
|
564
|
-
expected: FileSystemVersion | null | undefined,
|
|
565
|
-
operation: FsOperation,
|
|
566
|
-
path: WorkspacePath,
|
|
567
|
-
): void {
|
|
568
|
-
if (expected === undefined) return;
|
|
569
|
-
if (expected === null ? !entry : entry?.version === expected) return;
|
|
570
|
-
throw this.error(
|
|
571
|
-
'conflict',
|
|
572
|
-
operation,
|
|
573
|
-
path,
|
|
574
|
-
'Entry version does not match the expected version.',
|
|
575
|
-
);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
private async resolveDirectory(path: WorkspacePath): Promise<FileSystemDirectoryHandle | null> {
|
|
579
|
-
if (!path) return this.root;
|
|
580
|
-
let current = this.root;
|
|
581
|
-
for (const segment of path.split('/')) {
|
|
582
|
-
try {
|
|
583
|
-
current = await current.getDirectoryHandle(segment);
|
|
584
|
-
} catch (error: unknown) {
|
|
585
|
-
if (errorName(error) === 'NotFoundError') return null;
|
|
586
|
-
throw error;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
return current;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
private async getHandle(path: WorkspacePath): Promise<FileSystemHandle | null> {
|
|
593
|
-
if (!path) return this.root;
|
|
594
|
-
const parent = await this.resolveDirectory(workspacePathDirname(path));
|
|
595
|
-
if (!parent) return null;
|
|
596
|
-
const name = workspacePathBasename(path);
|
|
597
|
-
try {
|
|
598
|
-
return await parent.getFileHandle(name);
|
|
599
|
-
} catch (error: unknown) {
|
|
600
|
-
if (!isMissingOrKindError(error)) throw error;
|
|
601
|
-
}
|
|
602
|
-
try {
|
|
603
|
-
return await parent.getDirectoryHandle(name);
|
|
604
|
-
} catch (error: unknown) {
|
|
605
|
-
if (!isMissingOrKindError(error)) throw error;
|
|
606
|
-
return null;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
private async tryScanMetadata(
|
|
611
|
-
path: WorkspacePath,
|
|
612
|
-
operation: FsOperation,
|
|
613
|
-
): Promise<MetadataScan | null> {
|
|
614
|
-
const handle = await this.getHandle(path);
|
|
615
|
-
return handle ? this.scanMetadataHandle(path, handle, operation) : null;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
private async tryScanSnapshot(
|
|
619
|
-
path: WorkspacePath,
|
|
620
|
-
operation: FsOperation,
|
|
621
|
-
): Promise<SnapshotScan | null> {
|
|
622
|
-
const handle = await this.getHandle(path);
|
|
623
|
-
return handle ? this.scanSnapshotHandle(path, handle, operation) : null;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
private async requireMetadata(
|
|
627
|
-
path: WorkspacePath,
|
|
628
|
-
operation: FsOperation,
|
|
629
|
-
): Promise<MetadataScan> {
|
|
630
|
-
const scanned = await this.tryScanMetadata(path, operation);
|
|
631
|
-
if (!scanned) throw this.error('not-found', operation, path, 'Entry does not exist.');
|
|
632
|
-
return scanned;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
private async requireSnapshot(
|
|
636
|
-
path: WorkspacePath,
|
|
637
|
-
operation: FsOperation,
|
|
638
|
-
): Promise<SnapshotScan> {
|
|
639
|
-
const scanned = await this.tryScanSnapshot(path, operation);
|
|
640
|
-
if (!scanned) throw this.error('not-found', operation, path, 'Entry does not exist.');
|
|
641
|
-
return scanned;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
private scanMetadataHandle(
|
|
645
|
-
path: WorkspacePath,
|
|
646
|
-
handle: FileSystemHandle,
|
|
647
|
-
operation: FsOperation,
|
|
648
|
-
): Promise<MetadataScan> {
|
|
649
|
-
// File snapshots expose stable size/lastModified metadata without reading payload bytes.
|
|
650
|
-
// Keep stat/list/version checks on this path so directory scans scale with entries, not bytes.
|
|
651
|
-
return this.scanHandle(path, handle, operation, (filePath, fileHandle) =>
|
|
652
|
-
this.scanFileMetadata(filePath, fileHandle, operation),
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
private scanSnapshotHandle(
|
|
657
|
-
path: WorkspacePath,
|
|
658
|
-
handle: FileSystemHandle,
|
|
659
|
-
operation: FsOperation,
|
|
660
|
-
): Promise<SnapshotScan> {
|
|
661
|
-
return this.scanHandle(path, handle, operation, (filePath, fileHandle) =>
|
|
662
|
-
this.scanFileSnapshot(filePath, fileHandle, operation),
|
|
663
|
-
);
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
private async scanHandle<TFile extends FileSystemFileSnapshot>(
|
|
667
|
-
path: WorkspacePath,
|
|
668
|
-
handle: FileSystemHandle,
|
|
669
|
-
operation: FsOperation,
|
|
670
|
-
scanFile: (path: WorkspacePath, handle: FileSystemFileHandle) => Promise<TFile>,
|
|
671
|
-
): Promise<ScannedEntry<TFile>> {
|
|
672
|
-
if (handle.kind === 'file') {
|
|
673
|
-
const entry = await scanFile(path, handle as FileSystemFileHandle);
|
|
674
|
-
return { root: entry, entries: Object.freeze([entry]) };
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
const children: ScannedEntry<TFile>[] = [];
|
|
678
|
-
for (const [name, childHandle] of await listDirectory(
|
|
679
|
-
handle as FileSystemDirectoryHandle,
|
|
680
|
-
operation,
|
|
681
|
-
path,
|
|
682
|
-
)) {
|
|
683
|
-
children.push(
|
|
684
|
-
await this.scanHandle(workspacePathJoin(path, name), childHandle, operation, scanFile),
|
|
685
|
-
);
|
|
686
|
-
}
|
|
687
|
-
const childRoots = children.map((child) => child.root).sort(compareSnapshots);
|
|
688
|
-
const version = await metadataVersion(
|
|
689
|
-
'directory',
|
|
690
|
-
new TextEncoder().encode(
|
|
691
|
-
childRoots
|
|
692
|
-
.map((child) => `${child.kind}\0${child.name.length}:${child.name}\0${child.version}`)
|
|
693
|
-
.join('\n'),
|
|
694
|
-
),
|
|
695
|
-
operation,
|
|
696
|
-
path,
|
|
697
|
-
);
|
|
698
|
-
const directory: FileSystemDirectorySnapshot = Object.freeze({
|
|
699
|
-
kind: 'directory' as const,
|
|
700
|
-
path,
|
|
701
|
-
name: workspacePathBasename(path),
|
|
702
|
-
size: null,
|
|
703
|
-
version,
|
|
704
|
-
lastModified: newestLastModified(childRoots),
|
|
705
|
-
});
|
|
706
|
-
return {
|
|
707
|
-
root: directory,
|
|
708
|
-
entries: Object.freeze([directory, ...children.flatMap((child) => child.entries)]),
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
private async scanFileMetadata(
|
|
713
|
-
path: WorkspacePath,
|
|
714
|
-
handle: FileSystemFileHandle,
|
|
715
|
-
operation: FsOperation,
|
|
716
|
-
): Promise<FileSystemFileSnapshot> {
|
|
717
|
-
const file = await this.getFileSnapshot(handle, path, operation);
|
|
718
|
-
return this.fileMetadata(file, path, operation);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
private async scanFileSnapshot(
|
|
722
|
-
path: WorkspacePath,
|
|
723
|
-
handle: FileSystemFileHandle,
|
|
724
|
-
operation: FsOperation,
|
|
725
|
-
): Promise<FileSystemSnapshotFile> {
|
|
726
|
-
const file = await this.getFileSnapshot(handle, path, operation);
|
|
727
|
-
const metadata = await this.fileMetadata(file, path, operation);
|
|
728
|
-
let data: ArrayBuffer;
|
|
729
|
-
try {
|
|
730
|
-
data = copyBytes(await file.arrayBuffer());
|
|
731
|
-
} catch (error: unknown) {
|
|
732
|
-
throw this.translateError(error, operation, path, null);
|
|
733
|
-
}
|
|
734
|
-
if (metadata.size !== data.byteLength) {
|
|
735
|
-
throw this.error('io', operation, path, 'Native file metadata is inconsistent.');
|
|
736
|
-
}
|
|
737
|
-
return Object.freeze({ ...metadata, data });
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
private async getFileSnapshot(
|
|
741
|
-
handle: FileSystemFileHandle,
|
|
742
|
-
path: WorkspacePath,
|
|
743
|
-
operation: FsOperation,
|
|
744
|
-
): Promise<File> {
|
|
745
|
-
try {
|
|
746
|
-
return await handle.getFile();
|
|
747
|
-
} catch (error: unknown) {
|
|
748
|
-
throw this.translateError(error, operation, path, null);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
private async fileMetadata(
|
|
753
|
-
file: File,
|
|
754
|
-
path: WorkspacePath,
|
|
755
|
-
operation: FsOperation,
|
|
756
|
-
): Promise<FileSystemFileSnapshot> {
|
|
757
|
-
if (!Number.isSafeInteger(file.size) || file.size < 0 || !Number.isFinite(file.lastModified)) {
|
|
758
|
-
throw this.error('io', operation, path, 'Native file metadata is inconsistent.');
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
let lastModified: string;
|
|
762
|
-
try {
|
|
763
|
-
lastModified = new Date(file.lastModified).toISOString();
|
|
764
|
-
} catch {
|
|
765
|
-
throw this.error('io', operation, path, 'Native file metadata is inconsistent.');
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
return Object.freeze({
|
|
769
|
-
kind: 'file',
|
|
770
|
-
path,
|
|
771
|
-
name: workspacePathBasename(path),
|
|
772
|
-
size: file.size,
|
|
773
|
-
version: await metadataVersion(
|
|
774
|
-
'file',
|
|
775
|
-
new TextEncoder().encode(`${file.size}\0${file.lastModified}`),
|
|
776
|
-
operation,
|
|
777
|
-
path,
|
|
778
|
-
),
|
|
779
|
-
lastModified,
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
private async planParents(
|
|
784
|
-
path: WorkspacePath,
|
|
785
|
-
createParents: boolean,
|
|
786
|
-
operation: FsOperation,
|
|
787
|
-
): Promise<WorkspacePath[]> {
|
|
788
|
-
const missing: WorkspacePath[] = [];
|
|
789
|
-
for (const parent of parentChain(path)) {
|
|
790
|
-
const handle = await this.getHandle(parent);
|
|
791
|
-
if (handle?.kind === 'file') {
|
|
792
|
-
throw this.error('type-mismatch', operation, parent, 'A parent path is a file.');
|
|
793
|
-
}
|
|
794
|
-
if (!handle) {
|
|
795
|
-
if (!createParents) {
|
|
796
|
-
throw this.error('not-found', operation, parent, 'Parent directory does not exist.');
|
|
797
|
-
}
|
|
798
|
-
missing.push(parent);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
return missing;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
private async createDirectories(paths: readonly WorkspacePath[]): Promise<WorkspacePath[]> {
|
|
805
|
-
const created: WorkspacePath[] = [];
|
|
806
|
-
try {
|
|
807
|
-
for (const path of paths) {
|
|
808
|
-
if (!path) continue;
|
|
809
|
-
const parent = await this.resolveDirectory(workspacePathDirname(path));
|
|
810
|
-
if (!parent) {
|
|
811
|
-
throw new DOMException('Parent directory does not exist.', 'NotFoundError');
|
|
812
|
-
}
|
|
813
|
-
await parent.getDirectoryHandle(workspacePathBasename(path), { create: true });
|
|
814
|
-
created.push(path);
|
|
815
|
-
}
|
|
816
|
-
return created;
|
|
817
|
-
} catch (error: unknown) {
|
|
818
|
-
await this.rollbackDirectories(created);
|
|
819
|
-
throw error;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
private async rollbackDirectories(paths: readonly WorkspacePath[]): Promise<void> {
|
|
824
|
-
for (const path of [...paths].reverse()) {
|
|
825
|
-
try {
|
|
826
|
-
await this.removeEntry(path, false);
|
|
827
|
-
} catch {
|
|
828
|
-
// Best effort: a non-empty directory may now contain external data.
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
private async writeBytes(path: WorkspacePath, data: ArrayBuffer): Promise<void> {
|
|
834
|
-
const parent = await this.resolveDirectory(workspacePathDirname(path));
|
|
835
|
-
if (!parent) throw new DOMException('Parent directory does not exist.', 'NotFoundError');
|
|
836
|
-
const fileHandle = await parent.getFileHandle(workspacePathBasename(path), { create: true });
|
|
837
|
-
const writable = await fileHandle.createWritable();
|
|
838
|
-
await writeAndClose(writable, data);
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
private async removeEntry(path: WorkspacePath, recursive: boolean): Promise<void> {
|
|
842
|
-
const parent = await this.resolveDirectory(workspacePathDirname(path));
|
|
843
|
-
if (!parent) throw new DOMException('Parent directory does not exist.', 'NotFoundError');
|
|
844
|
-
await parent.removeEntry(workspacePathBasename(path), { recursive });
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
private async removeEmptyFileIfPresent(path: WorkspacePath): Promise<void> {
|
|
848
|
-
const current = await this.tryScanMetadata(path, 'write');
|
|
849
|
-
if (current?.root.kind !== 'file' || current.root.size !== 0) return;
|
|
850
|
-
await this.removeEntry(path, false);
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
private async currentTreeVersion(operation: FsOperation): Promise<FileSystemVersion> {
|
|
854
|
-
return (await this.scanMetadataHandle(WORKSPACE_ROOT, this.root, operation)).root.version;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
private async writeTree(
|
|
858
|
-
source: SnapshotScan,
|
|
859
|
-
sourcePath: WorkspacePath,
|
|
860
|
-
destinationPath: WorkspacePath,
|
|
861
|
-
): Promise<void> {
|
|
862
|
-
const remapped = source.entries.map((entry) => {
|
|
863
|
-
const suffix = entry.path.slice(sourcePath.length);
|
|
864
|
-
return [entry, parseWorkspacePath(`${destinationPath}${suffix}`)] as const;
|
|
865
|
-
});
|
|
866
|
-
const directories = remapped
|
|
867
|
-
.filter(
|
|
868
|
-
(item): item is readonly [FileSystemDirectorySnapshot, WorkspacePath] =>
|
|
869
|
-
item[0].kind === 'directory',
|
|
870
|
-
)
|
|
871
|
-
.sort((left, right) => pathDepth(left[1]) - pathDepth(right[1]));
|
|
872
|
-
for (const [, path] of directories) {
|
|
873
|
-
const parent = await this.resolveDirectory(workspacePathDirname(path));
|
|
874
|
-
if (!parent) throw new DOMException('Parent directory does not exist.', 'NotFoundError');
|
|
875
|
-
await parent.getDirectoryHandle(workspacePathBasename(path), { create: true });
|
|
876
|
-
}
|
|
877
|
-
for (const [entry, path] of remapped) {
|
|
878
|
-
if (entry.kind === 'file') await this.writeBytes(path, entry.data);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
private async rollbackMoveAndThrow(
|
|
883
|
-
sourcePath: WorkspacePath,
|
|
884
|
-
destinationPath: WorkspacePath,
|
|
885
|
-
source: SnapshotScan,
|
|
886
|
-
createdParents: readonly WorkspacePath[],
|
|
887
|
-
destinationVersion: FileSystemVersion | null,
|
|
888
|
-
sourceDeleted: boolean,
|
|
889
|
-
primary: unknown,
|
|
890
|
-
): Promise<never> {
|
|
891
|
-
const primaryError = this.translateError(primary, 'move', sourcePath, destinationPath);
|
|
892
|
-
const recoveryErrors: FsError[] = [];
|
|
893
|
-
|
|
894
|
-
const sourceCurrent = await this.probeScan(sourcePath);
|
|
895
|
-
if (sourceCurrent === null && sourceDeleted) {
|
|
896
|
-
try {
|
|
897
|
-
await this.writeTree(source, sourcePath, sourcePath);
|
|
898
|
-
const restored = await this.probeSnapshot(sourcePath);
|
|
899
|
-
if (!restored || !equalTreeContents(source, sourcePath, restored, sourcePath)) {
|
|
900
|
-
throw new FsError('conflict', 'Restored source does not match its captured state.', {
|
|
901
|
-
operation: 'move',
|
|
902
|
-
path: sourcePath,
|
|
903
|
-
destinationPath,
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
} catch (error: unknown) {
|
|
907
|
-
recoveryErrors.push(this.translateError(error, 'move', sourcePath, destinationPath));
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
const destinationCurrent = await this.probeScan(destinationPath);
|
|
912
|
-
if (destinationCurrent) {
|
|
913
|
-
if (destinationVersion && destinationCurrent.root.version !== destinationVersion) {
|
|
914
|
-
recoveryErrors.push(
|
|
915
|
-
new FsError('conflict', 'Destination changed; rollback will not delete it.', {
|
|
916
|
-
operation: 'move',
|
|
917
|
-
path: sourcePath,
|
|
918
|
-
destinationPath,
|
|
919
|
-
}),
|
|
920
|
-
);
|
|
921
|
-
} else {
|
|
922
|
-
try {
|
|
923
|
-
await this.removeEntry(destinationPath, destinationCurrent.root.kind === 'directory');
|
|
924
|
-
} catch (error: unknown) {
|
|
925
|
-
recoveryErrors.push(this.translateError(error, 'move', sourcePath, destinationPath));
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
await this.rollbackDirectories(createdParents);
|
|
930
|
-
|
|
931
|
-
const state: NativeFileSystemMoveRecoveryState = {
|
|
932
|
-
source: await this.probePresence(sourcePath),
|
|
933
|
-
destination: await this.probePresence(destinationPath),
|
|
934
|
-
};
|
|
935
|
-
if (
|
|
936
|
-
recoveryErrors.length === 0 &&
|
|
937
|
-
state.source === 'present' &&
|
|
938
|
-
state.destination === 'missing'
|
|
939
|
-
) {
|
|
940
|
-
throw primaryError;
|
|
941
|
-
}
|
|
942
|
-
throw new NativeFileSystemMoveRecoveryError(
|
|
943
|
-
sourcePath,
|
|
944
|
-
destinationPath,
|
|
945
|
-
primaryError,
|
|
946
|
-
recoveryErrors,
|
|
947
|
-
state,
|
|
948
|
-
);
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
private async probeScan(path: WorkspacePath): Promise<MetadataScan | null | undefined> {
|
|
952
|
-
try {
|
|
953
|
-
return await this.tryScanMetadata(path, 'move');
|
|
954
|
-
} catch {
|
|
955
|
-
return undefined;
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
private async probeSnapshot(path: WorkspacePath): Promise<SnapshotScan | null | undefined> {
|
|
960
|
-
try {
|
|
961
|
-
return await this.tryScanSnapshot(path, 'move');
|
|
962
|
-
} catch {
|
|
963
|
-
return undefined;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
private async probePresence(path: WorkspacePath): Promise<NativeFileSystemMovePathState> {
|
|
968
|
-
try {
|
|
969
|
-
return (await this.getHandle(path)) ? 'present' : 'missing';
|
|
970
|
-
} catch {
|
|
971
|
-
return 'unknown';
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
async function listDirectory(
|
|
977
|
-
directory: FileSystemDirectoryHandle,
|
|
978
|
-
operation: FsOperation,
|
|
979
|
-
path: WorkspacePath,
|
|
980
|
-
): Promise<readonly (readonly [string, FileSystemHandle])[]> {
|
|
981
|
-
const entries: Array<readonly [string, FileSystemHandle]> = [];
|
|
982
|
-
try {
|
|
983
|
-
for await (const entry of directory as unknown as AsyncIterable<
|
|
984
|
-
readonly [string, FileSystemHandle]
|
|
985
|
-
>) {
|
|
986
|
-
const [name, handle] = entry;
|
|
987
|
-
if (
|
|
988
|
-
typeof name !== 'string' ||
|
|
989
|
-
!handle ||
|
|
990
|
-
(handle.kind !== 'file' && handle.kind !== 'directory')
|
|
991
|
-
) {
|
|
992
|
-
throw new FsError('io', 'Native directory returned an invalid entry.', {
|
|
993
|
-
operation,
|
|
994
|
-
path,
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
|
-
entries.push([name, handle]);
|
|
998
|
-
}
|
|
999
|
-
} catch (error: unknown) {
|
|
1000
|
-
throw fsErrorFromUnknown(error, { operation, path });
|
|
1001
|
-
}
|
|
1002
|
-
entries.sort(([left], [right]) => compareText(left, right));
|
|
1003
|
-
return entries;
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
async function writeAndClose(
|
|
1007
|
-
writable: FileSystemWritableFileStream,
|
|
1008
|
-
data: ArrayBuffer,
|
|
1009
|
-
): Promise<void> {
|
|
1010
|
-
try {
|
|
1011
|
-
await writable.write(data);
|
|
1012
|
-
await writable.close();
|
|
1013
|
-
} catch (error: unknown) {
|
|
1014
|
-
await writable.abort(error).catch(() => undefined);
|
|
1015
|
-
throw error;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
async function metadataVersion(
|
|
1020
|
-
kind: 'file' | 'directory',
|
|
1021
|
-
metadata: Uint8Array,
|
|
1022
|
-
operation: FsOperation,
|
|
1023
|
-
path: WorkspacePath,
|
|
1024
|
-
): Promise<FileSystemVersion> {
|
|
1025
|
-
const prefix = new TextEncoder().encode(`${kind}\0`);
|
|
1026
|
-
const input = new Uint8Array(prefix.byteLength + metadata.byteLength);
|
|
1027
|
-
input.set(prefix);
|
|
1028
|
-
input.set(metadata, prefix.byteLength);
|
|
1029
|
-
let digest: ArrayBuffer;
|
|
1030
|
-
try {
|
|
1031
|
-
digest = await globalThis.crypto.subtle.digest('SHA-256', input.buffer as ArrayBuffer);
|
|
1032
|
-
} catch (error: unknown) {
|
|
1033
|
-
throw fsErrorFromUnknown(error, {
|
|
1034
|
-
operation,
|
|
1035
|
-
path,
|
|
1036
|
-
defaultCode: 'not-supported',
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
const hex = [...new Uint8Array(digest)]
|
|
1040
|
-
.map((value) => value.toString(16).padStart(2, '0'))
|
|
1041
|
-
.join('');
|
|
1042
|
-
return parseFileSystemVersion(`sha256:${hex}`);
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
function parentChain(path: WorkspacePath): WorkspacePath[] {
|
|
1046
|
-
const parents: WorkspacePath[] = [];
|
|
1047
|
-
let current = workspacePathDirname(path);
|
|
1048
|
-
while (current) {
|
|
1049
|
-
parents.unshift(current);
|
|
1050
|
-
current = workspacePathDirname(current);
|
|
1051
|
-
}
|
|
1052
|
-
return parents;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
function pathDepth(path: WorkspacePath): number {
|
|
1056
|
-
return path ? path.split('/').length : 0;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
function errorName(error: unknown): string | null {
|
|
1060
|
-
if (!error || typeof error !== 'object') return null;
|
|
1061
|
-
const name = (error as { name?: unknown }).name;
|
|
1062
|
-
return typeof name === 'string' ? name : null;
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
function isMissingOrKindError(error: unknown): boolean {
|
|
1066
|
-
const name = errorName(error);
|
|
1067
|
-
return name === 'NotFoundError' || name === 'TypeMismatchError';
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
function copyBytes(data: ArrayBuffer | Uint8Array): ArrayBuffer {
|
|
1071
|
-
const source = ArrayBuffer.isView(data)
|
|
1072
|
-
? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
|
|
1073
|
-
: new Uint8Array(data);
|
|
1074
|
-
const copy = new Uint8Array(source.byteLength);
|
|
1075
|
-
copy.set(source);
|
|
1076
|
-
return copy.buffer as ArrayBuffer;
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
function equalBytes(left: ArrayBuffer, right: ArrayBuffer): boolean {
|
|
1080
|
-
const leftBytes = new Uint8Array(left);
|
|
1081
|
-
const rightBytes = new Uint8Array(right);
|
|
1082
|
-
return (
|
|
1083
|
-
leftBytes.byteLength === rightBytes.byteLength &&
|
|
1084
|
-
leftBytes.every((value, index) => value === rightBytes[index])
|
|
1085
|
-
);
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
function equalTreeContents(
|
|
1089
|
-
left: SnapshotScan,
|
|
1090
|
-
leftRoot: WorkspacePath,
|
|
1091
|
-
right: SnapshotScan,
|
|
1092
|
-
rightRoot: WorkspacePath,
|
|
1093
|
-
): boolean {
|
|
1094
|
-
if (left.entries.length !== right.entries.length) return false;
|
|
1095
|
-
|
|
1096
|
-
const rightByRelativePath = new Map<
|
|
1097
|
-
string,
|
|
1098
|
-
FileSystemDirectorySnapshot | FileSystemSnapshotFile
|
|
1099
|
-
>();
|
|
1100
|
-
for (const entry of right.entries) {
|
|
1101
|
-
const relativePath = treeRelativePath(rightRoot, entry.path);
|
|
1102
|
-
if (relativePath === null || rightByRelativePath.has(relativePath)) return false;
|
|
1103
|
-
rightByRelativePath.set(relativePath, entry);
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
for (const entry of left.entries) {
|
|
1107
|
-
const relativePath = treeRelativePath(leftRoot, entry.path);
|
|
1108
|
-
if (relativePath === null) return false;
|
|
1109
|
-
const counterpart = rightByRelativePath.get(relativePath);
|
|
1110
|
-
if (!counterpart || counterpart.kind !== entry.kind) return false;
|
|
1111
|
-
if (entry.kind === 'file') {
|
|
1112
|
-
if (counterpart.kind !== 'file' || !equalBytes(entry.data, counterpart.data)) return false;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
return true;
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
function treeRelativePath(root: WorkspacePath, path: WorkspacePath): string | null {
|
|
1119
|
-
if (path === root) return '';
|
|
1120
|
-
const prefix = root ? `${root}/` : '';
|
|
1121
|
-
return path.startsWith(prefix) ? path.slice(prefix.length) : null;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
function withoutData(entry: FileSystemEntrySnapshot): FileSystemEntrySnapshot {
|
|
1125
|
-
if (entry.kind === 'directory') return Object.freeze({ ...entry });
|
|
1126
|
-
return Object.freeze({
|
|
1127
|
-
kind: 'file',
|
|
1128
|
-
path: entry.path,
|
|
1129
|
-
name: entry.name,
|
|
1130
|
-
size: entry.size,
|
|
1131
|
-
version: entry.version,
|
|
1132
|
-
lastModified: entry.lastModified,
|
|
1133
|
-
});
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
function copySnapshotEntry(entry: FileSystemSnapshotEntry): FileSystemSnapshotEntry {
|
|
1137
|
-
if (entry.kind === 'directory') return Object.freeze({ ...entry });
|
|
1138
|
-
return Object.freeze({
|
|
1139
|
-
kind: 'file',
|
|
1140
|
-
path: entry.path,
|
|
1141
|
-
name: entry.name,
|
|
1142
|
-
size: entry.size,
|
|
1143
|
-
version: entry.version,
|
|
1144
|
-
lastModified: entry.lastModified,
|
|
1145
|
-
data: entry.data.slice(0),
|
|
1146
|
-
});
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
function newestLastModified(children: readonly FileSystemEntrySnapshot[]): string {
|
|
1150
|
-
let newest = 0;
|
|
1151
|
-
for (const child of children) {
|
|
1152
|
-
const timestamp = Date.parse(child.lastModified);
|
|
1153
|
-
if (Number.isFinite(timestamp)) newest = Math.max(newest, timestamp);
|
|
1154
|
-
}
|
|
1155
|
-
return newest ? new Date(newest).toISOString() : EPOCH;
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
function compareSnapshots(left: FileSystemEntrySnapshot, right: FileSystemEntrySnapshot): number {
|
|
1159
|
-
if (left.kind !== right.kind) return left.kind === 'directory' ? -1 : 1;
|
|
1160
|
-
return compareText(left.name, right.name);
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
function compareText(left: string, right: string): number {
|
|
1164
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
1165
|
-
}
|