Skip to content

Commit 3ac60eb

Browse files
committed
Fix Environment.updating for custom and rawBytes
1 parent d781b8f commit 3ac60eb

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

Sources/Subprocess/Configuration.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,32 @@ public struct Environment: Sendable, Hashable {
422422
/// Keys with `nil` values in `newValue` will be removed from existing
423423
/// `Environment` before passing to child process.
424424
public func updating(_ newValue: [Key: String?]) -> Self {
425-
return .init(config: .inherit(newValue))
425+
switch config {
426+
case .inherit(var overrides):
427+
for (key, value) in newValue {
428+
overrides[key] = value
429+
}
430+
return .init(config: .inherit(overrides))
431+
case .custom(var environment):
432+
for (key, value) in newValue {
433+
environment[key] = value
434+
}
435+
return .init(config: .custom(environment))
436+
#if !os(Windows)
437+
case .rawBytes(var rawBytesArray):
438+
let overriddenKeys = newValue.keys.map { Array("\($0)=".utf8) }
439+
rawBytesArray.removeAll {
440+
overriddenKeys.contains(where: $0.starts)
441+
}
442+
443+
for (key, value) in newValue {
444+
if let value {
445+
rawBytesArray.append(Array("\(key)=\(value)".utf8))
446+
}
447+
}
448+
return .init(config: .rawBytes(rawBytesArray))
449+
#endif
450+
}
426451
}
427452
/// Use custom environment variables
428453
public static func custom(_ newValue: [Key: String]) -> Self {

0 commit comments

Comments
 (0)