Merge lp:~jelmer/brz/smart-add-illegal-char into lp:brz

Proposed by Jelmer Vernooij
Status: Needs review
Proposed branch: lp:~jelmer/brz/smart-add-illegal-char
Merge into: lp:brz
Diff against target: 108 lines (+55/-2)
5 files modified
breezy/bzr/inventorytree.py (+9/-0)
breezy/bzr/workingtree.py (+9/-1)
breezy/git/workingtree.py (+7/-1)
breezy/tests/per_workingtree/test_smart_add.py (+25/-0)
doc/en/release-notes/brz-3.0.txt (+5/-0)
To merge this branch: bzr merge lp:~jelmer/brz/smart-add-illegal-char
Reviewer Review Type Date Requested Status
Martin Packman Needs Fixing
Review via email: mp+358608@code.launchpad.net

Description of the change

Raise better exception when encountering filenames that are invalid in the current encoding.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

This should use the osutils.DirReader abstraction that uses different logic for filesystems that are really bytes (*nix) and filesystems that are really unicode (windows).

review: Needs Fixing
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Unmerged revisions

7145. By Jelmer Vernooij

Fix python3 compatibility."

7144. By Jelmer Vernooij

Raise better exception when encountering invalid characters in the current fs encoding.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/bzr/inventorytree.py'
--- breezy/bzr/inventorytree.py 2018-09-14 14:13:30 +0000
+++ breezy/bzr/inventorytree.py 2018-11-13 02:37:00 +0000
@@ -671,7 +671,16 @@
671 if this_ie.kind != 'directory':671 if this_ie.kind != 'directory':
672 this_ie = self._convert_to_directory(this_ie, inv_path)672 this_ie = self._convert_to_directory(this_ie, inv_path)
673673
674 abspath = abspath.encode(osutils._fs_enc)
675
674 for subf in sorted(os.listdir(abspath)):676 for subf in sorted(os.listdir(abspath)):
677 try:
678 subf = subf.decode(osutils._fs_enc)
679 except UnicodeDecodeError:
680 relpath = (directory.encode(osutils._fs_enc) +
681 b'/' + subf)
682 raise errors.BadFilenameEncoding(relpath,
683 osutils._fs_enc)
675 inv_f, _ = osutils.normalized_filename(subf)684 inv_f, _ = osutils.normalized_filename(subf)
676 # here we could use TreeDirectory rather than685 # here we could use TreeDirectory rather than
677 # string concatenation.686 # string concatenation.
678687
=== modified file 'breezy/bzr/workingtree.py'
--- breezy/bzr/workingtree.py 2018-09-22 01:03:30 +0000
+++ breezy/bzr/workingtree.py 2018-11-13 02:37:00 +0000
@@ -1104,7 +1104,15 @@
11041104
1105 # But do this child first if recursing down1105 # But do this child first if recursing down
1106 if recursive:1106 if recursive:
1107 new_children = sorted(os.listdir(fap))1107 new_children = []
1108 for subf in os.listdir(fap.encode(osutils._fs_enc)):
1109 try:
1110 new_children.append(subf.decode(osutils._fs_enc))
1111 except UnicodeDecodeError:
1112 relpath = fp.lstrip('/').encode(osutils._fs_enc) + b'/' + subf
1113 raise errors.BadFilenameEncoding(relpath,
1114 osutils._fs_enc)
1115 new_children.sort()
1108 new_children = collections.deque(new_children)1116 new_children = collections.deque(new_children)
1109 stack.append((f_ie.file_id, fp, fap, new_children))1117 stack.append((f_ie.file_id, fp, fap, new_children))
1110 # Break out of inner loop,1118 # Break out of inner loop,
11111119
=== modified file 'breezy/git/workingtree.py'
--- breezy/git/workingtree.py 2018-09-30 00:33:53 +0000
+++ breezy/git/workingtree.py 2018-11-13 02:37:00 +0000
@@ -482,7 +482,13 @@
482 trace.warning('skipping nested tree %r', abs_user_dir)482 trace.warning('skipping nested tree %r', abs_user_dir)
483 continue483 continue
484484
485 for name in os.listdir(abs_user_dir):485 for name in os.listdir(abs_user_dir.encode(osutils._fs_enc)):
486 try:
487 name = name.decode(osutils._fs_enc)
488 except UnicodeDecodeError:
489 relpath = user_dir.encode(osutils._fs_enc) + b'/' + name
490 raise errors.BadFilenameEncoding(relpath,
491 osutils._fs_enc)
486 subp = os.path.join(user_dir, name)492 subp = os.path.join(user_dir, name)
487 if self.is_control_filename(subp) or self.mapping.is_special_file(subp):493 if self.is_control_filename(subp) or self.mapping.is_special_file(subp):
488 continue494 continue
489495
=== modified file 'breezy/tests/per_workingtree/test_smart_add.py'
--- breezy/tests/per_workingtree/test_smart_add.py 2018-07-23 22:49:40 +0000
+++ breezy/tests/per_workingtree/test_smart_add.py 2018-11-13 02:37:00 +0000
@@ -377,3 +377,28 @@
377 # just ignore files that don't fit the normalization377 # just ignore files that don't fit the normalization
378 # rules, rather than exploding378 # rules, rather than exploding
379 self.assertRaises(errors.InvalidNormalization, self.wt.smart_add, [])379 self.assertRaises(errors.InvalidNormalization, self.wt.smart_add, [])
380
381
382class TestIllegalPaths(per_workingtree.TestCaseWithWorkingTree):
383
384 def test_bad_fs_path(self):
385 if osutils.normalizes_filenames():
386 # You *can't* create an illegal filename on OSX.
387 raise tests.TestNotApplicable('OSX normalizes filenames')
388 self.requireFeature(features.UTF8Filesystem)
389 # We require a UTF8 filesystem, because otherwise we would need to get
390 # tricky to figure out how to create an illegal filename.
391 # \xb5 is an illegal path because it should be \xc2\xb5 for UTF-8
392 tree = self.make_branch_and_tree('tree')
393 self.build_tree(['tree/subdir/', 'tree/subdir/somefile'])
394 tree.add(['subdir', 'subdir/somefile'])
395
396 with open(b'tree/subdir/m\xb5', 'wb') as f:
397 f.write(b'trivial\n')
398
399 with tree.lock_tree_write():
400 e = self.assertListRaises(errors.BadFilenameEncoding,
401 tree.smart_add, ['tree'])
402 # We should display the relative path
403 self.assertEqual(b'subdir/m\xb5', e.filename)
404 self.assertEqual(osutils._fs_enc, e.fs_encoding)
380405
=== modified file 'doc/en/release-notes/brz-3.0.txt'
--- doc/en/release-notes/brz-3.0.txt 2018-09-18 02:08:46 +0000
+++ doc/en/release-notes/brz-3.0.txt 2018-11-13 02:37:00 +0000
@@ -171,6 +171,11 @@
171171
172* Support '0' markers in fastimport plugin. (Jelmer Vernooij, #1744615)172* Support '0' markers in fastimport plugin. (Jelmer Vernooij, #1744615)
173173
174* Raise a clearer exception when encountering filenames not in
175 the current encoding when running 'brz add'.
176 (Jelmer Vernooij, #715547)
177
178
174Documentation179Documentation
175*************180*************
176181

Subscribers

People subscribed via source and target branches