Rev 4099: (mbp) better OSErrors from _readdir_pyx in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Mar 10 00:49:31 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4099
revision-id: pqm at pqm.ubuntu.com-20090310004923-3gtpq4ned1d6xhoj
parent: pqm at pqm.ubuntu.com-20090309084556-9i2m12qlud2qcrtw
parent: mbp at sourcefrog.net-20090309130035-v2fccwxqc7tfkzkg
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-03-10 00:49:23 +0000
message:
  (mbp) better OSErrors from _readdir_pyx
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
  bzrlib/tests/test_trace.py     testtrace.py-20051110225523-a21117fc7a07eeff
    ------------------------------------------------------------
    revno: 4095.1.4
    revision-id: mbp at sourcefrog.net-20090309130035-v2fccwxqc7tfkzkg
    parent: mbp at sourcefrog.net-20090309125802-guvsapvb980yt85n
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: 338653-oserror
    timestamp: Mon 2009-03-09 23:00:35 +1000
    message:
      Update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4095.1.3
    revision-id: mbp at sourcefrog.net-20090309125802-guvsapvb980yt85n
    parent: mbp at sourcefrog.net-20090309123607-kgyijvh73nhw2euf
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: 338653-oserror
    timestamp: Mon 2009-03-09 22:58:02 +1000
    message:
      Add test for failures inside pyrex readdir
    modified:
      bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
    ------------------------------------------------------------
    revno: 4095.1.2
    revision-id: mbp at sourcefrog.net-20090309123607-kgyijvh73nhw2euf
    parent: mbp at sourcefrog.net-20090309123543-93ok3sjnduu2o8wf
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: 338653-oserror
    timestamp: Mon 2009-03-09 22:36:07 +1000
    message:
      Raise better error messages from Pyrex readdir
    modified:
      bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
    ------------------------------------------------------------
    revno: 4095.1.1
    revision-id: mbp at sourcefrog.net-20090309123543-93ok3sjnduu2o8wf
    parent: pqm at pqm.ubuntu.com-20090309052557-ao3zck4ogpqtvvgt
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: 338653-oserror
    timestamp: Mon 2009-03-09 22:35:43 +1000
    message:
      Add more distinct tests for IOError and OSError
    modified:
      bzrlib/tests/test_trace.py     testtrace.py-20051110225523-a21117fc7a07eeff
=== modified file 'NEWS'
--- a/NEWS	2009-03-09 08:45:56 +0000
+++ b/NEWS	2009-03-10 00:49:23 +0000
@@ -85,6 +85,10 @@
 
   BUG FIXES:
 
+    * Bazaar now gives a better message including the filename if it's
+      unable to read a file in the working directory, for example because
+      of a permission error.  (Martin Pool, #338653)
+
     * ``bzr missing`` now uses ``Repository.get_revision_delta()`` rather
       than fetching trees and determining a delta itself. (Jelmer
       Vernooij, #315048)

=== modified file 'bzrlib/_readdir_pyx.pyx'
--- a/bzrlib/_readdir_pyx.pyx	2008-11-21 04:06:25 +0000
+++ b/bzrlib/_readdir_pyx.pyx	2009-03-09 12:58:02 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, 2008 Canonical Ltd
+# Copyright (C) 2006, 2008, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -298,16 +298,16 @@
         # passing full paths every time.
         orig_dir_fd = open(".", O_RDONLY, 0)
         if orig_dir_fd == -1:
-            raise OSError(errno, strerror(errno))
+            raise OSError(errno, "open: " + strerror(errno), ".")
         if -1 == chdir(path):
-            raise OSError(errno, strerror(errno))
+            raise OSError(errno, "chdir: " + strerror(errno), path)
     else:
         orig_dir_fd = -1
 
     try:
         the_dir = opendir(".")
         if NULL == the_dir:
-            raise OSError(errno, strerror(errno))
+            raise OSError(errno, "opendir: " + strerror(errno), path)
         try:
             result = []
             entry = &sentinel
@@ -330,7 +330,7 @@
                         # we consider ENOTDIR to be 'no error'.
                         continue
                     else:
-                        raise OSError(errno, strerror(errno))
+                        raise OSError(errno, "readdir: " + strerror(errno), path)
                 name = entry.d_name
                 if not (name[0] == c"." and (
                     (name[1] == 0) or 
@@ -340,7 +340,8 @@
                     stat_result = lstat(entry.d_name, &statvalue._st)
                     if stat_result != 0:
                         if errno != ENOENT:
-                            raise OSError(errno, strerror(errno))
+                            raise OSError(errno, "lstat: " + strerror(errno),
+                                path + "/" + entry.d_name)
                         else:
                             kind = _missing
                             statvalue = None
@@ -355,7 +356,7 @@
                         statvalue, None))
         finally:
             if -1 == closedir(the_dir):
-                raise OSError(errno, strerror(errno))
+                raise OSError(errno, "closedir: " + strerror(errno), path)
     finally:
         if -1 != orig_dir_fd:
             failed = False
@@ -363,7 +364,7 @@
                 # try to close the original directory anyhow
                 failed = True
             if -1 == close(orig_dir_fd) or failed:
-                raise OSError(errno, strerror(errno))
+                raise OSError(errno, "return to orig_dir: " + strerror(errno))
 
     return result
 

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2009-03-07 06:58:17 +0000
+++ b/bzrlib/tests/test_osutils.py	2009-03-10 00:49:23 +0000
@@ -879,6 +879,26 @@
         self.assertEqual(expected_dirblocks[1:],
             [(dirinfo, [line[0:3] for line in block]) for dirinfo, block in result])
 
+    def test_walkdirs_os_error(self):
+        # <https://bugs.edge.launchpad.net/bzr/+bug/338653>
+        # Pyrex readdir didn't raise useful messages if it had an error
+        # reading the directory
+        if sys.platform == 'win32':
+            raise tests.TestNotApplicable(
+                "readdir IOError not tested on win32")
+        os.mkdir("test-unreadable")
+        os.chmod("test-unreadable", 0000)
+        # must chmod it back so that it can be removed
+        self.addCleanup(lambda: os.chmod("test-unreadable", 0700))
+        # The error is not raised until the generator is actually evaluated.
+        # (It would be ok if it happened earlier but at the moment it
+        # doesn't.)
+        e = self.assertRaises(OSError, list,
+            osutils._walkdirs_utf8("."))
+        self.assertEquals(e.filename, './test-unreadable')
+        self.assertEquals(str(e),
+            "[Errno 13] chdir: Permission denied: './test-unreadable'")
+
     def test__walkdirs_utf8(self):
         tree = [
             '.bzr',

=== modified file 'bzrlib/tests/test_trace.py'
--- a/bzrlib/tests/test_trace.py	2009-01-17 01:30:58 +0000
+++ b/bzrlib/tests/test_trace.py	2009-03-09 12:35:43 +0000
@@ -70,8 +70,17 @@
 
     def test_format_os_error(self):
         try:
+            os.rmdir('nosuchfile22222')
+        except OSError:
+            pass
+        msg = _format_exception()
+        self.assertContainsRe(msg,
+            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile22222')
+
+    def test_format_io_error(self):
+        try:
             file('nosuchfile22222')
-        except (OSError, IOError):
+        except IOError:
             pass
         msg = _format_exception()
         self.assertContainsRe(msg, r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')




More information about the bazaar-commits mailing list