Skip to content

Commit d6c097e

Browse files
committed
close smmap handles, to be able to delete files / trees in process (req. for windows)
1 parent 060e5ea commit d6c097e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: gitdb/pack.py

+12
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ def __init__(self, indexpath):
266266
super(PackIndexFile, self).__init__()
267267
self._indexpath = indexpath
268268

269+
def close(self):
270+
mman.force_map_handle_removal_win(self._indexpath)
271+
self._cursor = None
272+
269273
def _set_cache_(self, attr):
270274
if attr == "_packfile_checksum":
271275
self._packfile_checksum = self._cursor.map()[-40:-20]
@@ -527,6 +531,10 @@ class PackFile(LazyMixin):
527531
def __init__(self, packpath):
528532
self._packpath = packpath
529533

534+
def close(self):
535+
mman.force_map_handle_removal_win(self._packpath)
536+
self._cursor = None
537+
530538
def _set_cache_(self, attr):
531539
# we fill the whole cache, whichever attribute gets queried first
532540
self._cursor = mman.make_cursor(self._packpath).use_region()
@@ -668,6 +676,10 @@ def __init__(self, pack_or_index_path):
668676
self._index = self.IndexFileCls("%s.idx" % basename) # PackIndexFile instance
669677
self._pack = self.PackFileCls("%s.pack" % basename) # corresponding PackFile instance
670678

679+
def close(self):
680+
self._index.close()
681+
self._pack.close()
682+
671683
def _set_cache_(self, attr):
672684
# currently this can only be _offset_map
673685
# TODO: make this a simple sorted offset array which can be bisected

Diff for: gitdb/test/test_pack.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,11 @@ def rewind_streams():
217217
assert os.path.getsize(ppath) > 100
218218

219219
# verify pack
220-
pf = PackFile(ppath) # FIXME: Leaks file-pointer(s)!
220+
pf = PackFile(ppath)
221221
assert pf.size() == len(pack_objs)
222222
assert pf.version() == PackFile.pack_version_default
223223
assert pf.checksum() == pack_sha
224+
pf.close()
224225

225226
# verify index
226227
if ipath is not None:
@@ -231,6 +232,7 @@ def rewind_streams():
231232
assert idx.packfile_checksum() == pack_sha
232233
assert idx.indexfile_checksum() == index_sha
233234
assert idx.size() == len(pack_objs)
235+
idx.close()
234236
# END verify files exist
235237
# END for each packpath, indexpath pair
236238

@@ -245,7 +247,8 @@ def rewind_streams():
245247
# END for each crc mode
246248
# END for each info
247249
assert count == len(pack_objs)
248-
250+
entity.close()
251+
249252
def test_pack_64(self):
250253
# TODO: hex-edit a pack helping us to verify that we can handle 64 byte offsets
251254
# of course without really needing such a huge pack

0 commit comments

Comments
 (0)