Skip to content

Commit 5746ec3

Browse files
authored
Fix: prevent delete default network (apple#1083)
- Fixed apple#1073 - Move the conditional check to the front; there's no need to check for a default network after filtering. Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
1 parent c42108d commit 5746ec3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

‎Sources/ContainerCommands/Network/NetworkDelete.swift‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ extension Application {
5454
let uniqueNetworkNames = Set<String>(networkNames)
5555
let networks: [NetworkState]
5656

57+
if uniqueNetworkNames.contains(ClientNetwork.defaultNetworkName) {
58+
throw ContainerizationError(
59+
.invalidArgument,
60+
message: "cannot delete the default network"
61+
)
62+
}
63+
5764
if all {
5865
networks = try await ClientNetwork.list()
66+
.filter { $0.id != ClientNetwork.defaultNetworkName }
5967
} else {
6068
networks = try await ClientNetwork.list()
6169
.filter { c in
@@ -78,13 +86,6 @@ extension Application {
7886
}
7987
}
8088

81-
if uniqueNetworkNames.contains(ClientNetwork.defaultNetworkName) {
82-
throw ContainerizationError(
83-
.invalidArgument,
84-
message: "cannot delete the default network"
85-
)
86-
}
87-
8889
var failed = [String]()
8990
let logger = log
9091
try await withThrowingTaskGroup(of: NetworkState?.self) { group in

0 commit comments

Comments
 (0)