mirror of
https://github.com/apple/container.git
synced 2026-08-24 10:05:43 -05:00
volumes: Allow "." (#1326)
We should allow passing . for the src of a volume.
This commit is contained in:
@@ -515,8 +515,8 @@ public struct Parser {
|
||||
let src = String(parts[0])
|
||||
let dst = String(parts[1])
|
||||
|
||||
// Check if it's a filesystem path
|
||||
guard src.contains("/") else {
|
||||
// Check if it's a filesystem path (absolute, or relative like ".", "..", "./foo", "../foo")
|
||||
guard src.contains("/") || src == "." || src == ".." else {
|
||||
// Named volume - validate name syntax only
|
||||
guard VolumeStorage.isValidVolumeName(src) else {
|
||||
throw ContainerizationError(.invalidArgument, message: "invalid volume name '\(src)': must match \(VolumeStorage.volumeNamePattern)")
|
||||
|
||||
@@ -392,6 +392,48 @@ struct ParserTest {
|
||||
#expect(Bool(false), "Expected filesystem mount, got volume")
|
||||
}
|
||||
}
|
||||
|
||||
// Test volume with bare "." as source (current directory)
|
||||
do {
|
||||
let tempDir = FileManager.default.temporaryDirectory.appendingPathComponent("test-volume-dot-\(UUID().uuidString)")
|
||||
try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true)
|
||||
defer {
|
||||
try? FileManager.default.removeItem(at: tempDir)
|
||||
}
|
||||
|
||||
let result = try Parser.volume(".:/docs:ro", relativeTo: tempDir)
|
||||
|
||||
switch result {
|
||||
case .filesystem(let fs):
|
||||
let expectedPath = tempDir.standardizedFileURL.path
|
||||
#expect(fs.source.trimmingCharacters(in: CharacterSet(charactersIn: "/")) == expectedPath.trimmingCharacters(in: CharacterSet(charactersIn: "/")))
|
||||
#expect(fs.destination == "/docs")
|
||||
#expect(fs.options.contains("ro"))
|
||||
case .volume:
|
||||
#expect(Bool(false), "Expected filesystem mount, got volume")
|
||||
}
|
||||
}
|
||||
|
||||
// Test volume with ".." as source (parent directory)
|
||||
do {
|
||||
let tempDir = FileManager.default.temporaryDirectory.appendingPathComponent("test-volume-dotdot-\(UUID().uuidString)")
|
||||
let childDir = tempDir.appendingPathComponent("child")
|
||||
try FileManager.default.createDirectory(at: childDir, withIntermediateDirectories: true)
|
||||
defer {
|
||||
try? FileManager.default.removeItem(at: tempDir)
|
||||
}
|
||||
|
||||
let result = try Parser.volume("..:/data", relativeTo: childDir)
|
||||
|
||||
switch result {
|
||||
case .filesystem(let fs):
|
||||
let expectedPath = tempDir.standardizedFileURL.path
|
||||
#expect(fs.source.trimmingCharacters(in: CharacterSet(charactersIn: "/")) == expectedPath.trimmingCharacters(in: CharacterSet(charactersIn: "/")))
|
||||
#expect(fs.destination == "/data")
|
||||
case .volume:
|
||||
#expect(Bool(false), "Expected filesystem mount, got volume")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user