Close zstd encoder before reading file info, to ensure accurate file size reporting for index file

This commit is contained in:
Seednode 2024-01-04 12:43:26 -06:00
parent b90f6cfc64
commit 89637c12b2
2 changed files with 9 additions and 1 deletions

View File

@ -106,11 +106,17 @@ func (index *fileIndex) Export(path string) error {
index.mutex.RLock() index.mutex.RLock()
err = enc.Encode(&index.list) err = enc.Encode(&index.list)
if err != nil { if err != nil {
index.mutex.RUnlock()
return err return err
} }
length := len(index.list) length := len(index.list)
index.mutex.RUnlock() index.mutex.RUnlock()
// Close encoder prior to checking file size,
// to ensure the correct value is returned.
z.Close()
stats, err := file.Stat() stats, err := file.Stat()
if err != nil { if err != nil {
return err return err
@ -154,6 +160,8 @@ func (index *fileIndex) Import(path string) error {
index.mutex.Lock() index.mutex.Lock()
err = dec.Decode(&index.list) err = dec.Decode(&index.list)
if err != nil { if err != nil {
index.mutex.Unlock()
return err return err
} }
length := len(index.list) length := len(index.list)

View File

@ -14,7 +14,7 @@ import (
const ( const (
AllowedCharacters string = `^[A-z0-9.\-_]+$` AllowedCharacters string = `^[A-z0-9.\-_]+$`
ReleaseVersion string = "3.7.0" ReleaseVersion string = "3.7.1"
) )
var ( var (