fileService.ts ×10

Frontier kind: Code frontier

unlabeled · c_a3be1457e777

620 tests · 11395 LOC · 44 files · introduces 0 tests · 47 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
12 ranges47 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1771 ranges11395 lines · 44 files · Browse complete extent
All tests (intent)
620 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.

2 files ranked by introduced lines: 47 introduced LOC across 12 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/files/common/fileService.ts 43 introduced LOC · 10 ranges

Open complete file

585
586 private async doReadFileStream(provider: IFileSystemProviderWithFileReadWriteCapability | IFileSystemProviderWithOpenReadWriteCloseCapability | IFileSystemProviderWithFileReadStreamCapability, resource: URI, options?: IReadFileOptions & IReadFileStreamOptions & { preferUnbuffered?: boolean }, token?: CancellationToken): Promise<IFileStreamContent> {
588 > // install a cancellation token that gets cancelled
589 > // when any error occurs. this allows us to resolve
590 > // the content of the file while resolving metadata
591 > // but still cancel the operation in certain cases.
592 > //
593 > // in addition, we pass the optional token in that
594 > // we got from the outside to even allow for external
595 > // cancellation of the read operation.
596 > const cancellableSource = new CancellationTokenSource(token);
597 >
598 > let readFileOptions = options;
599 > if (hasFileAtomicReadCapability(provider) && provider.enforceAtomicReadFile?.(resource)) {
600 readFileOptions = { ...options, atomic: true };
601 }
603 > // validate read operation
604 > const statPromise = this.validateReadFile(resource, readFileOptions).then(stat => stat, error => {
605 cancellableSource.dispose(true);
606
607 throw error;
608 > }); fileService.ts
609 >
610 > let fileStream: VSBufferReadableStream | undefined = undefined;
611 > try {
612 >
613 > // if the etag is provided, we await the result of the validation
614 > // due to the likelihood of hitting a NOT_MODIFIED_SINCE result.
615 > // otherwise, we let it run in parallel to the file reading for
616 > // optimal startup performance.
617 > if (typeof readFileOptions?.etag === 'string' && readFileOptions.etag !== ETAG_DISABLED) {
618 await statPromise;
619 }
621 > // read unbuffered
622 > if (
623 > (readFileOptions?.atomic && hasFileAtomicReadCapability(provider)) || // atomic reads are always unbuffered
624 > !(hasOpenReadWriteCloseCapability(provider) || hasFileReadStreamCapability(provider)) || // provider has no buffered capability
625 > (hasReadWriteCapability(provider) && readFileOptions?.preferUnbuffered) // unbuffered read is preferred
626 > ) {
627 fileStream = this.readFileUnbuffered(provider, resource, readFileOptions);
628 }
637 fileStream = this.readFileBuffered(provider, resource, cancellableSource.token, readFileOptions);
638 }
640 > fileStream.on('end', () => cancellableSource.dispose());
641 > fileStream.on('error', () => cancellableSource.dispose());
642 >
643 > const fileStat = await statPromise;
644
645 return {
647 value: fileStream
648 };
649 > } catch (error) { fileService.ts
650
651 // Await the stream to finish so that we exit this method
660 throw this.restoreReadError(error, resource, readFileOptions);
661 }
662 > } fileService.ts
663
664 private restoreReadError(error: Error, resource: URI, options?: IReadFileStreamOptions): FileOperationError {
736
737 private async validateReadFile(resource: URI, options?: IReadFileStreamOptions): Promise<IFileStatWithMetadata> {
738 > const stat = await this.resolve(resource, { resolveMetadata: true }); fileService.ts
739
740 // Throw if resource is a directory
744
745 // Throw if file not modified since (unless disabled)
746 > if (typeof options?.etag === 'string' && options.etag !== ETAG_DISABLED && options.etag === stat.etag) { fileService.ts
747 throw new NotModifiedSinceFileOperationError(localize('fileNotModifiedError', "File not modified since"), stat, options);
748 }
752
753 return stat;
754 > } fileService.ts
755
756 private validateReadFileLimits(resource: URI, size: number, options?: IReadFileStreamOptions): void {
src/vs/platform/files/common/files.ts 4 introduced LOC · 2 ranges

Open complete file

768
769 export function hasFileAtomicReadCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileAtomicReadCapability {
770 > if (!hasReadWriteCapability(provider)) { files.ts
771 return false; // we require the `FileReadWrite` capability too
772 }
773 > files.ts
774 > return !!(provider.capabilities & FileSystemProviderCapabilities.FileAtomicRead);
775 > }
776
777 export interface IFileSystemProviderWithFileAtomicWriteCapability extends IFileSystemProvider {