Skip to content

Commit 274d295

Browse files
authored
Merge pull request #6345 from haskell/lukko
Use lukko for file-locking
2 parents 39fb0a4 + fedadb3 commit 274d295

File tree

5 files changed

+56
-214
lines changed

5 files changed

+56
-214
lines changed

cabal-install/Distribution/Client/Compat/FileLock.hsc

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

cabal-install/Distribution/Client/Store.hs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE RecordWildCards, NamedFieldPuns #-}
1+
{-# LANGUAGE CPP, RecordWildCards, NamedFieldPuns #-}
22

33

44
-- | Management for the installed package store.
@@ -23,7 +23,6 @@ module Distribution.Client.Store (
2323

2424
import Prelude ()
2525
import Distribution.Client.Compat.Prelude
26-
import Distribution.Client.Compat.FileLock
2726

2827
import Distribution.Client.DistDirLayout
2928
import Distribution.Client.RebuildMonad
@@ -41,8 +40,16 @@ import Control.Exception
4140
import Control.Monad (forM_)
4241
import System.FilePath
4342
import System.Directory
44-
import System.IO
4543

44+
#ifdef MIN_VERSION_lukko
45+
import Lukko
46+
#else
47+
import System.IO (openFile, IOMode(ReadWriteMode), hClose)
48+
import GHC.IO.Handle.Lock (hLock, hTryLock, LockMode(ExclusiveLock))
49+
#if MIN_VERSION_base(4,11,0)
50+
import GHC.IO.Handle.Lock (hUnlock)
51+
#endif
52+
#endif
4653

4754
-- $concurrency
4855
--
@@ -235,6 +242,26 @@ withIncomingUnitIdLock verbosity StoreDirLayout{storeIncomingLock}
235242
compid unitid action =
236243
bracket takeLock releaseLock (\_hnd -> action)
237244
where
245+
#ifdef MIN_VERSION_lukko
246+
takeLock
247+
| fileLockingSupported = do
248+
fd <- fdOpen (storeIncomingLock compid unitid)
249+
gotLock <- fdTryLock fd ExclusiveLock
250+
unless gotLock $ do
251+
info verbosity $ "Waiting for file lock on store entry "
252+
++ display compid </> display unitid
253+
fdLock fd ExclusiveLock
254+
return fd
255+
256+
-- if there's no locking, do nothing. Be careful on AIX.
257+
| otherwise = return undefined -- :(
258+
259+
releaseLock fd
260+
| fileLockingSupported = do
261+
fdUnlock fd
262+
fdClose fd
263+
| otherwise = return ()
264+
#else
238265
takeLock = do
239266
h <- openFile (storeIncomingLock compid unitid) ReadWriteMode
240267
-- First try non-blocking, but if we would have to wait then
@@ -246,5 +273,5 @@ withIncomingUnitIdLock verbosity StoreDirLayout{storeIncomingLock}
246273
hLock h ExclusiveLock
247274
return h
248275

249-
releaseLock = hClose
250-
276+
releaseLock h = hUnlock h >> hClose h
277+
#endif

cabal-install/bootstrap.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ TAR_VER="0.5.1.0"; TAR_VER_REGEXP="0\.5\.([1-9]|1[0-9]|0\.[3-9]|0\.1[0-9])\.
266266
# >= 0.5.0.3 && < 0.6
267267
DIGEST_VER="0.0.1.2"; DIGEST_REGEXP="0\.0\.(1\.[2-9]|[2-9]\.?)"
268268
# >= 0.0.1.2 && < 0.1
269-
ZIP_ARCHIVE_VER="0.3.3"; ZIP_ARCHIVE_REGEXP="0\.3\.[3-9]"
270-
# >= 0.3.3 && < 0.4
269+
LUKKO_VER="0.1.1"; LUKKO_VER_REGEXP="0\.1\.[1-9]"
270+
# >= 0.1.1 && <0.2
271271

272272
HACKAGE_URL="https://hackage.haskell.org/package"
273273

@@ -471,7 +471,7 @@ info_pkg "edit-distance" ${EDIT_DISTANCE_VER} ${EDIT_DISTANCE_VER_REGEXP}
471471
info_pkg "ed25519" ${ED25519_VER} ${ED25519_VER_REGEXP}
472472
info_pkg "tar" ${TAR_VER} ${TAR_VER_REGEXP}
473473
info_pkg "digest" ${DIGEST_VER} ${DIGEST_REGEXP}
474-
info_pkg "zip-archive" ${ZIP_ARCHIVE_VER} ${ZIP_ARCHIVE_REGEXP}
474+
info_pkg "lukko" ${LUKKO_VER} ${LUKKO_REGEXP}
475475
info_pkg "hackage-security" ${HACKAGE_SECURITY_VER} \
476476
${HACKAGE_SECURITY_VER_REGEXP}
477477

@@ -509,7 +509,7 @@ do_pkg "edit-distance" ${EDIT_DISTANCE_VER} ${EDIT_DISTANCE_VER_REGEXP}
509509
do_pkg "ed25519" ${ED25519_VER} ${ED25519_VER_REGEXP}
510510
do_pkg "tar" ${TAR_VER} ${TAR_VER_REGEXP}
511511
do_pkg "digest" ${DIGEST_VER} ${DIGEST_REGEXP}
512-
do_pkg "zip-archive" ${ZIP_ARCHIVE_VER} ${ZIP_ARCHIVE_REGEXP}
512+
do_pkg "lukko" ${LUKKO_VER} ${LUKKO_REGEXP}
513513
do_pkg "hackage-security" ${HACKAGE_SECURITY_VER} \
514514
${HACKAGE_SECURITY_VER_REGEXP}
515515

cabal-install/cabal-install.cabal

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Category: Distribution
2121
Build-type: Custom
2222
Extra-Source-Files:
2323
README.md bash-completion/cabal bootstrap.sh changelog
24-
tests/README.md
2524

2625
-- Generated with 'make gen-extra-source-files'
2726
-- Do NOT edit this section manually; instead, run the script.
@@ -122,6 +121,11 @@ Flag debug-tracetree
122121
default: False
123122
manual: True
124123

124+
Flag lukko
125+
description: Use @lukko@ for file-locking
126+
default: True
127+
manual: True
128+
125129
custom-setup
126130
setup-depends:
127131
Cabal >= 2.2,
@@ -176,7 +180,6 @@ executable cabal
176180
Distribution.Client.CmdSdist
177181
Distribution.Client.Compat.Directory
178182
Distribution.Client.Compat.ExecutablePath
179-
Distribution.Client.Compat.FileLock
180183
Distribution.Client.Compat.FilePerms
181184
Distribution.Client.Compat.Prelude
182185
Distribution.Client.Compat.Process
@@ -352,6 +355,11 @@ executable cabal
352355
else
353356
build-depends: unix >= 2.5 && < 2.9
354357

358+
if flag(lukko)
359+
build-depends: lukko >= 0.1 && <0.2
360+
else
361+
build-depends: base >= 4.10
362+
355363
if flag(debug-expensive-assertions)
356364
cpp-options: -DDEBUG_EXPENSIVE_ASSERTIONS
357365

cabal-install/cabal-install.cabal.pp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
build-depends: Win32 >= 2 && < 3
6262
else
6363
build-depends: unix >= 2.5 && < 2.9
64+
65+
if flag(lukko)
66+
build-depends: lukko >= 0.1 && <0.2
67+
else
68+
build-depends: base >= 4.10
6469
%enddef
6570
%def CABAL_COMPONENTCOMMON
6671
default-language: Haskell2010
@@ -106,7 +111,6 @@
106111
Distribution.Client.CmdSdist
107112
Distribution.Client.Compat.Directory
108113
Distribution.Client.Compat.ExecutablePath
109-
Distribution.Client.Compat.FileLock
110114
Distribution.Client.Compat.FilePerms
111115
Distribution.Client.Compat.Prelude
112116
Distribution.Client.Compat.Process
@@ -275,7 +279,6 @@
275279
%endif
276280
Extra-Source-Files:
277281
README.md bash-completion/cabal bootstrap.sh changelog
278-
tests/README.md
279282
280283
-- Generated with 'make gen-extra-source-files'
281284
-- Do NOT edit this section manually; instead, run the script.
@@ -376,6 +379,11 @@
376379
default: False
377380
manual: True
378381
382+
Flag lukko
383+
description: Use @lukko@ for file-locking
384+
default: True
385+
manual: True
386+
379387
%if CABAL_FLAG_LIB
380388
%else
381389
custom-setup

0 commit comments

Comments
 (0)