Merge pull request #178 from danw/microfactory_locking

Add file locking to microfactory
This commit is contained in:
Dan Willemsen 2017-10-18 16:37:39 -07:00 committed by GitHub
commit 2f769ef470

View file

@ -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)