samba-tool: Fix for gpo restore not working without --tmpdir
[samba.git] / python / samba / netcmd / gpo.py
index 7c2df29bdc5de059b88ea6b011d68117d4d1491c..e32837a0f0c345d6e85728d040a346dac909ea93 100644 (file)
@@ -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()