Merge pull request #178 from danw/microfactory_locking
Add file locking to microfactory
This commit is contained in:
commit
2f769ef470
1 changed files with 12 additions and 0 deletions
|
@ -485,6 +485,18 @@ func Build(config *Config, out, pkg string) (*GoPackage, error) {
|
|||
Name: "main",
|
||||
}
|
||||
|
||||
lockFileName := filepath.Join(filepath.Dir(out), "."+filepath.Base(out)+".lock")
|
||||
lockFile, err := os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error creating lock file (%q): %v", lockFileName, err)
|
||||
}
|
||||
defer lockFile.Close()
|
||||
|
||||
err = syscall.Flock(int(lockFile.Fd()), syscall.LOCK_EX)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error locking file (%q): %v", lockFileName, err)
|
||||
}
|
||||
|
||||
path, ok, err := config.Path(pkg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error finding package %q for main: %v", pkg, err)
|
||||
|
|
Loading…
Reference in a new issue