[virt-manager PATCH 3/3] installer*.py: Remove temporary dirs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Together with the temporary files removal, let's also remove the
directories created to store those files.

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 virtinst/installer.py          | 10 ++++++++++
 virtinst/installertreemedia.py |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/virtinst/installer.py b/virtinst/installer.py
index ca23d526..24653d3c 100644
--- a/virtinst/installer.py
+++ b/virtinst/installer.py
@@ -140,10 +140,20 @@ class Installer(object):
         self._install_floppy_device.sync_path_props()
 
     def _cleanup_unattended_files(self):
+        dirs = []
         for f in self._unattended_files:
+            dirname = os.path.dirname(f)
+            if dirname not in dirs:
+                dirs.append(dirname)
+
             logging.debug("Removing %s", str(f))
             os.unlink(f)
 
+        for d in dirs:
+            if not os.listdir(d):
+                logging.debug("Removing %s", str(d))
+                os.rmdir(d)
+
     def _build_boot_order(self, guest, bootdev):
         bootorder = [bootdev]
 
diff --git a/virtinst/installertreemedia.py b/virtinst/installertreemedia.py
index ea522904..d7fef898 100644
--- a/virtinst/installertreemedia.py
+++ b/virtinst/installertreemedia.py
@@ -208,10 +208,19 @@ class InstallerTreeMedia(object):
 
     def cleanup(self, guest):
         ignore = guest
+        dirs = []
         for f in self._tmpfiles:
+            dirname = os.path.dirname(f)
+            if dirname not in dirs:
+                dirs.append(dirname)
             logging.debug("Removing %s", str(f))
             os.unlink(f)
 
+        for d in dirs:
+            if not os.listdir(d):
+                logging.debug("Removing %s", d)
+                os.rmdir(d)
+
         for vol in self._tmpvols:
             logging.debug("Removing volume '%s'", vol.name())
             vol.delete(0)
-- 
2.21.0

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list




[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux