1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Create lockfile directory if it doesn't exist yet

This commit is contained in:
JanHoefelmeyer 2023-03-27 11:51:15 +02:00
parent b0d7df69b8
commit c59a8f07a3

View file

@ -13,6 +13,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/csaf-poc/csaf_distribution/util"
"github.com/gofrs/flock"
@ -39,6 +40,12 @@ func lock(lockFile *string, fn func() error) error {
// No locking configured.
return fn()
}
err := os.MkdirAll(filepath.Dir(*lockFile), 0700)
if err != nil {
return fmt.Errorf("file locking failed: %v", err)
}
fl := flock.New(*lockFile)
locked, err := fl.TryLock()
if err != nil {