Skip to content

Commit a531bd6

Browse files
authored
Merge pull request #2 from dsa0x/try-fslock
use fslock
2 parents a12d518 + 2b904eb commit a531bd6

File tree

7 files changed

+15
-90
lines changed

7 files changed

+15
-90
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v2
1818

19-
- name: Set up Go test for ${{ matrix.go-version }} on ${{ matrix.os }}
19+
- name: Set up workflow for ${{ matrix.go-version }} on ${{ matrix.os }}
2020
uses: actions/setup-go@v2
2121
with:
2222
go-version: ${{ matrix.go-version }}

dev.enc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5f990c89f9b5f406e2e6d3c641b6fea7efadd697e759f5b63f1cdfa6265f38d957eeb3==--==25a5bf6099052bf3b862e49f
1+
27737e8dfe9f1835d42dbf06f0b0f609431c40bd951f496819d917a47a0b25b644fa78==--==a7630f58252bb75c65ccff8f

filelock.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

filelock_test.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/dsa0x/sicher
22

33
go 1.17
44

5-
require golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
5+
require (
6+
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b // indirect
7+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
8+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b h1:FQ7+9fxhyp82ks9vAuyPzG0/vVbWwMwLJ+P6yJI5FN8=
2+
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b/go.mod h1:HMcgvsgd0Fjj4XXDkbjdmlbI505rUPBs6WBMYg2pXks=
13
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
24
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

sicher.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"reflect"
1818
"regexp"
1919
"time"
20+
21+
"github.com/juju/fslock"
2022
)
2123

2224
var delimiter = "==--=="
@@ -191,8 +193,11 @@ func (s *sicher) Edit(editor ...string) error {
191193
defer credFile.Close()
192194

193195
// lock file to enable only one edit at a time
194-
credFileLock := newFileLock(credFile)
195-
credFileLock.LockWithTimeout(time.Second * 10)
196+
credFileLock := fslock.New(credFile.Name()) //newFileLock(credFile)
197+
err = credFileLock.LockWithTimeout(time.Second * 10)
198+
if err != nil {
199+
return fmt.Errorf("error locking file: %s", err)
200+
}
196201
defer credFileLock.Unlock()
197202

198203
var buf bytes.Buffer

0 commit comments

Comments
 (0)