forked from swiftlang/vscode-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin32.ts
69 lines (66 loc) · 2.72 KB
/
win32.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2024 the VS Code Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import * as fs from "fs/promises";
import { SwiftOutputChannel } from "./SwiftOutputChannel";
import { TemporaryFolder } from "../utilities/tempFolder";
import configuration from "../configuration";
import * as vscode from "vscode";
/**
* Warns the user about lack of symbolic link support on Windows. Performs the
* check in the background to avoid extending extension startup times.
*
* @param outputChannel The Swift output channel to log any errors to
*/
export function checkAndWarnAboutWindowsSymlinks(outputChannel: SwiftOutputChannel) {
if (process.platform === "win32" && configuration.warnAboutSymlinkCreation) {
isSymlinkAllowed(outputChannel).then(async canCreateSymlink => {
if (canCreateSymlink) {
return;
}
const selected = await vscode.window.showWarningMessage(
"The Swift extension is unable to create symbolic links on your system and some features may not work correctly. Please either enable Developer Mode or allow symlink creation via Windows privileges.",
"Learn More",
"Don't Show Again"
);
if (selected === "Learn More") {
return vscode.env.openExternal(
vscode.Uri.parse(
"https://learn.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development"
)
);
} else if (selected === "Don't Show Again") {
configuration.warnAboutSymlinkCreation = false;
}
});
}
}
/**
* Checks to see if the platform allows creating symlinks.
*
* @returns whether or not a symlink can be created
*/
export async function isSymlinkAllowed(outputChannel?: SwiftOutputChannel): Promise<boolean> {
const temporaryFolder = await TemporaryFolder.create();
return await temporaryFolder.withTemporaryFile("", async testFilePath => {
const testSymlinkPath = temporaryFolder.filename("symlink-");
try {
await fs.symlink(testFilePath, testSymlinkPath, "file");
await fs.unlink(testSymlinkPath);
return true;
} catch (error) {
outputChannel?.log(`${error}`);
return false;
}
});
}