+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:
+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)
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': by_name( fname):
+ OS_OPEN_FLAGS = os.O_RDONLY | os.O_BINARY
+else:
+ OS_OPEN_FLAGS = os.O_RDONLY
+
def sha_file_
"""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)