Skip to content

Commit

Permalink
Fix Windows not being able to delete temporary files #13
Browse files Browse the repository at this point in the history
  • Loading branch information
makuto authored and junkblocker committed Jun 2, 2022
1 parent 351619a commit ee8bdba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ func Merge(dst, src1, src2 string) {
ix3.flush()
ix3.finish().Close()

nameIndexFile.file.Close()
os.Remove(nameIndexFile.name)
w.postIndexFile.file.Close()
os.Remove(w.postIndexFile.name)
}

Expand Down
15 changes: 13 additions & 2 deletions index/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,15 @@ func (ix *IndexWriter) Flush() {
}
ix.main.writeString(trailerMagic)

ix.nameData.file.Close()
os.Remove(ix.nameData.name)
for _, f := range ix.postFile {
f.Close()
os.Remove(f.Name())
}
ix.nameIndex.file.Close()
os.Remove(ix.nameIndex.name)
ix.postIndex.file.Close()
os.Remove(ix.postIndex.name)

log.Printf("%d data bytes, %d index bytes", ix.totalBytes, ix.main.offset())
Expand Down Expand Up @@ -355,6 +359,9 @@ func (ix *IndexWriter) mergePost(out *bufWriter) {
break
}
}
for _, mappedData := range h.mappedData {
unmmapFile(mappedData)
}
}

// A postChunk represents a chunk of post entries flushed to disk or
Expand All @@ -368,13 +375,17 @@ const postBuf = 4096

// A postHeap is a heap (priority queue) of postChunks.
type postHeap struct {
ch []*postChunk
ch []*postChunk
mappedData []*mmapData
}

func (h *postHeap) addFile(f *os.File) {
data := mmapFile(f).d
mappedData := mmapFile(f)
data := mappedData.d
m := (*[npost]postEntry)(unsafe.Pointer(&data[0]))[:len(data)/8]
h.addMem(m)
// Make sure we close the mmap memory once we're done with it
h.mappedData = append(h.mappedData, (&mappedData))
}

func (h *postHeap) addMem(x []postEntry) {
Expand Down

0 comments on commit ee8bdba

Please sign in to comment.