Skip to content

Commit

Permalink
Merge pull request #938 from giuseppe/drop-lseek
Browse files Browse the repository at this point in the history
lockfile: merge Seek+Read/Write into Pread/Pwrite
  • Loading branch information
rhatdan authored Jun 9, 2021
2 parents 38ac468 + 10afc92 commit 23c70d0
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pkg/lockfile/lockfile_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ func (l *lockfile) Touch() error {
defer l.stateMutex.Unlock()
l.lw = stringid.GenerateRandomID()
id := []byte(l.lw)
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
if err != nil {
return err
}
n, err := unix.Write(int(l.fd), id)
n, err := unix.Pwrite(int(l.fd), id, 0)
if err != nil {
return err
}
Expand All @@ -217,11 +213,7 @@ func (l *lockfile) Modified() (bool, error) {
panic("attempted to check last-writer in lockfile without locking it first")
}
defer l.stateMutex.Unlock()
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
if err != nil {
return true, err
}
n, err := unix.Read(int(l.fd), id)
n, err := unix.Pread(int(l.fd), id, 0)
if err != nil {
return true, err
}
Expand Down

0 comments on commit 23c70d0

Please sign in to comment.