Skip to content

Commit

Permalink
fix: fix diskcache empty pos
Browse files Browse the repository at this point in the history
  • Loading branch information
coanor committed Nov 17, 2023
1 parent 2309188 commit f890423
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions diskcache/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func posFromFile(fname string) (*pos, error) {
return nil, err
}

if len(bin) <= 8 {
return nil, nil
}

var p pos
if err := p.UnmarshalBinary(bin); err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions diskcache/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func (c *DiskCache) loadUnfinishedFile() error {
return fmt.Errorf("posFromFile: %w", err)
}

if pos == nil {
return nil
}

// check file's healty
if _, err := os.Stat(string(pos.Name)); err != nil { // not exist
if err := c.pos.reset(); err != nil {
Expand Down

0 comments on commit f890423

Please sign in to comment.