2019-05-31 00:24:14 +03:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import ClassyPrelude
|
2019-07-16 03:01:45 +03:00
|
|
|
|
|
|
|
import Noun
|
2019-05-31 00:24:14 +03:00
|
|
|
import Vere.Pier.Types
|
2019-07-16 03:01:45 +03:00
|
|
|
import Vere.Pier
|
|
|
|
import Vere.Serf
|
2019-07-19 03:52:53 +03:00
|
|
|
import Data.Acquire
|
|
|
|
import Data.Conduit
|
|
|
|
import Data.Conduit.List
|
2019-07-16 03:01:45 +03:00
|
|
|
|
2019-07-16 05:20:23 +03:00
|
|
|
import Control.Concurrent (threadDelay)
|
2019-07-19 03:52:53 +03:00
|
|
|
import System.Directory (removeFile, doesFileExist)
|
2019-07-16 05:20:23 +03:00
|
|
|
import Text.Show.Pretty (pPrint)
|
2019-06-25 04:10:41 +03:00
|
|
|
|
|
|
|
import qualified Vere.Log as Log
|
|
|
|
import qualified Vere.Persist as Persist
|
|
|
|
import qualified Vere.Pier as Pier
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2019-05-31 00:24:14 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
removeFileIfExists :: FilePath -> IO ()
|
|
|
|
removeFileIfExists pax = do
|
|
|
|
exists <- doesFileExist pax
|
|
|
|
when exists $ do
|
|
|
|
removeFile pax
|
|
|
|
|
2019-07-17 08:32:36 +03:00
|
|
|
wipeSnapshot :: FilePath -> IO ()
|
|
|
|
wipeSnapshot shipPath = do
|
2019-07-19 03:52:53 +03:00
|
|
|
removeFileIfExists (shipPath <> ".urb/chk/north.bin")
|
|
|
|
removeFileIfExists (shipPath <> ".urb/chk/south.bin")
|
2019-06-25 04:10:41 +03:00
|
|
|
|
2019-07-17 08:32:36 +03:00
|
|
|
tryBootFromPill :: FilePath -> FilePath -> Ship -> IO ()
|
|
|
|
tryBootFromPill pillPath shipPath ship = do
|
|
|
|
wipeSnapshot shipPath
|
2019-07-19 03:52:53 +03:00
|
|
|
Pier.boot pillPath shipPath ship $ \s l ss -> do
|
|
|
|
print "lul"
|
|
|
|
print ss
|
|
|
|
threadDelay 500000
|
|
|
|
shutdownAndWait s 0 >>= print
|
|
|
|
putStrLn "Booted!"
|
2019-07-16 05:20:23 +03:00
|
|
|
|
2019-07-17 08:32:36 +03:00
|
|
|
tryResume :: FilePath -> IO ()
|
|
|
|
tryResume shipPath = do
|
2019-07-19 03:52:53 +03:00
|
|
|
Pier.resume shipPath $ \s l ss -> do
|
|
|
|
print ss
|
|
|
|
threadDelay 500000
|
|
|
|
shutdownAndWait s 0 >>= print
|
|
|
|
putStrLn "Resumed!"
|
2019-06-25 04:10:41 +03:00
|
|
|
|
2019-07-17 08:32:36 +03:00
|
|
|
tryFullReplay :: FilePath -> IO ()
|
|
|
|
tryFullReplay shipPath = do
|
|
|
|
wipeSnapshot shipPath
|
|
|
|
tryResume shipPath
|
|
|
|
|
|
|
|
zod :: Ship
|
|
|
|
zod = 0
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
let pillPath = "/home/benjamin/r/urbit/bin/brass.pill"
|
|
|
|
shipPath = "/home/benjamin/r/urbit/zod/"
|
|
|
|
ship = zod
|
|
|
|
|
|
|
|
tryBootFromPill pillPath shipPath ship
|
|
|
|
|
|
|
|
tryResume shipPath
|
|
|
|
|
|
|
|
tryFullReplay shipPath
|
|
|
|
|
2019-07-16 03:01:45 +03:00
|
|
|
pure ()
|
2019-06-25 04:10:41 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
tryCopyLog :: IO ()
|
|
|
|
tryCopyLog = do
|
|
|
|
let logPath = "/Users/erg/src/urbit/zod/.urb/falselog/"
|
2019-05-31 02:04:06 +03:00
|
|
|
falselogPath = "/Users/erg/src/urbit/zod/.urb/falselog2/"
|
2019-05-31 00:24:14 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
(ident, nextEv, events) <-
|
|
|
|
with (Log.existing logPath) $ \log -> do
|
|
|
|
persistQ <- newTQueueIO
|
|
|
|
releaseQ <- newTQueueIO
|
|
|
|
persist <- Persist.start log persistQ (writeTQueue releaseQ)
|
|
|
|
ident <- pure $ Log.identity log
|
|
|
|
events <- runConduit (Log.streamEvents log 1 .| consume)
|
|
|
|
nextEv <- Log.nextEv log
|
|
|
|
pure (ident, nextEv, events)
|
2019-05-31 00:24:14 +03:00
|
|
|
|
2019-06-25 04:10:41 +03:00
|
|
|
print ident
|
2019-07-19 03:52:53 +03:00
|
|
|
print nextEv
|
2019-06-25 04:10:41 +03:00
|
|
|
print (length events)
|
2019-05-31 00:24:14 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
with (Log.new falselogPath ident) $ \log2 -> do
|
|
|
|
persistQ2 <- newTQueueIO
|
|
|
|
releaseQ2 <- newTQueueIO
|
|
|
|
persist2 <- Persist.start log2 persistQ2 (writeTQueue releaseQ2)
|
2019-06-25 04:10:41 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
let writs = zip [1..] events <&> \(id, a) ->
|
|
|
|
Writ id Nothing (Jam a) []
|
2019-06-25 04:10:41 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
print "About to write"
|
2019-05-31 00:24:14 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
for_ writs $ \w ->
|
|
|
|
atomically (writeTQueue persistQ2 w)
|
2019-05-31 00:24:14 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
print "About to wait"
|
2019-06-25 04:10:41 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
replicateM_ 100 $ do
|
|
|
|
atomically $ readTQueue releaseQ2
|
2019-06-25 04:10:41 +03:00
|
|
|
|
2019-07-19 03:52:53 +03:00
|
|
|
print "Done"
|