Blame SOURCES/0047-python-Split-semanage-import-into-two-transactions.patch

e86716
From 09c944561c76146b1fc11e99e95b6a674366cddf Mon Sep 17 00:00:00 2001
e86716
From: Vit Mojzis <vmojzis@redhat.com>
e86716
Date: Mon, 30 May 2022 14:20:21 +0200
e86716
Subject: [PATCH] python: Split "semanage import" into two transactions
e86716
e86716
First transaction applies all deletion operations, so that there are no
e86716
collisions when applying the rest of the changes.
e86716
e86716
Fixes:
e86716
  # semanage port -a -t http_cache_port_t -r s0 -p tcp 3024
e86716
  # semanage export | semanage import
e86716
  ValueError: Port tcp/3024 already defined
e86716
e86716
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
e86716
---
e86716
 python/semanage/semanage | 21 +++++++++++++++++++--
e86716
 1 file changed, 19 insertions(+), 2 deletions(-)
e86716
e86716
diff --git a/python/semanage/semanage b/python/semanage/semanage
e86716
index ebb93ea5..b8842d28 100644
e86716
--- a/python/semanage/semanage
e86716
+++ b/python/semanage/semanage
e86716
@@ -841,10 +841,29 @@ def handleImport(args):
e86716
     trans = seobject.semanageRecords(args)
e86716
     trans.start()
e86716
 
e86716
+    deleteCommands = []
e86716
+    commands = []
e86716
+    # separate commands for deletion from the rest so they can be
e86716
+    # applied in a separate transaction
e86716
     for l in sys.stdin.readlines():
e86716
         if len(l.strip()) == 0:
e86716
             continue
e86716
+        if "-d" in l or "-D" in l:
e86716
+            deleteCommands.append(l)
e86716
+        else:
e86716
+            commands.append(l)
e86716
+
e86716
+    if deleteCommands:
e86716
+        importHelper(deleteCommands)
e86716
+        trans.finish()
e86716
+        trans.start()
e86716
+
e86716
+    importHelper(commands)
e86716
+    trans.finish()
e86716
 
e86716
+
e86716
+def importHelper(commands):
e86716
+    for l in commands:
e86716
         try:
e86716
             commandParser = createCommandParser()
e86716
             args = commandParser.parse_args(mkargv(l))
e86716
@@ -858,8 +877,6 @@ def handleImport(args):
e86716
         except KeyboardInterrupt:
e86716
             sys.exit(0)
e86716
 
e86716
-    trans.finish()
e86716
-
e86716
 
e86716
 def setupImportParser(subparsers):
e86716
     importParser = subparsers.add_parser('import', help=_('Import local customizations'))
e86716
-- 
e86716
2.35.3
e86716