From: Kacper Date: Wed, 30 Aug 2023 12:33:49 +0000 (+0200) Subject: samba-tool: Fix for gpo restore not working without --tmpdir X-Git-Tag: tevent-0.16.0~307 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=90ba53eee4a3614da81ee562be2a55c01888c2cf;p=thirdparty%2Fsamba.git samba-tool: Fix for gpo restore not working without --tmpdir cmd_restore depends on cmd_create but the later cleans up required temp files for cmd_restore to function. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15462 RN: Fix for gpo restore not working without --tmpdir Signed-off-by: Kacper Boström Reviewed-by: Andrew Bartlett Reviewed-by: David Mulder Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Fri Sep 29 03:15:18 UTC 2023 on atb-devel-224 --- diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index 7c2df29bdc5..e32837a0f0c 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -1664,6 +1664,11 @@ class cmd_restore(cmd_create): credopts, versionopts) try: + if tmpdir is None: + # Create GPT + self.tmpdir, gpodir = self.construct_tmpdir(tmpdir, self.gpo_name) + self.gpodir = gpodir + # Iterate over backup files and restore with DTD self.restore_from_backup_to_local_dir(backup, self.gpodir, dtd_header) @@ -1692,6 +1697,10 @@ class cmd_restore(cmd_create): self.samdb.modify(m) + if tmpdir is None: + # Without --tmpdir, we created one in /tmp/. It must go. + shutil.rmtree(self.tmpdir) + except Exception as e: import traceback traceback.print_exc()