forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrateTo135.swift
More file actions
47 lines (38 loc) · 1.67 KB
/
MigrateTo135.swift
File metadata and controls
47 lines (38 loc) · 1.67 KB
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
import Foundation
import GitHubCopilotService
func migrateFromLowerThanOrEqualToVersion135() throws {
// 0. Create the application support folder if it doesn't exist
let urls = try GitHubCopilotBaseService.createFoldersIfNeeded()
// 1. Move the undefined folder in application support into a sub folder called `GitHub
// Copilot/support`
let undefinedFolderURL = urls.applicationSupportURL.appendingPathComponent("undefined")
var isUndefinedADirectory: ObjCBool = false
let isUndefinedExisted = FileManager.default.fileExists(
atPath: undefinedFolderURL.path,
isDirectory: &isUndefinedADirectory
)
if isUndefinedExisted, isUndefinedADirectory.boolValue {
try FileManager.default.moveItem(
at: undefinedFolderURL,
to: urls.supportURL.appendingPathComponent("undefined")
)
}
// 2. Copy the GitHub copilot language service to `GitHub Copilot/executable`
let copilotFolderURL = urls.executableURL.appendingPathComponent("copilot")
var copilotIsFolder: ObjCBool = false
let executable = Bundle.main.resourceURL?.appendingPathComponent("copilot")
if let executable,
FileManager.default.fileExists(atPath: executable.path, isDirectory: &copilotIsFolder),
!FileManager.default.fileExists(atPath: copilotFolderURL.path)
{
try FileManager.default.copyItem(
at: executable,
to: urls.executableURL.appendingPathComponent("copilot")
)
}
// 3. Use chmod to change the permission of the executable to 755
try FileManager.default.setAttributes(
[.posixPermissions: 0o755],
ofItemAtPath: copilotFolderURL.path
)
}