From 14239b02c35ea0e7fd2fe7290347ecf5a534af49 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Thu, 31 Jul 2025 23:32:10 -0700 Subject: [PATCH] ContainerizationOS: minor fixes (#241) While reviewing test coverage, I noticed a couple of minor issues: - 0 is non-negative - allow for zero memory - we should likely use lstat instead of stat for file info - we should check for empty name parameter --------- Signed-off-by: Eric Ernst --- Sources/ContainerizationOS/BinaryInteger+Extensions.swift | 2 +- Sources/ContainerizationOS/File.swift | 2 +- Sources/ContainerizationOS/Path.swift | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/ContainerizationOS/BinaryInteger+Extensions.swift b/Sources/ContainerizationOS/BinaryInteger+Extensions.swift index 04163831..f7e4dd54 100644 --- a/Sources/ContainerizationOS/BinaryInteger+Extensions.swift +++ b/Sources/ContainerizationOS/BinaryInteger+Extensions.swift @@ -16,7 +16,7 @@ extension BinaryInteger { private func toUnsignedMemoryAmount(_ amount: UInt64) -> UInt64 { - guard self > 0 else { + guard self >= 0 else { fatalError("encountered negative number during conversion to memory amount") } let val = UInt64(self) diff --git a/Sources/ContainerizationOS/File.swift b/Sources/ContainerizationOS/File.swift index ee226254..fee818c2 100644 --- a/Sources/ContainerizationOS/File.swift +++ b/Sources/ContainerizationOS/File.swift @@ -42,7 +42,7 @@ public struct File: Sendable { /// - path: The path to the file as a string. public static func info(_ path: String) throws -> FileInfo { var st = stat() - guard stat(path, &st) == 0 else { + guard lstat(path, &st) == 0 else { throw Error.errno(errno) } return FileInfo(path, stat: st) diff --git a/Sources/ContainerizationOS/Path.swift b/Sources/ContainerizationOS/Path.swift index 5fe2690d..2b586bd0 100644 --- a/Sources/ContainerizationOS/Path.swift +++ b/Sources/ContainerizationOS/Path.swift @@ -33,6 +33,11 @@ public struct Path { } private static func lookup(_ name: String, path: String) -> URL? { + // Return nil for empty names + if name.isEmpty { + return nil + } + if name.contains("/") { if findExec(name) { return URL(fileURLWithPath: name)