[Bug 153493] Re: status gives false positives for text files with CRLF (@win32)

Alexander Belchenko bialix at ukr.net
Mon Oct 22 12:02:19 BST 2007


This regression was introduced by revno.2894 (Martin Pool) with log 
message:

add -Dhashcache, sha_file_by_name using raw os files rather than file 
objects (mbp)


I think bug actually in following line:

=== modified file 'bzrlib/osutils.py'
--- bzrlib/osutils.py 04.10.2007 8:09:58
+++ bzrlib/osutils.py 08.10.2007 8:09:59
@@ -590,6 +590,20 @@
      return s.hexdigest()


+def sha_file_by_name(fname):
+    """Calculate the SHA1 of a file by reading the full text"""
+    s = sha.new()
+    f = os.open(fname, os.O_RDONLY)

^-- I believe on Windows it should be:

+    f = os.open(fname, os.O_RDONLY|os.O_BINARY)

And this change indeed fixes regression.
The problem here is O_BINARY flag itself. According to Python 
documentation this flag exists only on Windows.
So probably fix should be something like this:

=== modified file 'bzrlib/osutils.py'
--- bzrlib/osutils.py   2007-10-08 05:09:59 +0000
+++ bzrlib/osutils.py   2007-10-22 10:57:42 +0000
@@ -590,10 +590,15 @@
      return s.hexdigest()


+if sys.platform == 'win32':
+    OS_OPEN_FLAGS = os.O_RDONLY | os.O_BINARY
+else:
+    OS_OPEN_FLAGS = os.O_RDONLY
+
  def sha_file_by_name(fname):
      """Calculate the SHA1 of a file by reading the full text"""
      s = sha.new()
-    f = os.open(fname, os.O_RDONLY)
+    f = os.open(fname, OS_OPEN_FLAGS)
      try:
          while True:
              b = os.read(f, 1<<16)





More information about the bazaar mailing list