Skip to content

Commit abaf812

Browse files
vmojzisjwcart2
authored andcommitted
python: Split "semanage import" into two transactions
First transaction applies all deletion operations, so that there are no collisions when applying the rest of the changes. Fixes: # semanage port -a -t http_cache_port_t -r s0 -p tcp 3024 # semanage export | semanage import ValueError: Port tcp/3024 already defined Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
1 parent c8ba796 commit abaf812

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

python/semanage/semanage

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,29 @@ def handleImport(args):
852852
trans = seobject.semanageRecords(args)
853853
trans.start()
854854

855+
deleteCommands = []
856+
commands = []
857+
# separate commands for deletion from the rest so they can be
858+
# applied in a separate transaction
855859
for l in sys.stdin.readlines():
856860
if len(l.strip()) == 0:
857861
continue
862+
if "-d" in l or "-D" in l:
863+
deleteCommands.append(l)
864+
else:
865+
commands.append(l)
866+
867+
if deleteCommands:
868+
importHelper(deleteCommands)
869+
trans.finish()
870+
trans.start()
871+
872+
importHelper(commands)
873+
trans.finish()
858874

875+
876+
def importHelper(commands):
877+
for l in commands:
859878
try:
860879
commandParser = createCommandParser()
861880
args = commandParser.parse_args(mkargv(l))
@@ -869,8 +888,6 @@ def handleImport(args):
869888
except KeyboardInterrupt:
870889
sys.exit(0)
871890

872-
trans.finish()
873-
874891

875892
def setupImportParser(subparsers):
876893
importParser = subparsers.add_parser('import', help=_('Import local customizations'))

0 commit comments

Comments
 (0)