Add a filelock for in-place case

Multiple bpmodify process on the same Android.bp can run in parallel in
the case of aidl-freeze-api.

So, add a file lock for in-place editing case(-w)

Bug: 229413853
Test: run bpmodify in parallel and check result
Change-Id: I5368b0304b59f34fff60025120b38cc5f615ac40
This commit is contained in:
Jeongik Cha 2022-05-09 09:16:29 +00:00
parent 5208ee885c
commit 28c7996f2c

View file

@ -15,6 +15,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"syscall"
"unicode"
"github.com/google/blueprint/parser"
@ -68,6 +69,11 @@ func processFile(filename string, in io.Reader, out io.Writer) error {
return err
}
defer f.Close()
if *write {
syscall.Flock(int(f.Fd()), syscall.LOCK_EX)
}
in = f
}