diff options
author | stuertz <js@contact.de> | 2017-03-27 11:20:48 +0200 |
---|---|---|
committer | stuertz <js@contact.de> | 2017-03-27 11:20:48 +0200 |
commit | d6c097eaf759dabfd3c42b55958962b6e9a05063 (patch) | |
tree | 114bc165a72cbba63d87b5a5c082656945a77800 | |
parent | 060e5ea18b010e4d8441a5cfad699aba69593c72 (diff) | |
download | gitdb-d6c097eaf759dabfd3c42b55958962b6e9a05063.tar.gz |
close smmap handles, to be able to delete files / trees in process (req. for windows)
-rw-r--r-- | gitdb/pack.py | 12 | ||||
-rw-r--r-- | gitdb/test/test_pack.py | 7 |
2 files changed, 17 insertions, 2 deletions
diff --git a/gitdb/pack.py b/gitdb/pack.py index 20a4515..115d943 100644 --- a/gitdb/pack.py +++ b/gitdb/pack.py @@ -266,6 +266,10 @@ class PackIndexFile(LazyMixin): super(PackIndexFile, self).__init__() self._indexpath = indexpath + def close(self): + mman.force_map_handle_removal_win(self._indexpath) + self._cursor = None + def _set_cache_(self, attr): if attr == "_packfile_checksum": self._packfile_checksum = self._cursor.map()[-40:-20] @@ -527,6 +531,10 @@ class PackFile(LazyMixin): def __init__(self, packpath): self._packpath = packpath + def close(self): + mman.force_map_handle_removal_win(self._packpath) + self._cursor = None + def _set_cache_(self, attr): # we fill the whole cache, whichever attribute gets queried first self._cursor = mman.make_cursor(self._packpath).use_region() @@ -668,6 +676,10 @@ class PackEntity(LazyMixin): self._index = self.IndexFileCls("%s.idx" % basename) # PackIndexFile instance self._pack = self.PackFileCls("%s.pack" % basename) # corresponding PackFile instance + def close(self): + self._index.close() + self._pack.close() + def _set_cache_(self, attr): # currently this can only be _offset_map # TODO: make this a simple sorted offset array which can be bisected diff --git a/gitdb/test/test_pack.py b/gitdb/test/test_pack.py index 6e31363..24e2a31 100644 --- a/gitdb/test/test_pack.py +++ b/gitdb/test/test_pack.py @@ -217,10 +217,11 @@ class TestPack(TestBase): assert os.path.getsize(ppath) > 100 # verify pack - pf = PackFile(ppath) # FIXME: Leaks file-pointer(s)! + pf = PackFile(ppath) assert pf.size() == len(pack_objs) assert pf.version() == PackFile.pack_version_default assert pf.checksum() == pack_sha + pf.close() # verify index if ipath is not None: @@ -231,6 +232,7 @@ class TestPack(TestBase): assert idx.packfile_checksum() == pack_sha assert idx.indexfile_checksum() == index_sha assert idx.size() == len(pack_objs) + idx.close() # END verify files exist # END for each packpath, indexpath pair @@ -245,7 +247,8 @@ class TestPack(TestBase): # END for each crc mode # END for each info assert count == len(pack_objs) - + entity.close() + def test_pack_64(self): # TODO: hex-edit a pack helping us to verify that we can handle 64 byte offsets # of course without really needing such a huge pack |