mirror of
https://github.com/apple/container.git
synced 2026-09-13 11:15:41 +00:00
OCI: Don't umount the rootfs path if it's not a mountpoint (#387)
Given this package is generic, and we use it in the guest where today we actually umount via an rpc, just skip this if it's not a mountpoint.
This commit is contained in:
@@ -110,9 +110,11 @@ public struct Bundle: Sendable {
|
||||
public func delete() throws {
|
||||
// Unmount, and then blow away the dir.
|
||||
#if os(Linux)
|
||||
let rootfs = self.rootfsPath.path
|
||||
guard _umount(rootfs, 0) == 0 else {
|
||||
throw POSIXError.fromErrno()
|
||||
let rootfs = self.rootfsPath
|
||||
if Self.isMountpoint(rootfs) {
|
||||
guard _umount(rootfs.path, 0) == 0 else {
|
||||
throw POSIXError.fromErrno()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// removeItem is recursive so should blow away the rootfs dir inside as well.
|
||||
@@ -125,4 +127,20 @@ public struct Bundle: Sendable {
|
||||
let data = try Data(contentsOf: self.configPath)
|
||||
return try JSONDecoder().decode(ContainerizationOCI.Spec.self, from: data)
|
||||
}
|
||||
|
||||
private static func isMountpoint(_ path: URL) -> Bool {
|
||||
var st = stat()
|
||||
var parent_st = stat()
|
||||
|
||||
guard stat(path.path, &st) == 0 else {
|
||||
return false
|
||||
}
|
||||
|
||||
let parentPath = path.deletingLastPathComponent()
|
||||
guard stat(parentPath.path, &parent_st) == 0 else {
|
||||
return false
|
||||
}
|
||||
|
||||
return st.st_dev != parent_st.st_dev
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user