python: Split "semanage import" into two transactions
PATCH 1/1 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 <[email protected]>
--- python/semanage/semanage | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
python/semanage/semanage +19 -2
@@ -852,10 +852,29 @@ def handleImport(args): trans = seobject.semanageRecords(args) trans.start() + deleteCommands = [] + commands = [] + # separate commands for deletion from the rest so they can be + # applied in a separate transaction for l in sys.stdin.readlines(): if len(l.strip()) == 0: continue + if "-d" in l or "-D" in l: + deleteCommands.append(l) + else: + commands.append(l) + + if deleteCommands: + importHelper(deleteCommands) + trans.finish() + trans.start() + + importHelper(commands) + trans.finish() + +def importHelper(commands): + for l in commands: try: commandParser = createCommandParser() args = commandParser.parse_args(mkargv(l))
@@ -869,8 +888,6 @@ def handleImport(args): except KeyboardInterrupt: sys.exit(0) - trans.finish() - def setupImportParser(subparsers): importParser = subparsers.add_parser('import', help=_('Import local customizations'))
Signature · 1 line
2.35.1
Quoted 10 lines · Vit Mojzis
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 definedSigned-off-by Vit Mojzis <[email protected]>
Acked-by James Carter <[email protected]>
Quoted 50 lines
--- python/semanage/semanage | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)python/semanage/semanage +19
-3@@ -852,10 +852,29 @@ def handleImport(args): trans = seobject.semanageRecords(args) trans.start() + deleteCommands = [] + commands = [] + # separate commands for deletion from the rest so they can be + # applied in a separate transaction for l in sys.stdin.readlines(): if len(l.strip()) == 0: continue + if "-d" in l or "-D" in l: + deleteCommands.append(l) + else: + commands.append(l) + + if deleteCommands: + importHelper(deleteCommands) + trans.finish() + trans.start() + + importHelper(commands) + trans.finish() + +def importHelper(commands): + for l in commands: try: commandParser = createCommandParser() args = commandParser.parse_args(mkargv(l))@@ -869,8 +888,6 @@ def handleImport(args): except KeyboardInterrupt: sys.exit(0) - trans.finish() - def setupImportParser(subparsers): importParser = subparsers.add_parser('import', help=_('Import local customizations')) --2.35.1
Quoted 6 lines · James Carter
Quoted 4 lines · Vit Mojzis
First transaction applies all deletion operations, so that there are no collisions when applying the rest of the changes.
Quoted 9 lines
Quoted 6 lines
Fixes:
# semanage port -a -t http_cache_port_t -r s0 -p tcp 3024 # semanage export | semanage import ValueError: Port tcp/3024 already definedSigned-off-by Vit Mojzis <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 51 lines
Quoted 51 lines
--- python/semanage/semanage | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)python/semanage/semanage +19
-3@@ -852,10 +852,29 @@ def handleImport(args): trans = seobject.semanageRecords(args) trans.start() + deleteCommands = [] + commands = [] + # separate commands for deletion from the rest so they can be + # applied in a separate transaction for l in sys.stdin.readlines(): if len(l.strip()) == 0: continue + if "-d" in l or "-D" in l: + deleteCommands.append(l) + else: + commands.append(l) + + if deleteCommands: + importHelper(deleteCommands) + trans.finish() + trans.start() + + importHelper(commands) + trans.finish() + +def importHelper(commands): + for l in commands: try: commandParser = createCommandParser() args = commandParser.parse_args(mkargv(l))@@ -869,8 +888,6 @@ def handleImport(args): except KeyboardInterrupt: sys.exit(0) - trans.finish() - def setupImportParser(subparsers): importParser = subparsers.add_parser('import', help=_('Import local customizations')) --2.35.1