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

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