Rev 2364: Catch Windows ERROR_DIRECTORY when doing os.listdir('file') in http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/win32_notdir
John Arbash Meinel
john at arbash-meinel.com
Mon Mar 19 23:10:44 GMT 2007
At http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/win32_notdir
------------------------------------------------------------
revno: 2364
revision-id: john at arbash-meinel.com-20070319231030-blqw1ylij3g290gg
parent: pqm at pqm.ubuntu.com-20070317015305-7b7562331da9f786
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: win32_notdir
timestamp: Mon 2007-03-19 18:10:30 -0500
message:
Catch Windows ERROR_DIRECTORY when doing os.listdir('file')
modified:
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
-------------- next part --------------
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-03-16 19:13:40 +0000
+++ b/bzrlib/workingtree_4.py 2007-03-19 23:10:30 +0000
@@ -96,6 +96,12 @@
from bzrlib.workingtree import WorkingTree, WorkingTree3, WorkingTreeFormat3
+# This is the Windows equivalent of ENOTDIR
+# It is defined in pywin32.winerror, but we don't want a strong dependency for
+# just an error code.
+ERROR_DIRECTORY = 267
+
+
class WorkingTree4(WorkingTree3):
"""This is the Format 4 working tree.
@@ -1979,6 +1985,12 @@
## import pdb;pdb.set_trace()
return ()
+ not_dir_exceptions = (OSError,)
+ if sys.platform == 'win32':
+ # os.listdir('file') raises WindowsError on win32, rather than
+ # raising an OSError
+ not_dir_exceptions = (OSError, WindowsError)
+
while search_specific_files:
# TODO: the pending list should be lexically sorted? the
# interface doesn't require it.
@@ -2062,8 +2074,11 @@
dir_iterator = osutils._walkdirs_utf8(root_abspath, prefix=current_root)
try:
current_dir_info = dir_iterator.next()
- except OSError, e:
- if e.errno in (errno.ENOENT, errno.ENOTDIR):
+ except not_dir_exceptions, e:
+ errno = getattr(e, 'errno', None)
+ winerrno = getattr(e, 'winerror', None)
+ if (errno in (errno.ENOENT, errno.ENOTDIR)
+ or winerrno in (ERROR_DIRECTORY,)):
# there may be directories in the inventory even though
# this path is not a file on disk: so mark it as end of
# iterator
More information about the bazaar-commits
mailing list