Rev 2923: (John Arbash Meinel, Alexander Belchenko) Fix bug #153493, use O_BINARY when reading files to compute sha1 sum. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Oct 22 18:08:03 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2923
revision-id: pqm at pqm.ubuntu.com-20071022170800-egprunbmf7j0hkvm
parent: pqm at pqm.ubuntu.com-20071022014712-mpln8namgmsywr75
parent: john at arbash-meinel.com-20071022160311-o9ghjovhh6s734n3
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2007-10-22 18:08:00 +0100
message:
  (John Arbash Meinel, Alexander Belchenko) Fix bug #153493, use O_BINARY when reading files to compute sha1 sum.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
    ------------------------------------------------------------
    revno: 2922.1.2
    merged: john at arbash-meinel.com-20071022160311-o9ghjovhh6s734n3
    parent: john at arbash-meinel.com-20071022155447-ev3m0pvsmeel6nge
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: binary_read_153493
    timestamp: Mon 2007-10-22 11:03:11 -0500
    message:
      Add tests for sha_file_by_name.
    ------------------------------------------------------------
    revno: 2922.1.1
    merged: john at arbash-meinel.com-20071022155447-ev3m0pvsmeel6nge
    parent: pqm at pqm.ubuntu.com-20071022014712-mpln8namgmsywr75
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: binary_read_153493
    timestamp: Mon 2007-10-22 10:54:47 -0500
    message:
      Fix bug #153493, use O_BINARY when reading files.
=== modified file 'NEWS'
--- a/NEWS	2007-10-19 18:43:47 +0000
+++ b/NEWS	2007-10-22 15:54:47 +0000
@@ -85,6 +85,9 @@
 
   BUG FIXES:
 
+   * Make sure to use ``O_BINARY`` when opening files to check their
+     sha1sum. (Alexander Belchenko, John Arbash Meinel, #153493)
+
    * Fix a problem with Win32 handling of the executable bit.
      (John Arbash Meinel, #149113)
 

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2007-10-08 05:09:59 +0000
+++ b/bzrlib/osutils.py	2007-10-22 15:54:47 +0000
@@ -593,7 +593,7 @@
 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.O_RDONLY | O_BINARY)
     try:
         while True:
             b = os.read(f, 1<<16)

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2007-09-25 08:14:12 +0000
+++ b/bzrlib/tests/test_osutils.py	2007-10-22 16:03:11 +0000
@@ -277,7 +277,6 @@
         foo_baz_path = osutils.pathjoin(foo_path, 'baz')
         self.assertEqual(baz_path, osutils.dereference_path(foo_baz_path))
 
-
     def test_changing_access(self):
         f = file('file', 'w')
         f.write('monkey')
@@ -299,7 +298,6 @@
             osutils.make_readonly('dangling')
             osutils.make_writable('dangling')
 
-
     def test_kind_marker(self):
         self.assertEqual("", osutils.kind_marker("file"))
         self.assertEqual("/", osutils.kind_marker(osutils._directory_kind))
@@ -1050,3 +1048,17 @@
         self.assertTrue(isinstance(offset, int))
         eighteen_hours = 18 * 3600
         self.assertTrue(-eighteen_hours < offset < eighteen_hours)
+
+
+class TestShaFileByName(TestCaseInTempDir):
+
+    def test_sha_empty(self):
+        self.build_tree_contents([('foo', '')])
+        expected_sha = osutils.sha_string('')
+        self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))
+
+    def test_sha_mixed_endings(self):
+        text = 'test\r\nwith\nall\rpossible line endings\r\n'
+        self.build_tree_contents([('foo', text)])
+        expected_sha = osutils.sha_string(text)
+        self.assertEqual(expected_sha, osutils.sha_file_by_name('foo'))




More information about the bazaar-commits mailing list