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

should provide straightforward way to know if file is already locked #10

Open
rogpeppe opened this issue Oct 22, 2015 · 0 comments
Open

Comments

@rogpeppe
Copy link

If the lock fails because of some reason other than it being already
locked, it would be nice to be able to tell that other than
with string comparison and checking .Temporary().
This would make it easer to implement blocking locks
based around a backoff-and-retry strategy (you probably
don't want to retry if you're getting EPERM for example).

For example (as an addition to the API):

// LockedError records an error that occurs when
// a file is already locked.
type LockedError struct {
    File string
}

func (e *LockedError) Error() string {
    return fmt.Sprintf("file %q already locked", e.File)
}

// IsLocked reports whether the error is due to
// a file being already locked.
func IsLocked(err error) bool {
    _, ok := err.(*LockedError)
    return ok
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant