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

chore: add GitHub Action #64

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Go Matrix

on:
push:
branches:
- main
- master
pull_request:

jobs:

cross:
name: Go
strategy:
matrix:
go-version: [ stable, oldstable ]
os: [ubuntu-latest, macos-latest, windows-latest]
env:
CGO_ENABLED: 1
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Check and get dependencies
run: |
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum

- name: Test
run: go test -v -check.vv -race ./...
33 changes: 33 additions & 0 deletions .github/workflows/pr-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PR only

on:
push:
branches:
- main
- master
pull_request:

jobs:

pr:
name: Linting
strategy:
matrix:
go-version: [ stable, oldstable ]
os: [ubuntu-latest, macos-latest, windows-latest]
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.59
CGO_ENABLED: 0
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright (c) 2018-2024, The Gofrs
Copyright (c) 2015-2020, Tim Heckman
All rights reserved.

Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# flock
[![TravisCI Build Status](https://img.shields.io/travis/gofrs/flock/master.svg?style=flat)](https://travis-ci.org/gofrs/flock)
[![GoDoc](https://img.shields.io/badge/godoc-flock-blue.svg?style=flat)](https://godoc.org/github.com/gofrs/flock)

[![Go Reference](https://pkg.go.dev/badge/github.com/gofrs/flock.svg)](https://pkg.go.dev/github.com/gofrs/flock)
[![License](https://img.shields.io/badge/license-BSD_3--Clause-brightgreen.svg?style=flat)](https://github.com/gofrs/flock/blob/master/LICENSE)
[![Go Report Card](https://goreportcard.com/badge/github.com/gofrs/flock)](https://goreportcard.com/report/github.com/gofrs/flock)

`flock` implements a thread-safe sync.Locker interface for file locking. It also
includes a non-blocking TryLock() function to allow locking without blocking execution.
`flock` implements a thread-safe sync.Locker interface for file locking.
It also includes a non-blocking `TryLock()` function to allow locking without blocking execution.

## License

`flock` is released under the BSD 3-Clause License. See the `LICENSE` file for more details.

## Go Compatibility
This package makes use of the `context` package that was introduced in Go 1.7. As such, this
package has an implicit dependency on Go 1.7+.

This package makes use of the `context` package that was introduced in Go 1.7.
As such, this package has an implicit dependency on Go 1.7+.

## Installation
```

```bash
go get -u github.com/gofrs/flock
```

## Usage
```Go

```go
import "github.com/gofrs/flock"

fileLock := flock.New("/var/lock/go-lock.lock")
Expand All @@ -38,4 +42,4 @@ if locked {
```

For more detailed usage information take a look at the package API docs on
[GoDoc](https://godoc.org/github.com/gofrs/flock).
[GoDoc](https://pkg.go.dev/github.com/gofrs/flock).
25 changes: 0 additions & 25 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion flock_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// This code is adapted from the Go package:
// cmd/go/internal/lockedfile/internal/filelock

//+build aix
//go:build aix

package flock

Expand Down
14 changes: 10 additions & 4 deletions flock_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ import (

func ExampleFlock_Locked() {
f := flock.New(os.TempDir() + "/go-lock.lock")
f.TryLock() // unchecked errors here

_, err := f.TryLock()
if err != nil {
// handle locking error
}

fmt.Printf("locked: %v\n", f.Locked())

f.Unlock()
err = f.Unlock()
if err != nil {
// handle locking error
}

fmt.Printf("locked: %v\n", f.Locked())
// Output: locked: true
Expand All @@ -32,7 +39,6 @@ func ExampleFlock_TryLock() {
fileLock := flock.New(os.TempDir() + "/go-lock.lock")

locked, err := fileLock.TryLock()

if err != nil {
// handle locking error
}
Expand All @@ -54,8 +60,8 @@ func ExampleFlock_TryLockContext() {

lockCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
locked, err := fileLock.TryLockContext(lockCtx, 678*time.Millisecond)

locked, err := fileLock.TryLockContext(lockCtx, 678*time.Millisecond)
if err != nil {
// handle locking error
}
Expand Down
3 changes: 1 addition & 2 deletions flock_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package flock

import (
"io/ioutil"
"os"
"testing"
)

func Test(t *testing.T) {
tmpFileFh, err := ioutil.TempFile(os.TempDir(), "go-flock-")
tmpFileFh, err := os.CreateTemp(os.TempDir(), "go-flock-")
tmpFileFh.Close()
tmpFile := tmpFileFh.Name()
os.Remove(tmpFile)
Expand Down
19 changes: 6 additions & 13 deletions flock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package flock_test

import (
"context"
"io/ioutil"
"os"
"runtime"
"testing"
Expand All @@ -28,7 +27,7 @@ var _ = Suite(&TestSuite{})
func Test(t *testing.T) { TestingT(t) }

func (t *TestSuite) SetUpTest(c *C) {
tmpFile, err := ioutil.TempFile(os.TempDir(), "go-flock-")
tmpFile, err := os.CreateTemp(os.TempDir(), "go-flock-")
c.Assert(err, IsNil)
c.Assert(tmpFile, Not(IsNil))

Expand All @@ -46,36 +45,30 @@ func (t *TestSuite) TearDownTest(c *C) {
}

func (t *TestSuite) TestNew(c *C) {
var f *flock.Flock

f = flock.New(t.path)
f := flock.New(t.path)
c.Assert(f, Not(IsNil))
c.Check(f.Path(), Equals, t.path)
c.Check(f.Locked(), Equals, false)
c.Check(f.RLocked(), Equals, false)
}

func (t *TestSuite) TestFlock_Path(c *C) {
var path string
path = t.flock.Path()
path := t.flock.Path()
c.Check(path, Equals, t.path)
}

func (t *TestSuite) TestFlock_Locked(c *C) {
var locked bool
locked = t.flock.Locked()
locked := t.flock.Locked()
c.Check(locked, Equals, false)
}

func (t *TestSuite) TestFlock_RLocked(c *C) {
var locked bool
locked = t.flock.RLocked()
locked := t.flock.RLocked()
c.Check(locked, Equals, false)
}

func (t *TestSuite) TestFlock_String(c *C) {
var str string
str = t.flock.String()
str := t.flock.String()
c.Assert(str, Equals, t.path)
}

Expand Down
7 changes: 4 additions & 3 deletions flock_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by the BSD 3-Clause
// license that can be found in the LICENSE file.

// +build !aix,!windows
//go:build !aix && !windows

package flock

Expand Down Expand Up @@ -171,8 +171,9 @@ retry:

// reopenFDOnError determines whether we should reopen the file handle
// in readwrite mode and try again. This comes from util-linux/sys-utils/flock.c:
// Since Linux 3.4 (commit 55725513)
// Probably NFSv4 where flock() is emulated by fcntl().
//
// Since Linux 3.4 (commit 55725513)
// Probably NFSv4 where flock() is emulated by fcntl().
func (f *Flock) reopenFDOnError(err error) (bool, error) {
if err != syscall.EIO && err != syscall.EBADF {
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion flock_winapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by the BSD 3-Clause
// license that can be found in the LICENSE file.

// +build windows
//go:build windows

package flock

Expand Down