on master help sign in
Run ob init in a temp dir to prevent leftovers when failing midway
commit00282640c46951fbd9f450761c55c5337a6e43a1 authorAlexandre Esteves <alexandre.fmp.esteves@gmail.com> dateThu 24 May 2018, 15:34 (8 years ago) parent209a6dc
1 file changed+16−4
lib/command/src/Obelisk/Command/Project.hs+16−4
lib/command/src/Obelisk/Command/Project.hs+16−4
@@ -24,6 +24,7 @@ import Data.Monoid
2424import qualified Data.Text as T
2525import System.Directory
2626import System.FilePath
27+import System.IO.Temp
2728import System.Posix (FileStatus, UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
2829import System.Posix.Files
2930import System.Process (CreateProcess, cwd, proc, waitForProcess)
@@ -67,10 +68,11 @@ toImplDir p = toObeliskDir p </> "impl"
6768
6869-- | Create a new project rooted in the current directory
6970initProject :: MonadObelisk m => InitSource -> m ()
70−initProject source = do
71− let implDir = toImplDir "."
71+initProject source = withSystemTempDirectory "ob-init" $ \tmpDir -> do
72+ let implDir = toImplDir tmpDir
73+ obDir = toObeliskDir tmpDir
7274 skeleton <- withSpinner "Setting up obelisk" $ do
73− liftIO $ createDirectory $ toObeliskDir "."
75+ liftIO $ createDirectory obDir
7476 case source of
7577 InitSource_Default -> createThunkWithLatest implDir obeliskSource
7678 InitSource_Branch branch -> createThunkWithLatest implDir $ obeliskSourceWithBranch branch
@@ -81,7 +83,17 @@ initProject source = do
8183 liftIO $ createSymbolicLink symlinkPath implDir
8284 _ <- nixBuildAttrWithCache implDir "command"
8385 --TODO: We should probably handoff to the impl here
84− nixBuildAttrWithCache implDir "skeleton" --TODO: I don't think there's actually any reason to cache this
86+ skel <- nixBuildAttrWithCache implDir "skeleton" --TODO: I don't think there's actually any reason to cache this
87+
88+ callProcessAndLogOutput (Notice, Error) $
89+ cp
90+ [ "-r"
91+ , "--preserve=links"
92+ , obDir
93+ , toObeliskDir "."
94+ ]
95+ pure skel
96+
8597 withSpinner "Copying project skeleton" $ do
8698 callProcessAndLogOutput (Notice, Error) $
8799 cp --TODO: Make this package depend on nix-prefetch-url properly