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
10 changes: 9 additions & 1 deletion Sources/ContainerizationOS/AsyncSignalHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

import Foundation
import Dispatch
import Synchronization

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Darwin)
import Darwin
#endif

/// Async friendly wrapper around `DispatchSourceSignal`. Provides an `AsyncStream`
/// interface to get notified of received signals.
public final class AsyncSignalHandler: Sendable {
Expand Down
16 changes: 14 additions & 2 deletions Sources/ContainerizationOS/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

import Foundation
#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Darwin)
import Darwin
#endif

#if canImport(FoundationEssentials)
import struct FoundationEssentials.URL
#else
import struct Foundation.URL
#endif

/// Trivial type to discover information about a given file (uid, gid, mode...).
public struct File: Sendable {
Expand Down Expand Up @@ -52,7 +64,7 @@ public struct File: Sendable {
/// `FileInfo` holds and provides easy access to stat(2) data
/// for a file.
public struct FileInfo: Sendable {
private let _stat_t: Foundation.stat
private let _stat_t: stat
private let _path: String

init(_ path: String, stat: stat) {
Expand Down
4 changes: 4 additions & 0 deletions Sources/ContainerizationOS/Keychain/KeychainQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
//===----------------------------------------------------------------------===//

#if os(macOS)
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

/// Holds the result of a query to the keychain.
public struct KeychainQueryResult {
Expand Down
4 changes: 4 additions & 0 deletions Sources/ContainerizationOS/Keychain/RegistryInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

/// Holds the stored attributes for a registry.
public struct RegistryInfo: Sendable {
Expand Down
4 changes: 4 additions & 0 deletions Sources/ContainerizationOS/Linux/Binfmt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

#if canImport(Musl)
import Musl
Expand Down
5 changes: 5 additions & 0 deletions Sources/ContainerizationOS/Linux/Capabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
//===----------------------------------------------------------------------===//

import CShim

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: - Configuration Types

Expand Down
4 changes: 4 additions & 0 deletions Sources/ContainerizationOS/Linux/Epoll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
//===----------------------------------------------------------------------===//

#if os(Linux)
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

#if canImport(Musl)
import Musl
Expand Down
5 changes: 5 additions & 0 deletions Sources/ContainerizationOS/Mount/Mount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
//===----------------------------------------------------------------------===//

import CShim

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

#if canImport(Musl)
import Musl
Expand Down
12 changes: 12 additions & 0 deletions Sources/ContainerizationOS/POSIXError+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Darwin)
import Darwin
#endif

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

extension POSIXError {
public static func fromErrno() -> POSIXError {
Expand Down
4 changes: 4 additions & 0 deletions Sources/ContainerizationOS/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

/// `Path` provides utilities to look for binaries in the current PATH,
/// or to return the current PATH.
Expand Down
11 changes: 11 additions & 0 deletions Sources/ContainerizationOS/Reaper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Darwin)
import Darwin
#endif
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

/// A process reaper that returns exited processes along
/// with their exit status.
Expand Down
16 changes: 15 additions & 1 deletion Sources/ContainerizationOS/Socket/BidirectionalRelay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,24 @@
//===----------------------------------------------------------------------===//

import ContainerizationError
import Foundation
import Dispatch
import Logging
import Synchronization

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Darwin)
import Darwin
#endif

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

/// Manages bidirectional data relay between two file descriptors using `DispatchSource`.
public final class BidirectionalRelay: Sendable {
private let fd1: Int32
Expand Down
7 changes: 7 additions & 0 deletions Sources/ContainerizationOS/Sysctl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

#if canImport(Darwin)
import Darwin
#endif
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

/// Helper type to deal with system control functionalities.
public struct Sysctl {
Expand Down
26 changes: 22 additions & 4 deletions Sources/ContainerizationOS/URL+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@
// limitations under the License.
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Darwin)
import Darwin
#endif

/// The `resolvingSymlinksInPath` method of the `URL` struct does not resolve the symlinks
/// for directories under `/private` which include`tmp`, `var` and `etc`
Expand All @@ -34,20 +46,26 @@ extension URL {
let parts = url.pathComponents
if parts.count > 1 {
if (parts.first == "/") && ["tmp", "var", "etc"].contains(parts[1]) {
if let resolved = NSURL.fileURL(withPathComponents: ["/", "private"] + parts[1...]) {
return resolved
var resolved = URL(filePath: "/private")
for part in parts[1...] {
resolved.append(path: part)
}
return resolved
}
}
#endif
return url
}

public var isDirectory: Bool {
(try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true
var st = stat()
guard stat(self.path, &st) == 0 else { return false }
return (st.st_mode & S_IFMT) == S_IFDIR
}

public var isSymlink: Bool {
(try? resourceValues(forKeys: [.isSymbolicLinkKey]))?.isSymbolicLink == true
var st = stat()
guard lstat(self.path, &st) == 0 else { return false }
return (st.st_mode & S_IFMT) == S_IFLNK
}
}
5 changes: 5 additions & 0 deletions Sources/ContainerizationOS/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
//===----------------------------------------------------------------------===//

import ContainerizationError

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

/// `User` provides utilities to ensure that a given username exists in
/// /etc/passwd (and /etc/group). Largely inspired by runc (and moby's)
Expand Down
Loading