on master help sign in
Merge pull request #5 from alexfmpe/ob-init-tmp-dir
abb6978Luigy Leon
lib/command/src/Obelisk/Command/Project.hs+16−4
@@ -24,6 +24,7 @@ import Data.Monoid
24import qualified Data.Text as T
24import qualified Data.Text as T
25import System.Directory
25import System.Directory
26import System.FilePath
26import System.FilePath
27+import System.IO.Temp
27import System.Posix (FileStatus, UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
28import System.Posix (FileStatus, UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
28import System.Posix.Files
29import System.Posix.Files
29import System.Process (CreateProcess, cwd, proc, waitForProcess)
30import System.Process (CreateProcess, cwd, proc, waitForProcess)
@@ -67,10 +68,11 @@ toImplDir p = toObeliskDir p </> "impl"
67
68
68-- | Create a new project rooted in the current directory
69-- | Create a new project rooted in the current directory
69initProject :: MonadObelisk m => InitSource -> m ()
70initProject :: MonadObelisk m => InitSource -> m ()
70−initProject source = do
71+initProject source = withSystemTempDirectory "ob-init" $ \tmpDir -> do
71− let implDir = toImplDir "."
72+ let implDir = toImplDir tmpDir
73+ obDir = toObeliskDir tmpDir
72 skeleton <- withSpinner "Setting up obelisk" $ do
74 skeleton <- withSpinner "Setting up obelisk" $ do
73− liftIO $ createDirectory $ toObeliskDir "."
75+ liftIO $ createDirectory obDir
74 case source of
76 case source of
75 InitSource_Default -> createThunkWithLatest implDir obeliskSource
77 InitSource_Default -> createThunkWithLatest implDir obeliskSource
76 InitSource_Branch branch -> createThunkWithLatest implDir $ obeliskSourceWithBranch branch
78 InitSource_Branch branch -> createThunkWithLatest implDir $ obeliskSourceWithBranch branch
@@ -81,7 +83,17 @@ initProject source = do
81 liftIO $ createSymbolicLink symlinkPath implDir
83 liftIO $ createSymbolicLink symlinkPath implDir
82 _ <- nixBuildAttrWithCache implDir "command"
84 _ <- nixBuildAttrWithCache implDir "command"
83 --TODO: We should probably handoff to the impl here
85 --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+
85 withSpinner "Copying project skeleton" $ do
97 withSpinner "Copying project skeleton" $ do
86 callProcessAndLogOutput (Notice, Error) $
98 callProcessAndLogOutput (Notice, Error) $
87 cp --TODO: Make this package depend on nix-prefetch-url properly
99 cp --TODO: Make this package depend on nix-prefetch-url properly