Rev 5302: (vila) Fix typo in treebuilder docstring in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Jun 17 11:33:49 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5302 [merge]
revision-id: pqm at pqm.ubuntu.com-20100617103338-k4kkjx9fkt5qv33e
parent: pqm at pqm.ubuntu.com-20100617091103-254bm3h1n8kpm4wq
parent: v.ladeuil+lp at free.fr-20100617073732-2a75e12mk987rmbj
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-06-17 11:33:38 +0100
message:
(vila) Fix typo in treebuilder docstring
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
bzrlib/treebuilder.py treebuilder.py-20060907214856-4omn6hf1u7fvrart-1
=== modified file 'NEWS'
--- a/NEWS 2010-06-17 09:11:03 +0000
+++ b/NEWS 2010-06-17 10:33:38 +0000
@@ -66,6 +66,9 @@
which previously caused "SyntaxError: No command for line".
(Martin Pool)
+* ``walkdirs`` now raises a useful message when the filenames are not using
+ the filesystem encoding. (Eric Moritz, #488519)
+
Improvements
************
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2010-05-28 06:04:57 +0000
+++ b/bzrlib/errors.py 2010-06-11 01:43:18 +0000
@@ -1923,12 +1923,12 @@
class CantMoveRoot(BzrError):
_fmt = "Moving the root directory is not supported at this time"
-
-
+
+
class TransformRenameFailed(BzrError):
_fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
-
+
def __init__(self, from_path, to_path, why, errno):
self.from_path = from_path
self.to_path = to_path
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2010-06-07 01:13:05 +0000
+++ b/bzrlib/osutils.py 2010-06-17 07:37:32 +0000
@@ -931,7 +931,7 @@
def parent_directories(filename):
"""Return the list of parent directories, deepest first.
-
+
For example, parent_directories("a/b/c") -> ["a/b", "a"].
"""
parents = []
@@ -961,7 +961,7 @@
# NB: This docstring is just an example, not a doctest, because doctest
# currently can't cope with the use of lazy imports in this namespace --
# mbp 20090729
-
+
# This currently doesn't report the failure at the time it occurs, because
# they tend to happen very early in startup when we can't check config
# files etc, and also we want to report all failures but not spam the user
@@ -1037,8 +1037,8 @@
def delete_any(path):
- """Delete a file, symlink or directory.
-
+ """Delete a file, symlink or directory.
+
Will delete even if readonly.
"""
try:
@@ -1233,6 +1233,22 @@
# but for now, we haven't optimized...
return [canonical_relpath(base, p) for p in paths]
+
+def decode_filename(filename):
+ """Decode the filename using the filesystem encoding
+
+ If it is unicode, it is returned.
+ Otherwise it is decoded from the the filesystem's encoding. If decoding
+ fails, a errors.BadFilenameEncoding exception is raised.
+ """
+ if type(filename) is unicode:
+ return filename
+ try:
+ return filename.decode(_fs_enc)
+ except UnicodeDecodeError:
+ raise errors.BadFilenameEncoding(filename, _fs_enc)
+
+
def safe_unicode(unicode_or_utf8_string):
"""Coerce unicode_or_utf8_string into unicode.
@@ -1644,7 +1660,7 @@
dirblock = []
append = dirblock.append
try:
- names = sorted(_listdir(top))
+ names = sorted(map(decode_filename, _listdir(top)))
except OSError, e:
if not _is_error_enotdir(e):
raise
@@ -2020,14 +2036,14 @@
def send_all(sock, bytes, report_activity=None):
"""Send all bytes on a socket.
-
+
Breaks large blocks in smaller chunks to avoid buffering limitations on
some platforms, and catches EINTR which may be thrown if the send is
interrupted by a signal.
This is preferred to socket.sendall(), because it avoids portability bugs
and provides activity reporting.
-
+
:param report_activity: Call this as bytes are read, see
Transport._report_activity
"""
@@ -2121,7 +2137,7 @@
def until_no_eintr(f, *a, **kw):
"""Run f(*a, **kw), retrying if an EINTR error occurs.
-
+
WARNING: you must be certain that it is safe to retry the call repeatedly
if EINTR does occur. This is typically only true for low-level operations
like os.read. If in any doubt, don't use this.
@@ -2258,7 +2274,7 @@
if sys.platform == 'win32':
def open_file(filename, mode='r', bufsize=-1):
"""This function is used to override the ``open`` builtin.
-
+
But it uses O_NOINHERIT flag so the file handle is not inherited by
child processes. Deleting or renaming a closed file opened with this
function is not blocking child processes.
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2010-05-25 17:27:52 +0000
+++ b/bzrlib/tests/__init__.py 2010-06-08 01:42:50 +0000
@@ -4345,6 +4345,17 @@
UnicodeFilename = _UnicodeFilename()
+class _ByteStringNamedFilesystem(Feature):
+ """Is the filesystem based on bytes?"""
+
+ def _probe(self):
+ if os.name == "posix":
+ return True
+ return False
+
+ByteStringNamedFilesystem = _ByteStringNamedFilesystem()
+
+
class _UTF8Filesystem(Feature):
"""Is the filesystem UTF-8?"""
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2010-05-27 17:59:18 +0000
+++ b/bzrlib/tests/test_osutils.py 2010-06-08 01:45:09 +0000
@@ -1083,6 +1083,40 @@
# Ensure the message contains the file name
self.assertContainsRe(str(e), "\./test-unreadable")
+
+ def test_walkdirs_encoding_error(self):
+ # <https://bugs.launchpad.net/bzr/+bug/488519>
+ # walkdirs didn't raise a useful message when the filenames
+ # are not using the filesystem's encoding
+
+ # require a bytestring based filesystem
+ self.requireFeature(tests.ByteStringNamedFilesystem)
+
+ tree = [
+ '.bzr',
+ '0file',
+ '1dir/',
+ '1dir/0file',
+ '1dir/1dir/',
+ '1file'
+ ]
+
+ self.build_tree(tree)
+
+ # rename the 1file to a latin-1 filename
+ os.rename("./1file", "\xe8file")
+
+ self._save_platform_info()
+ win32utils.winver = None # Avoid the win32 detection code
+ osutils._fs_enc = 'UTF-8'
+
+ # this should raise on error
+ def attempt():
+ for dirdetail, dirblock in osutils.walkdirs('.'):
+ pass
+
+ self.assertRaises(errors.BadFilenameEncoding, attempt)
+
def test__walkdirs_utf8(self):
tree = [
'.bzr',
@@ -1921,7 +1955,7 @@
def restore_osutils_globals(self):
osutils._terminal_size_state = self._orig_terminal_size_state
osutils._first_terminal_size = self._orig_first_terminal_size
-
+
def replace_stdout(self, new):
self.overrideAttr(sys, 'stdout', new)
=== modified file 'bzrlib/treebuilder.py'
--- a/bzrlib/treebuilder.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/treebuilder.py 2010-06-17 07:11:55 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006 Canonical Ltd
+# Copyright (C) 2006, 2008, 2009, 2010 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
@@ -16,7 +16,7 @@
"""TreeBuilder helper class.
-TreeBuilders are used to build trees of various shapres or properties. This
+TreeBuilders are used to build trees of various shapes or properties. This
can be extremely useful in testing for instance.
"""
More information about the bazaar-commits
mailing list