Skip to content

Commit

Permalink
Merge pull request #17 from sk91/file-permissions
Browse files Browse the repository at this point in the history
feat: add an option to configure lock file permissions
  • Loading branch information
alexflint authored Jan 11, 2024
2 parents 5b05e68 + 55ffc3a commit 27556bd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions filemutex_flock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux netbsd openbsd solaris

package filemutex

import "golang.org/x/sys/unix"
import (
"os"

"golang.org/x/sys/unix"
)

const (
mkdirPerm = 0750
mkdirPerm os.FileMode = 0750
)

// FileMutex is similar to sync.RWMutex, but also synchronizes across processes.
Expand All @@ -19,7 +24,15 @@ type FileMutex struct {
}

func New(filename string) (*FileMutex, error) {
fd, err := unix.Open(filename, unix.O_CREAT|unix.O_RDONLY, mkdirPerm)
return new(filename, mkdirPerm)
}

func NewWithMode(filename string, perm os.FileMode) (*FileMutex, error) {
return new(filename, perm)
}

func new(filename string, perm os.FileMode) (*FileMutex, error) {
fd, err := unix.Open(filename, unix.O_CREAT|unix.O_RDONLY, uint32(perm))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 27556bd

Please sign in to comment.