+
Skip to content

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

Open
@rogpeppe

Description

@rogpeppe

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载