inMemoryFilesystemProvider.ts ×20

Frontier kind: Code frontier

unlabeled · c_9d51ddb42103

1363 tests · 11320 LOC · 45 files · introduces 0 tests · 73 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
20 ranges73 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1727 ranges11320 lines · 45 files · Browse complete extent
All tests (intent)
1363 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 73 introduced LOC across 20 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/files/common/inMemoryFilesystemProvider.ts 73 introduced LOC · 20 ranges

Open complete file

42
43 constructor(name: string) {
44 > this.type = FileType.Directory; inMemoryFilesystemProvider.ts
45 > this.ctime = Date.now();
46 > this.mtime = Date.now();
47 > this.size = 0;
48 > this.name = name;
49 > this.entries = new Map();
50 > }
51 }
52
60 IFileSystemProviderWithFileAtomicWriteCapability,
61 IFileSystemProviderWithFileAtomicDeleteCapability {
63 > private memoryFdCounter = 0;
64 > private readonly fdMemory = new Map<number, { file: File; resource: URI; append: boolean; write: boolean }>();
65 > private _onDidChangeCapabilities = this._register(new Emitter<void>());
66 > readonly onDidChangeCapabilities = this._onDidChangeCapabilities.event;
67 >
68 > private _capabilities = FileSystemProviderCapabilities.FileReadWrite | FileSystemProviderCapabilities.FileOpenReadWriteClose | FileSystemProviderCapabilities.FileAppend | FileSystemProviderCapabilities.PathCaseSensitive;
69 > get capabilities(): FileSystemProviderCapabilities { return this._capabilities; }
70 >
71 > setReadOnly(readonly: boolean) {
72 const isReadonly = !!(this._capabilities & FileSystemProviderCapabilities.Readonly);
73 if (readonly !== isReadonly) {
76 }
77 }
79 > root = new Directory('');
80 >
81 > // --- manage file metadata
82 >
83 > async stat(resource: URI): Promise<IStat> {
84 return this._lookup(resource, false);
85 }
87 > async readdir(resource: URI): Promise<[string, FileType][]> {
88 const entry = this._lookupAsDirectory(resource, false);
89 const result: [string, FileType][] = [];
91 return result;
92 }
94 > // --- manage file contents
95 >
96 > async readFile(resource: URI): Promise<Uint8Array> {
97 const data = this._lookupAsFile(resource, false).data;
98 if (data) {
101 throw createFileSystemProviderError('file not found', FileSystemProviderErrorCode.FileNotFound);
102 }
104 > readFileStream(resource: URI): ReadableStreamEvents<Uint8Array> {
105 const data = this._lookupAsFile(resource, false).data;
106
110 return stream;
111 }
113 > async writeFile(resource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void> {
114 const basename = resources.basename(resource);
115 const parent = this._lookupParentDirectory(resource);
145 this._fireSoon({ type: FileChangeType.UPDATED, resource });
146 }
148 > // file open/read/write/close
149 > open(resource: URI, opts: IFileOpenOptions): Promise<number> {
150 let file = this._lookup(resource, true);
151 const write = isFileOpenForWriteOptions(opts);
175 return Promise.resolve(fd);
176 }
178 > close(fd: number): Promise<void> {
179 const fdData = this.fdMemory.get(fd);
180 if (fdData?.write) {
187 return Promise.resolve();
188 }
190 > read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> {
191 const fdData = this.fdMemory.get(fd);
192 if (!fdData) {
202 return Promise.resolve(toWrite.byteLength);
203 }
205 > write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> {
206 const fdData = this.fdMemory.get(fd);
207 if (!fdData) {
226 return Promise.resolve(toWrite.byteLength);
227 }
229 > // --- manage files/folders
230 >
231 > async rename(from: URI, to: URI, opts: IFileOverwriteOptions): Promise<void> {
232 if (!opts.overwrite && this._lookup(to, true)) {
233 throw createFileSystemProviderError('file exists already', FileSystemProviderErrorCode.FileExists);
249 );
250 }
252 > async delete(resource: URI, opts: IFileDeleteOptions): Promise<void> {
253 const dirname = resources.dirname(resource);
254 const basename = resources.basename(resource);
260 }
261 }
263 > async mkdir(resource: URI): Promise<void> {
264 if (this._lookup(resource, true)) {
265 throw createFileSystemProviderError('file exists already', FileSystemProviderErrorCode.FileExists);
276 this._fireSoon({ type: FileChangeType.UPDATED, resource: dirname }, { type: FileChangeType.ADDED, resource });
277 }
279 > // --- lookup
280 >
281 > private _lookup(uri: URI, silent: false): Entry;
282 > private _lookup(uri: URI, silent: boolean): Entry | undefined;
283 > private _lookup(uri: URI, silent: boolean): Entry | undefined {
284 const parts = uri.path.split('/');
285 let entry: Entry = this.root;
303 return entry;
304 }
306 > private _lookupAsDirectory(uri: URI, silent: boolean): Directory {
307 const entry = this._lookup(uri, silent);
308 if (entry instanceof Directory) {
311 throw createFileSystemProviderError('file not a directory', FileSystemProviderErrorCode.FileNotADirectory);
312 }
314 > private _lookupAsFile(uri: URI, silent: boolean): File {
315 const entry = this._lookup(uri, silent);
316 if (entry instanceof File) {
319 throw createFileSystemProviderError('file is a directory', FileSystemProviderErrorCode.FileIsADirectory);
320 }
322 > private _lookupParentDirectory(uri: URI): Directory {
323 const dirname = resources.dirname(uri);
324 return this._lookupAsDirectory(dirname, false);
325 }
327 > // --- manage file events
328 >
329 > private readonly _onDidChangeFile = this._register(new Emitter<readonly IFileChange[]>());
330 > readonly onDidChangeFile: Event<readonly IFileChange[]> = this._onDidChangeFile.event;
331 >
332 > private _bufferedChanges: IFileChange[] = [];
333 private _fireSoonHandle?: Timeout;
334