Skip to content

Commit

Permalink
Removed ensureSymlink
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Jul 17, 2023
1 parent 7ec0e7a commit 433287a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
41 changes: 2 additions & 39 deletions IHP/LibDir.hs
Expand Up @@ -3,7 +3,7 @@ Module: IHP.LibDir
Description: Functions to access the IHP lib/ directory at runtime
Copyright: (c) digitally induced GmbH, 2020
-}
module IHP.LibDir (findLibDirectory, ensureSymlink) where
module IHP.LibDir (findLibDirectory) where

import IHP.Prelude
import qualified System.Directory as Directory
Expand All @@ -30,41 +30,4 @@ findLibDirectory = do
pure "build/ihp-lib/"
else do
binDir <- cs <$> Process.readCreateProcess (Process.shell "dirname $(which RunDevServer)") ""
pure (Text.strip binDir <> "/../lib/IHP/")

-- | Creates the build/ihp-lib symlink if missing
--
-- This is called in dev mode to make sure that build/ihp-lib points to the right IHP version.
-- Otherwise the CLI tools might not work as expected, e.g. @make db@ might fail.
--
-- If the symlink is missing, it tries to fix this by starting a new nix-shell and pinpointing the framework lib dir in there
ensureSymlink :: IO ()
ensureSymlink = do
frameworkMountedLocally <- Directory.doesDirectoryExist "IHP"
ihpLibSymlinkAvailable <- Directory.doesDirectoryExist "build/ihp-lib"

unless ihpLibSymlinkAvailable do
-- Make sure the build directory exists, otherwise we cannot add the symlink
Directory.createDirectoryIfMissing False "build"

libDir <- if frameworkMountedLocally
then pure "../IHP/lib/IHP/"
else do
putStrLn "Building build/ihp-lib. This might take a few seconds"
binDir <- cs <$> Process.readCreateProcess (Process.shell "nix-shell --run 'dirname $(which RunDevServer)'") ""
pure (Text.strip binDir <> "/../lib/IHP/")


-- Below code could fail with 'createSymbolicLink: already exists (File exists)'
-- This happens when the symlink points to a non existing target
--
-- Therefore we retry this operation on error and try to remove a possible
-- existing symlink in that case.
let createLink = Files.createSymbolicLink (cs libDir) "build/ihp-lib"

result <- Exception.try createLink
case result of
Left (exception :: SomeException) -> do
Files.removeLink "build/ihp-lib"
createLink
Right ok -> pure ok
pure (Text.strip binDir <> "/../lib/IHP/")
1 change: 0 additions & 1 deletion exe/IHP/IDE/DevServer.hs
Expand Up @@ -35,7 +35,6 @@ main = withUtf8 do
actionVar <- newEmptyMVar
appStateRef <- emptyAppState >>= newIORef
portConfig <- findAvailablePortConfig
LibDir.ensureSymlink
ensureUserIsNotRoot

-- Start the dev server in Debug mode by setting the env var DEBUG=1
Expand Down

0 comments on commit 433287a

Please sign in to comment.