Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eeca37e

Browse files
committed
SF bug #453515: filecmp.dircmp case sensitivity bug
1 parent 09c7b60 commit eeca37e

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Lib/filecmp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os
1313
import stat
1414
import warnings
15-
from itertools import ifilter, ifilterfalse
15+
from itertools import ifilter, ifilterfalse, imap, izip
1616

1717
__all__ = ["cmp","dircmp","cmpfiles"]
1818

@@ -135,11 +135,11 @@ def phase0(self): # Compare everything except common subdirectories
135135
self.right_list.sort()
136136

137137
def phase1(self): # Compute common names
138-
b = dict.fromkeys(self.right_list)
139-
common = dict.fromkeys(ifilter(b.has_key, self.left_list))
140-
self.left_only = list(ifilterfalse(common.has_key, self.left_list))
141-
self.right_only = list(ifilterfalse(common.has_key, self.right_list))
142-
self.common = common.keys()
138+
a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list))
139+
b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list))
140+
self.common = map(a.__getitem__, ifilter(b.has_key, a))
141+
self.left_only = map(a.__getitem__, ifilterfalse(b.has_key, a))
142+
self.right_only = map(b.__getitem__, ifilterfalse(a.has_key, b))
143143

144144
def phase2(self): # Distinguish files, directories, funnies
145145
self.common_dirs = []

Lib/test/test_filecmp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ def setUp(self):
4949
data = 'Contents of file go here.\n'
5050
for dir in [self.dir, self.dir_same, self.dir_diff]:
5151
os.mkdir(dir)
52-
output = open(os.path.join(dir, 'file'), 'w')
52+
if dir is self.dir_same:
53+
fn = 'FiLe' # Verify case-insensitive comparison
54+
else:
55+
fn = 'file'
56+
output = open(os.path.join(dir, fn), 'w')
5357
output.write(data)
5458
output.close()
5559

@@ -93,7 +97,7 @@ def test_cmpfiles(self):
9397
def test_dircmp(self):
9498
# Check attributes for comparison of two identical directories
9599
d = filecmp.dircmp(self.dir, self.dir_same)
96-
self.failUnless(d.left_list == d.right_list == ['file'])
100+
self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
97101
self.failUnless(d.common == ['file'])
98102
self.failUnless(d.left_only == d.right_only == [])
99103
self.failUnless(d.same_files == ['file'])

0 commit comments

Comments
 (0)