remove sim log file
This commit is contained in:
parent
24b3aed84a
commit
bab330de33
2 changed files with 6 additions and 21 deletions
|
@ -70,7 +70,6 @@ data SimState t = SimState
|
||||||
, simRebalance :: Bool
|
, simRebalance :: Bool
|
||||||
, simHistory :: [SimCommand]
|
, simHistory :: [SimCommand]
|
||||||
, simVectorClock :: VectorClock
|
, simVectorClock :: VectorClock
|
||||||
, simLogFile :: Maybe FilePath
|
|
||||||
, simRootDirectory :: FilePath
|
, simRootDirectory :: FilePath
|
||||||
}
|
}
|
||||||
deriving (Show, Read)
|
deriving (Show, Read)
|
||||||
|
@ -93,7 +92,6 @@ emptySimState rngseed rootdir = SimState
|
||||||
, simRebalance = False
|
, simRebalance = False
|
||||||
, simHistory = []
|
, simHistory = []
|
||||||
, simVectorClock = VectorClock 0
|
, simVectorClock = VectorClock 0
|
||||||
, simLogFile = Nothing
|
|
||||||
, simRootDirectory = rootdir
|
, simRootDirectory = rootdir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,8 @@ seek ("show":[]) = do
|
||||||
simdir <- fromRepo gitAnnexSimDir
|
simdir <- fromRepo gitAnnexSimDir
|
||||||
liftIO (restoreSim simdir) >>= \case
|
liftIO (restoreSim simdir) >>= \case
|
||||||
Left err -> giveup err
|
Left err -> giveup err
|
||||||
Right st -> case simLogFile st of
|
Right st -> liftIO $ putStr $ generateSimFile $
|
||||||
Just f -> liftIO $ putStr =<< readFile f
|
reverse $ simHistory st
|
||||||
Nothing -> return ()
|
|
||||||
seek ps = case parseSimCommand ps of
|
seek ps = case parseSimCommand ps of
|
||||||
Left err -> giveup err
|
Left err -> giveup err
|
||||||
Right simcmd -> do
|
Right simcmd -> do
|
||||||
|
@ -66,9 +65,9 @@ seek ps = case parseSimCommand ps of
|
||||||
simdir <- fromRepo gitAnnexSimDir
|
simdir <- fromRepo gitAnnexSimDir
|
||||||
liftIO (restoreSim simdir) >>= \case
|
liftIO (restoreSim simdir) >>= \case
|
||||||
Left err -> giveup err
|
Left err -> giveup err
|
||||||
Right st ->
|
Right st ->
|
||||||
runSimCommand simcmd repobyname st
|
runSimCommand simcmd repobyname st
|
||||||
>>= liftIO . saveState
|
>>= liftIO . suspendSim
|
||||||
|
|
||||||
start :: Maybe FilePath -> CommandSeek
|
start :: Maybe FilePath -> CommandSeek
|
||||||
start simfile = do
|
start simfile = do
|
||||||
|
@ -76,13 +75,8 @@ start simfile = do
|
||||||
whenM (liftIO $ doesDirectoryExist simdir) $
|
whenM (liftIO $ doesDirectoryExist simdir) $
|
||||||
giveup "A sim was previously started. Use `git-annex sim end` to stop it before starting a new one."
|
giveup "A sim was previously started. Use `git-annex sim end` to stop it before starting a new one."
|
||||||
|
|
||||||
let simlogfile = case simfile of
|
|
||||||
Nothing -> simdir </> "log.sim"
|
|
||||||
Just f -> simdir </> takeFileName f
|
|
||||||
|
|
||||||
rng <- fst . random <$> initStdGen
|
rng <- fst . random <$> initStdGen
|
||||||
let st = (emptySimState rng simdir)
|
let st = emptySimState rng simdir
|
||||||
{ simLogFile = Just simlogfile }
|
|
||||||
case simfile of
|
case simfile of
|
||||||
Nothing -> startup simdir st []
|
Nothing -> startup simdir st []
|
||||||
Just f -> liftIO (readFile f) >>= \c ->
|
Just f -> liftIO (readFile f) >>= \c ->
|
||||||
|
@ -96,16 +90,9 @@ start simfile = do
|
||||||
createAnnexDirectory (toRawFilePath simdir)
|
createAnnexDirectory (toRawFilePath simdir)
|
||||||
let st' = recordSeed st cs
|
let st' = recordSeed st cs
|
||||||
st'' <- go st' repobyname cs
|
st'' <- go st' repobyname cs
|
||||||
liftIO $ saveState st''
|
liftIO $ suspendSim st''
|
||||||
|
|
||||||
go st _ [] = return st
|
go st _ [] = return st
|
||||||
go st repobyname (c:cs) = do
|
go st repobyname (c:cs) = do
|
||||||
st' <- runSimCommand c repobyname st
|
st' <- runSimCommand c repobyname st
|
||||||
go st' repobyname cs
|
go st' repobyname cs
|
||||||
|
|
||||||
saveState :: SimState SimRepo -> IO ()
|
|
||||||
saveState st = do
|
|
||||||
suspendSim st
|
|
||||||
case simLogFile st of
|
|
||||||
Just f -> writeFile f $ generateSimFile $ reverse $ simHistory st
|
|
||||||
Nothing -> noop
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue