restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import Foundation
|
||||
|
||||
/// A small case-sensitive APFS disk image, attached for one test and detached on deinit.
|
||||
final class CaseSensitiveVolume {
|
||||
let root: URL
|
||||
private let image: URL
|
||||
|
||||
init() throws {
|
||||
let base = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("helder-cs-\(UUID().uuidString)")
|
||||
.resolvingSymlinksInPath()
|
||||
try FileManager.default.createDirectory(at: base, withIntermediateDirectories: true)
|
||||
image = base.appendingPathComponent("volume.dmg")
|
||||
root = base.appendingPathComponent("mount")
|
||||
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
|
||||
try Self.hdiutil(["create", "-quiet", "-size", "8m", "-fs", "Case-sensitive APFS", "-volname", "HelderCS", image.path])
|
||||
try Self.hdiutil(["attach", "-quiet", "-nobrowse", "-mountpoint", root.path, image.path])
|
||||
}
|
||||
|
||||
deinit {
|
||||
try? Self.hdiutil(["detach", "-quiet", "-force", root.path])
|
||||
try? FileManager.default.removeItem(at: image.deletingLastPathComponent())
|
||||
}
|
||||
|
||||
private static func hdiutil(_ arguments: [String]) throws {
|
||||
let process = Process()
|
||||
process.executableURL = URL(fileURLWithPath: "/usr/bin/hdiutil")
|
||||
process.arguments = arguments
|
||||
process.standardInput = FileHandle.nullDevice
|
||||
process.standardOutput = FileHandle.nullDevice
|
||||
process.standardError = FileHandle.nullDevice
|
||||
try process.run()
|
||||
process.waitUntilExit()
|
||||
guard process.terminationStatus == 0 else {
|
||||
throw NSError(domain: "hdiutil", code: Int(process.terminationStatus), userInfo: [NSLocalizedDescriptionKey: arguments.joined(separator: " ")])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user