Skip to content

Commit

Permalink
lock updateFile (fix #36)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreisinger committed Oct 11, 2022
1 parent aa5684d commit 6e79f2e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions check/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/user"
"path/filepath"
"sync"
"time"
)

Expand All @@ -34,10 +35,16 @@ func getDbFilesPath(filename string) (string, error) {
return filepath.Join(dir, filename), nil
}

var mu sync.Mutex

// updateFile updates file from url if the file is older than a week. If file
// does not exist it downloads and creates it. compressFmt is the compression
// format of the file to download; gz or tgz. Empty string means no compression.
// Only one instance on updateFile can run at any given time.
func updateFile(file, url string, compressFmt string) error {
mu.Lock()
defer mu.Unlock()

f, err := os.Stat(file)

if os.IsNotExist(err) {
Expand Down

0 comments on commit 6e79f2e

Please sign in to comment.