فهرست منبع

libnetwork/iptables: IPTable.exists(): return early on error

Also remove a redundant string cast for the Table value.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 سال پیش
والد
کامیت
04e54c6bb0
1فایلهای تغییر یافته به همراه7 افزوده شده و 7 حذف شده
  1. 7 7
      libnetwork/iptables/iptables.go

+ 7 - 7
libnetwork/iptables/iptables.go

@@ -450,21 +450,21 @@ func (iptable IPTable) ExistsNative(table Table, chain string, rule ...string) b
 }
 }
 
 
 func (iptable IPTable) exists(native bool, table Table, chain string, rule ...string) bool {
 func (iptable IPTable) exists(native bool, table Table, chain string, rule ...string) bool {
+	if err := initCheck(); err != nil {
+		// The exists() signature does not allow us to return an error, but at least
+		// we can skip the (likely invalid) exec invocation.
+		return false
+	}
+
 	f := iptable.Raw
 	f := iptable.Raw
 	if native {
 	if native {
 		f = iptable.raw
 		f = iptable.raw
 	}
 	}
 
 
-	if string(table) == "" {
+	if table == "" {
 		table = Filter
 		table = Filter
 	}
 	}
 
 
-	if err := initCheck(); err != nil {
-		// The exists() signature does not allow us to return an error, but at least
-		// we can skip the (likely invalid) exec invocation.
-		return false
-	}
-
 	// if exit status is 0 then return true, the rule exists
 	// if exit status is 0 then return true, the rule exists
 	_, err := f(append([]string{"-t", string(table), "-C", chain}, rule...)...)
 	_, err := f(append([]string{"-t", string(table), "-C", chain}, rule...)...)
 	return err == nil
 	return err == nil