diff --git a/lib/core/option.py b/lib/core/option.py index 8e154e697..e6a1f6664 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1379,9 +1379,6 @@ def __purgeOutput(): """ if conf.purgeOutput and os.path.isdir(paths.SQLMAP_OUTPUT_PATH): - infoMsg = "purging content of output directory ('%s')" % paths.SQLMAP_OUTPUT_PATH - logger.info(infoMsg) - purge(paths.SQLMAP_OUTPUT_PATH) def __setConfAttributes(): diff --git a/lib/core/purge.py b/lib/core/purge.py index 1ec9b7e84..4917fa556 100644 --- a/lib/core/purge.py +++ b/lib/core/purge.py @@ -20,6 +20,12 @@ def purge(directory): Safely removes content from a given directory """ + if not os.path.isdir(directory): + return + + infoMsg = "purging content of directory ('%s'). Please wait. This could take a while..." % directory + logger.info(infoMsg) + filepaths = [] dirpaths = [] @@ -27,14 +33,14 @@ def purge(directory): dirpaths.extend([os.path.abspath(os.path.join(rootpath, _)) for _ in directories]) filepaths.extend([os.path.abspath(os.path.join(rootpath, _)) for _ in filenames]) - logger.info("changing file attributes...") + logger.debug("changing file attributes...") for filepath in filepaths: try: os.chmod(filepath, stat.S_IREAD | stat.S_IWRITE) except: pass - logger.info("writing random data to files...") + logger.debug("writing random data to files...") for filepath in filepaths: try: filesize = os.path.getsize(filepath) @@ -43,7 +49,7 @@ def purge(directory): except: pass - logger.info("truncating files...") + logger.debug("truncating files...") for filepath in filepaths: try: with open(filepath, 'w') as f: @@ -51,7 +57,7 @@ def purge(directory): except: pass - logger.info("renaming filenames to random values...") + logger.debug("renaming filenames to random values...") for filepath in filepaths: try: os.rename(filepath, os.path.join(os.path.dirname(filepath), "".join(random.sample(string.letters, random.randint(4, 8))))) @@ -60,15 +66,13 @@ def purge(directory): dirpaths.sort(cmp = lambda x, y: y.count(os.path.sep) - x.count(os.path.sep)) - logger.info("renaming directory names to random values...") + logger.debug("renaming directory names to random values...") for dirpath in dirpaths: try: os.rename(dirpath, os.path.join(os.path.dirname(dirpath), "".join(random.sample(string.letters, random.randint(4, 8))))) except: pass - logger.info("deleting the whole directory tree...") + logger.debug("deleting the whole directory tree...") os.chdir(os.path.join(directory, "..")) shutil.rmtree(directory) - - logger.info("purging done")