Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to define flag and permissions of the file #76

Merged
merged 1 commit into from
Jun 30, 2024

Conversation

ldez
Copy link
Contributor

@ldez ldez commented Jun 30, 2024

To avoid breaking changes (constructor signature and existing behavior), I extended the current constructor with a variadic of functions to add options.

The approach avoids creating a new constructor, like NewWithOptions(path string, opts Options), and breaking the current constructor signature.

func New(path string, opts ...Option) *Flock {
	...
}

There are 2 options:

  • SetFlag: sets the flag used to create/open the file.
  • SetPermissions: sets the OS permissions to set on the file.
	_ = flock.New("example", flock.SetFlag(os.O_CREATE|os.O_RDWR)))
	_ = flock.New("example", flock.SetPermissions(os.FileMode(0o600)))
	_ = flock.New("example", flock.SetFlag(os.O_CREATE|os.O_RDWR), flock.SetPermissions(os.FileMode(0o600)))

Fixes #59

@ldez ldez merged commit 2bc2890 into gofrs:master Jun 30, 2024
13 checks passed
@ldez ldez deleted the feat/add-options branch June 30, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected behaviour: file created when acquiring lock
1 participant