Skip to content

Commit 93d3011

Browse files
committed
pack/set.go: close potentially-opened index files
In [1], we matched upstream Git's behavior more closely by (1) first opening the corresponding *.idx, and _then_ opening the associated *.pack, skipping over any pairs which had missing/corrupt index files. In this commit, augment that behavior by closing a file descriptor we may have opened, but is otherwise deemed by os.Open to be unusable for one reason or another. This path is unlikely in practice, but is a safe change nonetheless. [1]: 561ed22 (pack/set: ignore packs without indices, 2018-11-29)
1 parent f0db732 commit 93d3011

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pack/set.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ func NewSet(db string) (*Set, error) {
6060
// We have a pack (since it matched the regex), but the
6161
// index is missing or unusable. Skip this pack and
6262
// continue on with the next one, as Git does.
63+
if idxf != nil {
64+
// In the unlikely event that we did open a
65+
// file, close it, but discard any error in
66+
// doing so.
67+
idxf.Close()
68+
}
6369
continue
6470
}
6571

0 commit comments

Comments
 (0)