def cleanupdir(self, path, ignoreErrors=True): cleanupdir_errors = [] try: files = self._iop.listdir(path) except OSError: if not ignoreErrors: raise else: for f in files: fullpath = os.path.join(path, f) if _IOProcessOs(self._iop).path.isdir(fullpath): try: self.cleanupdir(fullpath, ignoreErrors) except OSError as e: cleanupdir_errors.append(e) else: try: self._iop.unlink(fullpath) except Exception as e: cleanupdir_errors.append('%s: %s' % ("unlink", e)) try: self._iop.rmdir(path) except Exception as e: cleanupdir_errors.append('%s: %s' % ("rmdir", e)) if not ignoreErrors and cleanupdir_errors: raise se.MiscDirCleanupFailure("%s %s" % (path, cleanupdir_errors))
def cleanupdir(dirPath, ignoreErrors=True): """ Recursively remove all the files and directories in the given directory """ cleanupdir_errors = [] def logit(func, path, exc_info): cleanupdir_errors.append('%s: %s' % (func.__name__, exc_info[1])) shutil.rmtree(dirPath, onerror=logit) if not ignoreErrors and cleanupdir_errors: raise se.MiscDirCleanupFailure("%s %s" % (dirPath, cleanupdir_errors))
def format(cls, sdUUID): """ Format detached storage domain. This removes all data from the storage domain. """ cls.log.info("Formatting domain %s", sdUUID) try: domaindir = cls.findDomainPath(sdUUID) except (se.StorageDomainDoesNotExist): pass else: try: oop.getProcessPool(sdUUID).fileUtils.cleanupdir( domaindir, ignoreErrors=False) except RuntimeError as e: raise se.MiscDirCleanupFailure(str(e)) return True