##// END OF EJS Templates
Avoid looking up usernames if the current user owns the .hgrc file...
Alexis S. L. Carvalho -
r3677:1a0fa391 default
parent child Browse files
Show More
@@ -96,10 +96,12 b' class ui(object):'
96 96 def _is_trusted(self, fp, f, warn=True):
97 97 if not self.check_trusted:
98 98 return True
99 st = util.fstat(fp)
100 if util.isowner(fp, st):
101 return True
99 102 tusers = self.trusted_users
100 103 tgroups = self.trusted_groups
101 104 if (tusers or tgroups) and '*' not in tusers and '*' not in tgroups:
102 st = util.fstat(fp)
103 105 user = util.username(st.st_uid)
104 106 group = util.groupname(st.st_gid)
105 107 if user not in tusers and group not in tgroups:
@@ -654,6 +654,11 b" if os.name == 'nt':"
654 654 def explain_exit(code):
655 655 return _("exited with status %d") % code, code
656 656
657 # if you change this stub into a real check, please try to implement the
658 # username and groupname functions above, too.
659 def isowner(fp, st=None):
660 return True
661
657 662 try:
658 663 # override functions with win32 versions if possible
659 664 from util_win32 import *
@@ -765,6 +770,16 b' else:'
765 770 return _("stopped by signal %d") % val, val
766 771 raise ValueError(_("invalid exit code"))
767 772
773 def isowner(fp, st=None):
774 """Return True if the file object f belongs to the current user.
775
776 The return value of a util.fstat(f) may be passed as the st argument.
777 """
778 if st is None:
779 st = fstat(f)
780 return st.st_uid == os.getuid()
781
782
768 783 def opener(base, audit=True):
769 784 """
770 785 return a function that opens files relative to base
@@ -41,6 +41,10 b" def testui(user='foo', group='bar', tuse"
41 41 return group
42 42 util.groupname = groupname
43 43
44 def isowner(fp, st=None):
45 return user == cuser
46 util.isowner = isowner
47
44 48 # try to read everything
45 49 #print '# File belongs to user %s, group %s' % (user, group)
46 50 #print '# trusted users = %s; trusted groups = %s' % (tusers, tgroups)
General Comments 0
You need to be logged in to leave comments. Login now