File tree 2 files changed +18
-13
lines changed
2 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -176,9 +176,11 @@ func (f *Flock) setFh() error {
176
176
return nil
177
177
}
178
178
179
- // ensure the file handle is closed if no lock is held.
180
- func (f * Flock ) ensureFhState () {
181
- if f .l || f .r || f .fh == nil {
179
+ // resetFh resets file handle:
180
+ // - tries to close the file (ignore errors)
181
+ // - sets fh to nil.
182
+ func (f * Flock ) resetFh () {
183
+ if f .fh == nil {
182
184
return
183
185
}
184
186
@@ -187,11 +189,18 @@ func (f *Flock) ensureFhState() {
187
189
f .fh = nil
188
190
}
189
191
192
+ // ensure the file handle is closed if no lock is held.
193
+ func (f * Flock ) ensureFhState () {
194
+ if f .l || f .r || f .fh == nil {
195
+ return
196
+ }
197
+
198
+ f .resetFh ()
199
+ }
200
+
190
201
func (f * Flock ) reset () {
191
202
f .l = false
192
203
f .r = false
193
204
194
- _ = f .fh .Close ()
195
-
196
- f .fh = nil
205
+ f .resetFh ()
197
206
}
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ package flock
9
9
10
10
import (
11
11
"errors"
12
- "os"
13
12
14
13
"golang.org/x/sys/unix"
15
14
)
@@ -197,16 +196,13 @@ func (f *Flock) reopenFDOnError(err error) (bool, error) {
197
196
return false , nil
198
197
}
199
198
200
- _ = f .fh .Close ()
201
- f .fh = nil
199
+ f .resetFh ()
202
200
203
- // reopen in read-write mode and set the file handle
204
- fh , err := os . OpenFile ( f . path , f . flag , f . perm )
201
+ // reopen the file handle
202
+ err = f . setFh ( )
205
203
if err != nil {
206
204
return false , err
207
205
}
208
206
209
- f .fh = fh
210
-
211
207
return true , nil
212
208
}
You can’t perform that action at this time.
0 commit comments