src/vs/base/node/unc.ts

102 LOC · 48 covered · 54 uncovered · 6 ranges · 1 concepts · 1 introducers · 1 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- unc.ts ×6
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > export function getUNCHostAllowlist(): string[] {
7 const allowlist = processUNCHostAllowlist();
8 if (allowlist) {
9 return Array.from(allowlist);
10 }
11
12 return [];
13 }
14 > unc.ts ×6
15 function processUNCHostAllowlist(): Set<string> | undefined {
16
17 // The property `process.uncHostAllowlist` is not available in official node.js
18 // releases, only in our own builds, so we have to probe for availability
19
20 return (process as unknown as { uncHostAllowlist?: Set<string> }).uncHostAllowlist;
21 }
22 > unc.ts ×6
23 > export function addUNCHostToAllowlist(allowedHost: string | string[]): void {
24 if (process.platform !== 'win32') {
25 return;
26 }
27
28 const allowlist = processUNCHostAllowlist();
29 if (allowlist) {
30 if (typeof allowedHost === 'string') {
31 allowlist.add(allowedHost.toLowerCase()); // UNC hosts are case-insensitive
32 } else {
33 for (const host of toSafeStringArray(allowedHost)) {
34 addUNCHostToAllowlist(host);
35 }
36 }
37 }
38 }
39 > unc.ts ×6
40 function toSafeStringArray(arg0: unknown): string[] {
41 const allowedUNCHosts = new Set<string>();
42
43 if (Array.isArray(arg0)) {
44 for (const host of arg0) {
45 if (typeof host === 'string') {
46 allowedUNCHosts.add(host);
47 }
48 }
49 }
50
51 return Array.from(allowedUNCHosts);
52 }
53 > unc.ts ×6
54 > export function getUNCHost(maybeUNCPath: string | undefined | null): string | undefined {
55 > if (typeof maybeUNCPath !== 'string') {
56 > return undefined; // require a valid string
57 > }
58 >
59 > const uncRoots = [
60 > '\\\\.\\UNC\\', // DOS Device paths (https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats)
61 > '\\\\?\\UNC\\',
62 > '\\\\' // standard UNC path
63 > ];
64 >
65 > let host = undefined;
66 >
67 > for (const uncRoot of uncRoots) {
68 > const indexOfUNCRoot = maybeUNCPath.indexOf(uncRoot);
69 > if (indexOfUNCRoot !== 0) {
70 > continue; // not matching any of our expected UNC roots
71 > }
72 >
73 > const indexOfUNCPath = maybeUNCPath.indexOf('\\', uncRoot.length);
74 > if (indexOfUNCPath === -1) {
75 > continue; // no path component found
76 > }
77 >
78 > const hostCandidate = maybeUNCPath.substring(uncRoot.length, indexOfUNCPath);
79 > if (hostCandidate) {
80 > host = hostCandidate;
81 > break;
82 > }
83 > }
84 >
85 > return host;
86 > }
87 >
88 > export function disableUNCAccessRestrictions(): void {
89 if (process.platform !== 'win32') {
90 return;
91 }
92
93 (process as unknown as { restrictUNCAccess?: boolean }).restrictUNCAccess = false;
94 }
95 > unc.ts ×6
96 > export function isUNCAccessRestrictionsDisabled(): boolean {
97 if (process.platform !== 'win32') {
98 return true;
99 }
100
101 return (process as unknown as { restrictUNCAccess?: boolean }).restrictUNCAccess === false;
102 }