Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/tart/Commands/Set.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct Set: AsyncParsableCommand {
if let disk = disk {
let temporaryDiskURL = try Config().tartTmpDir.appendingPathComponent("set-disk-\(UUID().uuidString)")

try FileManager.default.copyItem(atPath: disk, toPath: temporaryDiskURL.path())
try FileManager.default.copyItem(atPath: disk, toPath: temporaryDiskURL.path(percentEncoded: false))

_ = try FileManager.default.replaceItemAt(vmDir.diskURL, withItemAt: temporaryDiskURL)
}
Expand Down
16 changes: 16 additions & 0 deletions Tests/TartTests/CommandBehaviorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ final class CommandBehaviorTests: XCTestCase {
}
}

func testSetDiskReplacesDiskWhenTartHomeContainsSpaces() async throws {
let home = try temporaryDirectory().appendingPathComponent("Tart Home", isDirectory: true)
let previousHome = ProcessInfo.processInfo.environment["TART_HOME"]
setenv("TART_HOME", home.path, 1)
defer { restoreEnvironment("TART_HOME", to: previousHome) }

let vmDir = try makeStandaloneVM(named: "spaces", diskContents: "disk")
let replacementURL = try temporaryDirectory().appendingPathComponent("replacement.img")
XCTAssertTrue(FileManager.default.createFile(atPath: replacementURL.path, contents: Data("replacement".utf8)))

let command = try Set.parseAsRoot(["spaces", "--disk", replacementURL.path]) as! Set
try await command.run()

XCTAssertEqual(try Data(contentsOf: vmDir.diskURL), Data("replacement".utf8))
}

func testSetPreservesDisplayRefitWhenChangingOtherOptions() async throws {
try await withTemporaryTartHome {
let vmDir = try makeStandaloneVM(named: "display-refit", diskContents: "disk")
Expand Down