Browse Source

Added Pack.keep() method.

A method to add a .keep file to a Pack object. These files are required
in some circumstances, such as when being called by git and performing a
fetch - without these, race conditions can occur that clean up a pack
before references to it can be updated.
Marc Brinkmann 14 years ago
parent
commit
38b3f49613
1 changed files with 13 additions and 0 deletions
  1. 13 0
      dulwich/pack.py

+ 13 - 0
dulwich/pack.py

@@ -1498,6 +1498,19 @@ class Pack(object):
             yield ShaFile.from_raw_chunks(
               *self.data.resolve_object(offset, type, obj))
 
+    def keep(self, msg=None):
+        """Add a .keep file for the pack, preventing git from garbage collecting it.
+           :param msg: A message written inside the .keep file; can be used later to
+                       determine whether or not a .keep file is obsolete.
+           :return: The path of the .keep file, as a string."""
+        keepfile_name = '%s.keep' % self._basename
+        keepfile = file(keepfile_name, 'wb')
+        if msg:
+            keepfile.write(msg)
+            keepfile.write('\n')
+        keepfile.close()
+        return keepfile_name
+
 
 try:
     from dulwich._pack import apply_delta, bisect_find_sha