Skip to content

Commit 14239b0

Browse files
authored
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 <[email protected]>
1 parent ab37e57 commit 14239b0

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Sources/ContainerizationOS/BinaryInteger+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
extension BinaryInteger {
1818
private func toUnsignedMemoryAmount(_ amount: UInt64) -> UInt64 {
19-
guard self > 0 else {
19+
guard self >= 0 else {
2020
fatalError("encountered negative number during conversion to memory amount")
2121
}
2222
let val = UInt64(self)

Sources/ContainerizationOS/File.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public struct File: Sendable {
4242
/// - path: The path to the file as a string.
4343
public static func info(_ path: String) throws -> FileInfo {
4444
var st = stat()
45-
guard stat(path, &st) == 0 else {
45+
guard lstat(path, &st) == 0 else {
4646
throw Error.errno(errno)
4747
}
4848
return FileInfo(path, stat: st)

Sources/ContainerizationOS/Path.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public struct Path {
3333
}
3434

3535
private static func lookup(_ name: String, path: String) -> URL? {
36+
// Return nil for empty names
37+
if name.isEmpty {
38+
return nil
39+
}
40+
3641
if name.contains("/") {
3742
if findExec(name) {
3843
return URL(fileURLWithPath: name)

0 commit comments

Comments
 (0)