Commit aac285c2 authored by Clément Chigot's avatar Clément Chigot Committed by Bryan C. Mills

cmd/go/internal/lockedfile: fix filelock.Unlock() called twice

filelock.Unlock() was called twice for fcntl implementation if an error
occurs during file.{,R}Lock(): once in the error handler, once in
filelock.lock().

Change-Id: I5ad84e8ef6b5e51d79e0a7a0c51f465276cd0c57
Reviewed-on: https://go-review.googlesource.com/c/152717
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBryan C. Mills <bcmills@google.com>
parent 5e172789
......@@ -29,24 +29,25 @@ func openFile(name string, flag int, perm os.FileMode) (*os.File, error) {
default:
err = filelock.RLock(f)
}
if err == nil && flag&os.O_TRUNC == os.O_TRUNC {
if err = f.Truncate(0); err != nil {
if err != nil {
f.Close()
return nil, err
}
if flag&os.O_TRUNC == os.O_TRUNC {
if err := f.Truncate(0); err != nil {
// The documentation for os.O_TRUNC says “if possible, truncate file when
// opened”, but doesn't define “possible” (golang.org/issue/28699).
// We'll treat regular files (and symlinks to regular files) as “possible”
// and ignore errors for the rest.
if fi, statErr := f.Stat(); statErr == nil && !fi.Mode().IsRegular() {
err = nil
if fi, statErr := f.Stat(); statErr != nil || fi.Mode().IsRegular() {
filelock.Unlock(f)
f.Close()
return nil, err
}
}
}
if err != nil {
filelock.Unlock(f)
f.Close()
return nil, err
}
return f, nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment