##// END OF EJS Templates
[PATCH] Harden os.system...
mpm@selenic.com -
r508:42a660ab default
parent child Browse files
Show More
@@ -291,7 +291,7 def clone(ui, source, dest = None, **opt
291
291
292 if link:
292 if link:
293 ui.debug("copying by hardlink\n")
293 ui.debug("copying by hardlink\n")
294 os.system("cp -al %s/.hg .hg" % source)
294 util.system("cp -al %s/.hg .hg" % source)
295 try:
295 try:
296 os.remove(".hg/dirstate")
296 os.remove(".hg/dirstate")
297 except: pass
297 except: pass
@@ -871,6 +871,8 def dispatch(args):
871 return r
871 return r
872 else:
872 else:
873 return d()
873 return d()
874 except util.CommandError, inst:
875 u.warn("abort: %s\n" % inst.args)
874 except hg.RepoError, inst:
876 except hg.RepoError, inst:
875 u.warn("abort: ", inst, "!\n")
877 u.warn("abort: ", inst, "!\n")
876 except SignalInterrupt:
878 except SignalInterrupt:
@@ -5,7 +5,7
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 import os, sys, re, ConfigParser
8 import os, sys, re, ConfigParser, util
9
9
10 class ui:
10 class ui:
11 def __init__(self, verbose=False, debug=False, quiet=False,
11 def __init__(self, verbose=False, debug=False, quiet=False,
@@ -78,10 +78,7 class ui:
78 f.close()
78 f.close()
79
79
80 editor = os.environ.get("HGEDITOR") or os.environ.get("EDITOR", "vi")
80 editor = os.environ.get("HGEDITOR") or os.environ.get("EDITOR", "vi")
81 r = os.system("%s %s" % (editor, name))
81 util.system("%s %s" % (editor, name), errprefix = "edit failed")
82
83 if r:
84 raise "Edit failed!"
85
82
86 t = open(name).read()
83 t = open(name).read()
87 t = re.sub("(?m)^HG:.*\n", "", t)
84 t = re.sub("(?m)^HG:.*\n", "", t)
@@ -7,6 +7,29
7
7
8 import os
8 import os
9
9
10 class CommandError(Exception): pass
11
12 def explain_exit(code):
13 """return a 2-tuple (desc, code) describing a process's status"""
14 if os.WIFEXITED(code):
15 val = os.WEXITSTATUS(code)
16 return "exited with status %d" % val, val
17 elif os.WIFSIGNALED(code):
18 val = os.WTERMSIG(code)
19 return "killed by signal %d" % val, val
20 elif os.WIFSTOPPED(code):
21 val = os.STOPSIG(code)
22 return "stopped by signal %d" % val, val
23 raise ValueError("invalid exit code")
24
25 def system(cmd, errprefix = "abort"):
26 """execute a shell command that must succeed"""
27 rc = os.system(cmd)
28 if rc:
29 errmsg = "%s: %s %s" % (errprefix, os.path.basename(cmd.split(None, 1)[0]),
30 explain_exit(rc)[0])
31 raise CommandError(errmsg)
32
10 def rename(src, dst):
33 def rename(src, dst):
11 try:
34 try:
12 os.rename(src, dst)
35 os.rename(src, dst)
General Comments 0
You need to be logged in to leave comments. Login now