Rev 4790: os.lstat() != os.fstat() for the st_ino field on windows in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-win32-get-file-with-stat
John Arbash Meinel
john at arbash-meinel.com
Sun Nov 8 03:49:49 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-win32-get-file-with-stat
------------------------------------------------------------
revno: 4790
revision-id: john at arbash-meinel.com-20091108034939-hrsv3aw6vlcxz0bu
parent: pqm at pqm.ubuntu.com-20091106084512-t5ll6xywcd1bycfe
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-win32-get-file-with-stat
timestamp: Sat 2009-11-07 21:49:39 -0600
message:
os.lstat() != os.fstat() for the st_ino field on windows
test_get_file_with_stat was failing because of this fact.
Also, the tests were failing because we didn't close the file_obj directly
and tt.finalize() couldn't delete it. (I presume this was a PreviewTree permutation
that was failing.)
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-11-01 05:52:16 +0000
+++ b/bzrlib/tests/__init__.py 2009-11-08 03:49:39 +0000
@@ -1107,20 +1107,30 @@
self.assertEqual(mode, mode_test,
'mode mismatch %o != %o' % (mode, mode_test))
- def assertEqualStat(self, expected, actual):
+ def assertEqualStat(self, expected, actual, ignore_ino=False):
"""assert that expected and actual are the same stat result.
:param expected: A stat result.
:param actual: A stat result.
+ :param ignore_ino: On Windows os.fstat() returns a value for st_ino,
+ but os.lstat() returns 0 for st_ino. As such, we can't trust the
+ value.
:raises AssertionError: If the expected and actual stat values differ
other than by atime.
"""
- self.assertEqual(expected.st_size, actual.st_size)
- self.assertEqual(expected.st_mtime, actual.st_mtime)
- self.assertEqual(expected.st_ctime, actual.st_ctime)
- self.assertEqual(expected.st_dev, actual.st_dev)
- self.assertEqual(expected.st_ino, actual.st_ino)
- self.assertEqual(expected.st_mode, actual.st_mode)
+ self.assertEqual(expected.st_size, actual.st_size,
+ 'st_size did not match')
+ self.assertEqual(expected.st_mtime, actual.st_mtime,
+ 'st_mtime did not match')
+ self.assertEqual(expected.st_ctime, actual.st_ctime,
+ 'st_ctime did not match')
+ self.assertEqual(expected.st_dev, actual.st_dev,
+ 'st_dev did not match')
+ if not ignore_ino:
+ self.assertEqual(expected.st_ino, actual.st_ino,
+ 'st_ino did not match')
+ self.assertEqual(expected.st_mode, actual.st_mode,
+ 'st_mode did not match')
def assertLength(self, length, obj_with_len):
"""Assert that obj_with_len is of length length."""
=== modified file 'bzrlib/tests/per_tree/test_get_file_with_stat.py'
--- a/bzrlib/tests/per_tree/test_get_file_with_stat.py 2009-07-10 07:14:02 +0000
+++ b/bzrlib/tests/per_tree/test_get_file_with_stat.py 2009-11-08 03:49:39 +0000
@@ -17,12 +17,21 @@
"""Test that all WorkingTree's implement get_file_with_stat."""
import os
+import sys
from bzrlib.tests.per_tree import TestCaseWithTree
+
class TestGetFileWithStat(TestCaseWithTree):
+ # On Windows, 'os.fstat(f.fileno())' will return a value for 'st_ino' but
+ # 'os.lstat(filename)' does *not* return a value. As such, we can't just
+ # compare all attributes of the stat object to assert that fstat returns
+ # identical content to lstat...
+ # However, see also bug #478023
+ ignore_ino = (sys.platform == 'win32')
+
def test_get_file_with_stat_id_only(self):
work_tree = self.make_branch_and_tree('.')
self.build_tree(['foo'])
@@ -31,10 +40,14 @@
tree.lock_read()
self.addCleanup(tree.unlock)
file_obj, statvalue = tree.get_file_with_stat('foo-id')
- if statvalue is not None:
- expected = os.lstat('foo')
- self.assertEqualStat(expected, statvalue)
- self.assertEqual(["contents of foo\n"], file_obj.readlines())
+ try:
+ if statvalue is not None:
+ expected = os.lstat('foo')
+ self.assertEqualStat(expected, statvalue,
+ ignore_ino=self.ignore_ino)
+ self.assertEqual(["contents of foo\n"], file_obj.readlines())
+ finally:
+ file_obj.close()
def test_get_file_with_stat_id_and_path(self):
work_tree = self.make_branch_and_tree('.')
@@ -44,8 +57,11 @@
tree.lock_read()
self.addCleanup(tree.unlock)
file_obj, statvalue = tree.get_file_with_stat('foo-id', 'foo')
- expected = os.lstat('foo')
- if statvalue is not None:
- expected = os.lstat('foo')
- self.assertEqualStat(expected, statvalue)
- self.assertEqual(["contents of foo\n"], file_obj.readlines())
+ try:
+ if statvalue is not None:
+ expected = os.lstat('foo')
+ self.assertEqualStat(expected, statvalue,
+ ignore_ino=self.ignore_ino)
+ self.assertEqual(["contents of foo\n"], file_obj.readlines())
+ finally:
+ file_obj.close()
More information about the bazaar-commits
mailing list