Quellcode durchsuchen

Avoid use of 'with' in dulwich.index, fixes compatibility with python < 2.5.

Jelmer Vernooij vor 13 Jahren
Ursprung
Commit
9b19538f90
2 geänderte Dateien mit 10 neuen und 2 gelöschten Zeilen
  1. 4 0
      NEWS
  2. 6 2
      dulwich/index.py

+ 4 - 0
NEWS

@@ -1,5 +1,9 @@
 0.8.5	UNRELEASED
 0.8.5	UNRELEASED
 
 
+ BUG FIXES
+
+  * Avoid use of 'with' in dulwich.index. (Jelmer Vernooij)
+
 0.8.4	2012-03-28
 0.8.4	2012-03-28
 
 
  BUG FIXES
  BUG FIXES

+ 6 - 2
dulwich/index.py

@@ -413,11 +413,15 @@ def build_index_from_tree(prefix, index_path, object_store, tree_id):
 
 
         # FIXME: Merge new index into working tree
         # FIXME: Merge new index into working tree
         if stat.S_ISLNK(entry.mode):
         if stat.S_ISLNK(entry.mode):
+            # FIXME: This will fail on Windows. What should we do instead?
             os.symlink(object_store[entry.sha].as_raw_string(), full_path)
             os.symlink(object_store[entry.sha].as_raw_string(), full_path)
         else:
         else:
-            with open(full_path, 'wb') as file:
+            f = open(full_path, 'wb')
+            try:
                 # Write out file
                 # Write out file
-                file.write(object_store[entry.sha].as_raw_string())
+                f.write(object_store[entry.sha].as_raw_string())
+            finally:
+                f.close()
 
 
             os.chmod(full_path, entry.mode)
             os.chmod(full_path, entry.mode)