@@ -1548,18 +1548,36 @@ def _createTemporaryDirectory():
15481548 Creates temporary directory for this run.
15491549 """
15501550
1551- try :
1552- if not os .path .isdir (tempfile .gettempdir ()):
1553- os .makedirs (tempfile .gettempdir ())
1554- except IOError , ex :
1555- errMsg = "there has been a problem while accessing "
1556- errMsg += "system's temporary directory location(s) ('%s'). Please " % getSafeExString (ex )
1557- errMsg += "make sure that there is enough disk space left. If problem persists, "
1558- errMsg += "try to set environment variable 'TEMP' to a location "
1559- errMsg += "writeable by the current user"
1560- raise SqlmapSystemException , errMsg
1561-
1562- if "sqlmap" not in (tempfile .tempdir or "" ):
1551+ if conf .tmpDir :
1552+ try :
1553+ if not os .path .isdir (conf .tmpDir ):
1554+ os .makedirs (conf .tmpDir )
1555+
1556+ _ = os .path .join (conf .tmpDir , randomStr ())
1557+ open (_ , "w+b" ).close ()
1558+ os .remove (_ )
1559+
1560+ tempfile .tempdir = conf .tmpDir
1561+
1562+ warnMsg = "using '%s' as the temporary directory" % conf .tmpDir
1563+ logger .warn (warnMsg )
1564+ except (OSError , IOError ), ex :
1565+ errMsg = "there has been a problem while accessing "
1566+ errMsg += "temporary directory location(s) ('%s')" % getSafeExString (ex )
1567+ raise SqlmapSystemException , errMsg
1568+ else :
1569+ try :
1570+ if not os .path .isdir (tempfile .gettempdir ()):
1571+ os .makedirs (tempfile .gettempdir ())
1572+ except IOError , ex :
1573+ errMsg = "there has been a problem while accessing "
1574+ errMsg += "system's temporary directory location(s) ('%s'). Please " % getSafeExString (ex )
1575+ errMsg += "make sure that there is enough disk space left. If problem persists, "
1576+ errMsg += "try to set environment variable 'TEMP' to a location "
1577+ errMsg += "writeable by the current user"
1578+ raise SqlmapSystemException , errMsg
1579+
1580+ if "sqlmap" not in (tempfile .tempdir or "" ) or conf .tmpDir and tempfile .tempdir == conf .tmpDir :
15631581 tempfile .tempdir = tempfile .mkdtemp (prefix = "sqlmap" , suffix = str (os .getpid ()))
15641582
15651583 kb .tempDir = tempfile .tempdir
0 commit comments