Skip to content

Commit 69445b9

Browse files
authored
Throw error when starting a container with invalid virtiofs source (apple#1051)
Run = Create + Start 1) Mount source points to a valid directory - Run and Create + Start both correctly create the container with mount. 2) Mount source points to a file - Run fails bootstrapping the container, thus container not created. - Create creates the container, but Start fails bootstrapping, removing the container. (Thus, both are the same.) 3) Mount source deleted or replaced to file after container created - Start throw errors but do not delete the container.
1 parent 08f48d9 commit 69445b9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

‎Sources/ContainerCommands/Container/ContainerStart.swift‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ArgumentParser
1818
import ContainerAPIClient
1919
import ContainerizationError
2020
import ContainerizationOS
21+
import Foundation
2122
import TerminalProgress
2223

2324
extension Application {
@@ -69,6 +70,12 @@ extension Application {
6970
return
7071
}
7172

73+
for mount in container.configuration.mounts where mount.isVirtiofs {
74+
if !FileManager.default.fileExists(atPath: mount.source) {
75+
throw ContainerizationError(.invalidState, message: "path '\(mount.source)' is not a directory")
76+
}
77+
}
78+
7279
do {
7380
let io = try ProcessIO.create(
7481
tty: container.configuration.initProcess.terminal,

0 commit comments

Comments
 (0)