Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23fb753

Browse files
committed
Finishing work on Issue #52
1 parent 40fc648 commit 23fb753

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

lib/core/update.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
See the file 'doc/COPYING' for copying permission
66
"""
77

8+
import os
89
import re
910
import time
1011

@@ -25,31 +26,39 @@ def update():
2526
if not conf.updateAll:
2627
return
2728

29+
success = False
2830
rootDir = paths.SQLMAP_ROOT_PATH
2931

30-
infoMsg = "updating sqlmap to the latest development version from the "
31-
infoMsg += "GitHub repository"
32-
logger.info(infoMsg)
32+
if not os.path.exists(os.path.join(rootDir, ".git")):
33+
errMsg = "not a git repository. Please checkout the 'sqlmapproject/sqlmap' repository "
34+
errMsg += "from GitHub (e.g. git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev)"
35+
logger.error(errMsg)
36+
else:
37+
infoMsg = "updating sqlmap to the latest development version from the "
38+
infoMsg += "GitHub repository"
39+
logger.info(infoMsg)
3340

34-
debugMsg = "sqlmap will try to update itself using 'git' command"
35-
logger.debug(debugMsg)
41+
debugMsg = "sqlmap will try to update itself using 'git' command"
42+
logger.debug(debugMsg)
3643

37-
dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X"))
38-
process = execute("git pull %s" % rootDir, shell=True, stdout=PIPE, stderr=PIPE)
39-
pollProcess(process, True)
40-
stdout, stderr = process.communicate()
44+
dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X"))
45+
process = execute("git pull %s" % rootDir, shell=True, stdout=PIPE, stderr=PIPE)
46+
pollProcess(process, True)
47+
stdout, stderr = process.communicate()
48+
success = not process.returncode
4149

42-
if not process.returncode:
43-
logger.info("%s the latest revision '%s'" % ("already at" if "Already" in stdout else "updated to", REVISION))
44-
else:
45-
logger.error("update could not be completed (%s)" % repr(stderr))
50+
if success:
51+
logger.info("%s the latest revision '%s'" % ("already at" if "Already" in stdout else "updated to", REVISION))
52+
else:
53+
logger.error("update could not be completed ('%s')" % re.sub(r"\W+", " ", stderr).strip())
4654

55+
if not success:
4756
if IS_WIN:
4857
infoMsg = "for Windows platform it's recommended "
4958
infoMsg += "to use a GitHub for Windows client for updating "
5059
infoMsg += "purposes (http://windows.github.com/)"
5160
else:
52-
infoMsg = "for Linux platform it's recommended "
53-
infoMsg += "to use a standard 'git' package (e.g.: 'sudo apt-get install git')"
61+
infoMsg = "for Linux platform it's required "
62+
infoMsg += "to install a standard 'git' package (e.g.: 'sudo apt-get install git')"
5463

5564
logger.info(infoMsg)

0 commit comments

Comments
 (0)