diskFileSystemProvider.ts ×9

Frontier kind: Code frontier

unlabeled · c_230d1f8cdb6a

6 tests · 15491 LOC · 68 files · introduces 0 tests · 73 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges73 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2546 ranges15491 lines · 68 files · Browse complete extent
All tests (intent)
6 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.

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

src/vs/platform/files/node/diskFileSystemProvider.ts 39 introduced LOC · 9 ranges

Open complete file

244 async writeFile(resource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void> {
245 if (opts?.atomic !== false && opts?.atomic?.postfix && await this.canWriteFileAtomic(resource)) {
246 > return this.doWriteFileAtomic(resource, joinPath(resourcesDirname(resource), `${resourcesBasename(resource)}${opts.atomic.postfix}`), content, opts); diskFileSystemProvider.ts
247 } else {
248 return this.doWriteFile(resource, content, opts);
251
252 private async canWriteFileAtomic(resource: URI): Promise<boolean> {
254 > const filePath = this.toFilePath(resource);
255 > const { symbolicLink } = await SymlinkSupport.stat(filePath);
256 > if (symbolicLink) {
257 // atomic writes are unsupported for symbolic links because
258 // we need to ensure that the `rename` operation is atomic
262 return false;
263 }
264 > } catch (error) { diskFileSystemProvider.ts
265 // ignore stat errors here and just proceed trying to write
266 }
268 > return true; // atomic writing supported
269 > }
270
271 private async doWriteFileAtomic(resource: URI, tempResource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void> {
273 > // Ensure to create locks for all resources involved
274 > // since atomic write involves mutiple disk operations
275 > // and resources.
276 >
277 > const locks = new DisposableStore();
278 >
279 > try {
280 > locks.add(await this.createResourceLock(resource));
281 > locks.add(await this.createResourceLock(tempResource));
282 >
283 > // Write to temp resource first
284 > await this.doWriteFile(tempResource, content, { ...opts, create: true, overwrite: true }, true /* disable write lock */);
285 >
286 > try {
287 >
288 > // Rename over existing to ensure atomic replace
289 > await this.rename(tempResource, resource, { overwrite: true });
290 >
291 > } catch (error) {
292
293 // Cleanup in case of rename error
300 throw error;
301 }
302 > } finally { diskFileSystemProvider.ts
303 > locks.dispose();
304 > }
305 > }
306
307 private async doWriteFile(resource: URI, content: Uint8Array, opts: IFileWriteOptions, disableWriteLock?: boolean): Promise<void> {
760 return; // target does not exist so we are good
761 }
763 > if (!overwrite) {
764 throw createFileSystemProviderError(localize('fileMoveCopyErrorExists', "File at target already exists and thus will not be moved/copied to unless overwrite is specified"), FileSystemProviderErrorCode.FileExists);
765 }
767 > // Handle existing target for move/copy
768 if ((fromStat.type & FileType.File) !== 0 && (toStat.type & FileType.File) !== 0) {
769 > return; // node.js can move/copy a file over an existing file without having to delete it first diskFileSystemProvider.ts
770 > } else {
771 await this.delete(to, { recursive: true, useTrash: false, atomic: false });
772 }
src/vs/platform/state/node/stateService.ts 28 introduced LOC · 4 ranges

Open complete file

43
44 init(): Promise<void> {
45 > if (!this.initializing) { stateService.ts
46 > this.initializing = this.doInit();
47 > }
48 >
49 > return this.initializing;
50 > }
51
52 private async doInit(): Promise<void> {
53 > try { stateService.ts
54 > this.lastSavedStorageContents = (await this.fileService.readFile(this.storagePath)).value.toString();
55 > this.storage = JSON.parse(this.lastSavedStorageContents);
56 > } catch (error) {
57 > if ((<FileOperationError>error).fileOperationResult !== FileOperationResult.FILE_NOT_FOUND) {
58 > this.logService.error(error);
59 > }
60 > }
61 > }
62
63 getItem<T>(key: string, defaultValue: T): T;
127 return; // if we never initialized, we should not save our state
128 }
130 > // Make sure to wait for init to finish first
131 > await this.initializing;
132 >
133 > // Return early if the database has not changed
134 > const serializedDatabase = JSON.stringify(this.storage, null, 4);
135 > if (serializedDatabase === this.lastSavedStorageContents) {
136 return;
137 }
139 > // Write to disk
140 > try {
141 > await this.fileService.writeFile(this.storagePath, VSBuffer.fromString(serializedDatabase), { atomic: { postfix: '.vsctmp' } });
142 > this.lastSavedStorageContents = serializedDatabase;
143 > } catch (error) {
144 this.logService.error(error);
145 }
src/vs/platform/files/common/fileService.ts 6 introduced LOC · 4 ranges

Open complete file

469 const atomic = !!options?.atomic;
470 if (atomic) {
471 > if (!(provider.capabilities & FileSystemProviderCapabilities.FileAtomicWrite)) { fileService.ts
472 throw new Error(localize('writeFailedAtomicUnsupported1', "Unable to atomically write file '{0}' because provider does not support it.", this.resourceForError(resource)));
473 }
475 > if (!(provider.capabilities & FileSystemProviderCapabilities.FileReadWrite)) {
476 throw new Error(localize('writeFailedAtomicUnsupported2', "Unable to atomically write file '{0}' because provider does not support unbuffered writes.", this.resourceForError(resource)));
477 }
479 > if (unlock) {
480 throw new Error(localize('writeFailedAtomicUnlock', "Unable to unlock file '{0}' because atomic write is enabled.", this.resourceForError(resource)));
481 }
482 > } fileService.ts
483
484 // Validate via file stat meta data