changeset 8141:e40b629bedd1

ui: cleanup _is_trusted a bit
author Matt Mackall <mpm@selenic.com>
date Thu, 23 Apr 2009 15:40:10 -0500
parents 7c47ac9620a8
children 912bfef12ba6
files mercurial/ui.py tests/test-trusted.py.out
diffstat 2 files changed, 17 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Thu Apr 23 15:40:10 2009 -0500
+++ b/mercurial/ui.py	Thu Apr 23 15:40:10 2009 -0500
@@ -37,6 +37,7 @@
             self.overlay = util.configparser()
             self.cdata = util.configparser()
             self.ucdata = util.configparser()
+
             # we always trust global config files
             self.readconfig(util.rcpath(), assumetrusted=True)
         else:
@@ -63,26 +64,25 @@
                 ui._isatty = False
         return ui._isatty
 
-    def _is_trusted(self, fp, f, warn=True):
+    def _is_trusted(self, fp, f):
         st = util.fstat(fp)
         if util.isowner(fp, st):
             return True
+
         tusers = self.trusted_users
         tgroups = self.trusted_groups
-        if not tusers:
-            user = util.username()
-            if user is not None:
-                self.trusted_users[user] = 1
-                self.fixconfig(section='trusted')
-        if (tusers or tgroups) and '*' not in tusers and '*' not in tgroups:
-            user = util.username(st.st_uid)
-            group = util.groupname(st.st_gid)
-            if user not in tusers and group not in tgroups:
-                if warn and self.report_untrusted:
-                    self.warn(_('Not trusting file %s from untrusted '
-                                'user %s, group %s\n') % (f, user, group))
-                return False
-        return True
+        if '*' in tusers or '*' in tgroups:
+            return True
+
+        user = util.username(st.st_uid)
+        group = util.groupname(st.st_gid)
+        if user in tusers or group in tgroups or user == util.username():
+            return True
+
+        if self.report_untrusted:
+            self.warn(_('Not trusting file %s from untrusted '
+                        'user %s, group %s\n') % (f, user, group))
+        return False
 
     def readconfig(self, fn, root=None, assumetrusted=False):
         cdata = util.configparser()
@@ -175,7 +175,7 @@
             self.traceback = self.configbool('ui', 'traceback', False)
 
         # update trust information
-        if (section is None or section == 'trusted') and self.trusted_users:
+        if section is None or section == 'trusted':
             for user in self.configlist('trusted', 'users'):
                 self.trusted_users[user] = 1
             for group in self.configlist('trusted', 'groups'):
--- a/tests/test-trusted.py.out	Thu Apr 23 15:40:10 2009 -0500
+++ b/tests/test-trusted.py.out	Thu Apr 23 15:40:10 2009 -0500
@@ -143,10 +143,9 @@
 
 # Can't figure out the name of the user running this process
 # different user, different group
+Not trusting file .hg/hgrc from untrusted user abc, group def
 trusted
     global = /some/path
-    interpolated = /some/path/another/path
-    local = /another/path
 untrusted
 . . global = /some/path
 . . interpolated = /some/path/another/path