Rev 6542: (jelmer) Only read the first line from /etc/mailname. (Haw Loeung) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jul 24 13:25:42 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6542 [merge]
revision-id: pqm at pqm.ubuntu.com-20120724132542-5e7aakd1c3t9oggf
parent: pqm at pqm.ubuntu.com-20120723194645-5a57w8fw122aei34
parent: haw.loeung at canonical.com-20120724125336-r3wzxm02lyec7jm6
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2012-07-24 13:25:42 +0000
message:
  (jelmer) Only read the first line from /etc/mailname. (Haw Loeung)
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
  doc/en/release-notes/bzr-2.6.txt bzr2.6.txt-20120116134316-8w1xxom1c7vcu1t5-1
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2012-06-19 16:36:07 +0000
+++ b/bzrlib/config.py	2012-07-20 15:46:59 +0000
@@ -1562,7 +1562,7 @@
         return os.path.expanduser('~/.cache')
 
 
-def _get_default_mail_domain():
+def _get_default_mail_domain(mailname_file='/etc/mailname'):
     """If possible, return the assumed default email domain.
 
     :returns: string mail domain, or None.
@@ -1571,11 +1571,11 @@
         # No implementation yet; patches welcome
         return None
     try:
-        f = open('/etc/mailname')
+        f = open(mailname_file)
     except (IOError, OSError), e:
         return None
     try:
-        domain = f.read().strip()
+        domain = f.readline().strip()
         return domain
     finally:
         f.close()

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2012-06-20 14:35:26 +0000
+++ b/bzrlib/tests/test_config.py	2012-07-21 02:00:58 +0000
@@ -4568,8 +4568,8 @@
                                            port=99, path='/foo',
                                            realm='realm')
         CREDENTIALS = {'name': 'name', 'user': 'user', 'password': 'password',
-                       'verify_certificates': False, 'scheme': 'scheme', 
-                       'host': 'host', 'port': 99, 'path': '/foo', 
+                       'verify_certificates': False, 'scheme': 'scheme',
+                       'host': 'host', 'port': 99, 'path': '/foo',
                        'realm': 'realm'}
         self.assertEqual(CREDENTIALS, credentials)
         credentials_from_disk = config.AuthenticationConfig().get_credentials(
@@ -4583,8 +4583,8 @@
         self.assertIs(None, conf._get_config().get('name'))
         credentials = conf.get_credentials(host='host', scheme='scheme')
         CREDENTIALS = {'name': 'name2', 'user': 'user2', 'password':
-                       'password', 'verify_certificates': True, 
-                       'scheme': 'scheme', 'host': 'host', 'port': None, 
+                       'password', 'verify_certificates': True,
+                       'scheme': 'scheme', 'host': 'host', 'port': None,
                        'path': None, 'realm': None}
         self.assertEqual(CREDENTIALS, credentials)
 
@@ -4876,6 +4876,37 @@
             self.assertEquals((None, None), (realname, address))
 
 
+class TestDefaultMailDomain(tests.TestCaseInTempDir):
+    """Test retrieving default domain from mailname file"""
+
+    def test_default_mail_domain_simple(self):
+        f = file('simple', 'w')
+        try:
+            f.write("domainname.com\n")
+        finally:
+            f.close()
+        r = config._get_default_mail_domain('simple')
+        self.assertEquals('domainname.com', r)
+
+    def test_default_mail_domain_no_eol(self):
+        f = file('no_eol', 'w')
+        try:
+            f.write("domainname.com")
+        finally:
+            f.close()
+        r = config._get_default_mail_domain('no_eol')
+        self.assertEquals('domainname.com', r)
+
+    def test_default_mail_domain_multiple_lines(self):
+        f = file('multiple_lines', 'w')
+        try:
+            f.write("domainname.com\nsome other text\n")
+        finally:
+            f.close()
+        r = config._get_default_mail_domain('multiple_lines')
+        self.assertEquals('domainname.com', r)
+
+
 class EmailOptionTests(tests.TestCase):
 
     def test_default_email_uses_BZR_EMAIL(self):

=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- a/doc/en/release-notes/bzr-2.6.txt	2012-07-23 19:46:45 +0000
+++ b/doc/en/release-notes/bzr-2.6.txt	2012-07-24 12:53:36 +0000
@@ -31,8 +31,10 @@
 Bug Fixes
 *********
 
-.. Fixes for situations where bzr would previously crash or give incorrect
-   or undesirable results.
+* Fixed a bug where the entire contents of ``/etc/mailname`` is read in.
+  We only want to read in the first line so that comments could be added
+  and would be ignored.
+  (Haw Loeung, #932515)
 
 Documentation
 *************




More information about the bazaar-commits mailing list