##// 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 def _is_trusted(self, fp, f, warn=True):
96 def _is_trusted(self, fp, f, warn=True):
97 if not self.check_trusted:
97 if not self.check_trusted:
98 return True
98 return True
99 st = util.fstat(fp)
100 if util.isowner(fp, st):
101 return True
99 tusers = self.trusted_users
102 tusers = self.trusted_users
100 tgroups = self.trusted_groups
103 tgroups = self.trusted_groups
101 if (tusers or tgroups) and '*' not in tusers and '*' not in tgroups:
104 if (tusers or tgroups) and '*' not in tusers and '*' not in tgroups:
102 st = util.fstat(fp)
103 user = util.username(st.st_uid)
105 user = util.username(st.st_uid)
104 group = util.groupname(st.st_gid)
106 group = util.groupname(st.st_gid)
105 if user not in tusers and group not in tgroups:
107 if user not in tusers and group not in tgroups:
@@ -654,6 +654,11 b" if os.name == 'nt':"
654 def explain_exit(code):
654 def explain_exit(code):
655 return _("exited with status %d") % code, code
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 try:
662 try:
658 # override functions with win32 versions if possible
663 # override functions with win32 versions if possible
659 from util_win32 import *
664 from util_win32 import *
@@ -765,6 +770,16 b' else:'
765 return _("stopped by signal %d") % val, val
770 return _("stopped by signal %d") % val, val
766 raise ValueError(_("invalid exit code"))
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 def opener(base, audit=True):
783 def opener(base, audit=True):
769 """
784 """
770 return a function that opens files relative to base
785 return a function that opens files relative to base
@@ -41,6 +41,10 b" def testui(user='foo', group='bar', tuse"
41 return group
41 return group
42 util.groupname = groupname
42 util.groupname = groupname
43
43
44 def isowner(fp, st=None):
45 return user == cuser
46 util.isowner = isowner
47
44 # try to read everything
48 # try to read everything
45 #print '# File belongs to user %s, group %s' % (user, group)
49 #print '# File belongs to user %s, group %s' % (user, group)
46 #print '# trusted users = %s; trusted groups = %s' % (tusers, tgroups)
50 #print '# trusted users = %s; trusted groups = %s' % (tusers, tgroups)
General Comments 0
You need to be logged in to leave comments. Login now