pkg/lockfile: fix openLock file permissions

Since commit 162a0bf730, openLock creates a file in case ro
argument is set, but the file is created with 0 permission bits.

Fix this, and unify the file creation logic while at it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2022-09-08 15:20:27 -07:00
parent 2076605830
commit 463d50fabc
1 changed files with 4 additions and 8 deletions

View File

@ -71,15 +71,11 @@ func newLastWriterID() []byte {
// openLock will create the file and its parent directories,
// if necessary.
func openLock(path string, ro bool) (fd int, err error) {
if ro {
fd, err = unix.Open(path, os.O_RDONLY|unix.O_CLOEXEC|os.O_CREATE, 0)
} else {
fd, err = unix.Open(path,
os.O_RDWR|unix.O_CLOEXEC|os.O_CREATE,
unix.S_IRUSR|unix.S_IWUSR|unix.S_IRGRP|unix.S_IROTH,
)
flags := os.O_RDONLY | unix.O_CLOEXEC | os.O_CREATE
if !ro {
flags |= os.O_RDWR
}
fd, err = unix.Open(path, flags, 0o644)
if err == nil {
return
}