Rev 5652: (jameinel) Bug #660174, in file:///home/pqm/archives/thelove/bzr/2.3/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Jun 15 19:44:56 UTC 2011


At file:///home/pqm/archives/thelove/bzr/2.3/

------------------------------------------------------------
revno: 5652 [merge]
revision-id: pqm at pqm.ubuntu.com-20110615194453-jnzh5voa3sjdm7qu
parent: pqm at pqm.ubuntu.com-20110609145625-av5fshuaujij0qe8
parent: bialix at ukr.net-20110615152154-wpjjsa676v33nuk2
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.3
timestamp: Wed 2011-06-15 19:44:53 +0000
message:
  (jameinel) Bug #660174,
   trap accidental import of pwd on Windows where it doesn't exist. (Alexander
   Belchenko)
modified:
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/features.py       features.py-20090820042958-jglgza3wrn03ha9e-1
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
  doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2011-01-12 21:06:32 +0000
+++ b/bzrlib/osutils.py	2011-06-15 15:19:32 +0000
@@ -2369,6 +2369,18 @@
     except UnicodeDecodeError:
         raise errors.BzrError("Can't decode username as %s." % \
                 user_encoding)
+    except ImportError, e:
+        if sys.platform != 'win32':
+            raise
+        if str(e) != 'No module named pwd':
+            raise
+        # https://bugs.launchpad.net/bzr/+bug/660174
+        # getpass.getuser() is unable to return username on Windows
+        # if there is no USERNAME environment variable set.
+        # That could be true if bzr is running as a service,
+        # e.g. running `bzr serve` as a service on Windows.
+        # We should not fail with traceback in this case.
+        username = u'UNKNOWN'
     return username
 
 

=== modified file 'bzrlib/tests/features.py'
--- a/bzrlib/tests/features.py	2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/features.py	2011-06-15 14:14:11 +0000
@@ -18,6 +18,7 @@
 
 import os
 import stat
+import sys
 
 from bzrlib import tests
 
@@ -131,3 +132,17 @@
 bash_feature = ExecutableFeature('bash')
 sed_feature = ExecutableFeature('sed')
 diff_feature = ExecutableFeature('diff')
+
+
+class Win32Feature(tests.Feature):
+    """Feature testing whether we're running selftest on Windows
+    or Windows-like platform.
+    """
+
+    def _probe(self):
+        return sys.platform == 'win32'
+
+    def feature_name(self):
+        return "win32 platform"
+
+win32_feature = Win32Feature()

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2011-05-13 11:34:44 +0000
+++ b/bzrlib/tests/test_osutils.py	2011-06-15 15:21:54 +0000
@@ -2036,6 +2036,7 @@
         # Whatever the result is, if we don't raise an exception, it's ok.
         osutils.terminal_width()
 
+
 class TestCreationOps(tests.TestCaseInTempDir):
     _test_needs_features = [features.chown_feature]
 
@@ -2071,6 +2072,7 @@
         self.assertEquals(self.uid, s.st_uid)
         self.assertEquals(self.gid, s.st_gid)
 
+
 class TestGetuserUnicode(tests.TestCase):
 
     def test_ascii_user(self):
@@ -2091,6 +2093,13 @@
         self.overrideEnv('LOGNAME', u'jrandom\xb6'.encode(ue))
         self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
 
+    def test_no_username_bug_660174(self):
+        self.requireFeature(features.win32_feature)
+        for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
+            self.overrideEnv(name, None)
+        self.assertEqual(u'UNKNOWN', osutils.getuser_unicode())
+
+
 class TestBackupNames(tests.TestCase):
 
     def setUp(self):

=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt	2011-06-09 12:17:09 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt	2011-06-15 14:03:58 +0000
@@ -33,6 +33,10 @@
 .. Fixes for situations where bzr would previously crash or give incorrect
    or undesirable results.
 
+* Don't fail with traceback if `bzr serve` is running as a service on Windows,
+  and there is no USERNAME, nor BZR_EMAIL or other whoami-related environment
+  variables set. (Alexander Belchenko, Bug #660174)
+
 Documentation
 *************
 




More information about the bazaar-commits mailing list