Jelmer Vernooij пре 2 месеци
родитељ
комит
266a28c271
2 измењених фајлова са 27 додато и 1 уклоњено
  1. 8 1
      dulwich/midx.py
  2. 19 0
      dulwich/object_store.py

+ 8 - 1
dulwich/midx.py

@@ -410,7 +410,14 @@ class MultiPackIndex:
             yield sha, pack_name, offset
 
     def close(self) -> None:
-        """Close the MIDX file."""
+        """Close the MIDX file and release mmap resources."""
+        # Close mmap'd contents first if it's an mmap object
+        if self._contents is not None and has_mmap:
+            if isinstance(self._contents, mmap.mmap):
+                self._contents.close()
+        self._contents = None
+
+        # Close file handle
         if self._file is not None:
             self._file.close()
             self._file = None

+ 19 - 0
dulwich/object_store.py

@@ -2311,6 +2311,25 @@ class DiskObjectStore(PackBasedObjectStore):
                 if time.time() - mtime > grace_period:
                     os.remove(pack_path)
 
+    def close(self) -> None:
+        """Close the object store and release resources.
+
+        This method closes all cached pack files, MIDX, and frees associated resources.
+        """
+        # Close MIDX if it's loaded
+        if self._midx is not None:
+            self._midx.close()
+            self._midx = None
+
+        # Close alternates
+        if self._alternates is not None:
+            for alt in self._alternates:
+                alt.close()
+            self._alternates = None
+
+        # Call parent class close to handle pack files
+        super().close()
+
 
 class MemoryObjectStore(PackCapableObjectStore):
     """Object store that keeps all objects in memory."""