-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathProjectPath.swift
43 lines (37 loc) · 1.21 KB
/
ProjectPath.swift
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
//
// ProjectPath.swift
// CodeEditUITests
//
// Created by Khan Winter on 7/10/24.
//
import Foundation
func projectPath() -> String {
return String(
URL(fileURLWithPath: #filePath)
.pathComponents
.prefix(while: { $0 != "CodeEditUITests" })
.joined(separator: "/")
.dropFirst()
)
}
private var tempProjectPathIds = Set<String>()
private func makeTempID() -> String {
let id = String((0..<10).map { _ in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-".randomElement()! })
if tempProjectPathIds.contains(id) {
return makeTempID()
}
tempProjectPathIds.insert(id)
return id
}
func tempProjectPath() throws -> String {
let baseDir = FileManager.default.temporaryDirectory.appending(path: "CodeEditUITests")
let id = makeTempID()
let path = baseDir.appending(path: id)
try FileManager.default.createDirectory(at: path, withIntermediateDirectories: true)
return path.path(percentEncoded: false)
}
func cleanUpTempProjectPaths() throws {
let baseDir = FileManager.default.temporaryDirectory.appending(path: "CodeEditUITests")
try FileManager.default.removeItem(at: baseDir)
tempProjectPathIds.removeAll()
}