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 <eric_ernst@apple.com>
This commit is contained in:
Eric Ernst
2025-07-31 23:32:10 -07:00
committed by GitHub
parent ab37e574a0
commit 14239b02c3
3 changed files with 7 additions and 2 deletions
@@ -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)
+1 -1
View File
@@ -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)
+5
View File
@@ -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)