ghc-pkg: Try opening lockfiles in read-write mode first
authorBen Gamari <bgamari.foss@gmail.com>
Tue, 29 Aug 2017 18:26:55 +0000 (14:26 -0400)
committerBen Gamari <ben@smart-cactus.org>
Tue, 29 Aug 2017 23:08:07 +0000 (19:08 -0400)
commitf86de44dac0a6ca40c5fcd65f3a1944c45fa6011
tree94016ec9e646d1c94aa3875ea1900eaa840ed81e
parent5f6a82040694f7c8c2b394c1b418c0167b963e0b
ghc-pkg: Try opening lockfiles in read-write mode first

As pointed out in #13945, some filesystems only allow allow exclusive
locks if the fd being locked was opened for write access. This causes
ghc-pkg to fail as it first attempts to open and exclusively lock its
lockfile in read-only mode to accomodate package databases for which we
lack write permissions (e.g.  global package databases).

Instead, we now try read-write mode first, falling back to read-only
mode if this fails.

Reviewers: austin

Subscribers: rwbarton, thomie

GHC Trac Issues: #13945

Differential Revision: https://phabricator.haskell.org/D3897
libraries/ghc-boot/GHC/PackageDb.hs