Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New output-restore-list option for capturing a list of all products restored #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/App/Commands/Options/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ data PlanOptions = PlanOptions
} deriving (Eq, Show, Generic)

data SyncFromArchiveOptions = SyncFromArchiveOptions
{ region :: Region
, archiveUris :: [Location]
, buildPath :: FilePath
, storePath :: FilePath
, storePathHash :: Maybe String
, threads :: Int
, awsLogLevel :: Maybe AWS.LogLevel
{ region :: Region
, archiveUris :: [Location]
, buildPath :: FilePath
, storePath :: FilePath
, storePathHash :: Maybe String
, threads :: Int
, awsLogLevel :: Maybe AWS.LogLevel
, outputRestoreList :: Maybe FilePath
} deriving (Eq, Show, Generic)

data VersionOptions = VersionOptions deriving (Eq, Show, Generic)
18 changes: 17 additions & 1 deletion app/App/Commands/SyncFromArchive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import qualified HaskellWorks.CabalCache.IO.Lazy as IO
import qualified HaskellWorks.CabalCache.IO.Tar as IO
import qualified HaskellWorks.CabalCache.Types as Z
import qualified System.Directory as IO
import qualified System.Exit as IO
import qualified System.IO as IO
import qualified System.IO.Temp as IO
import qualified System.IO.Unsafe as IO
Expand All @@ -71,6 +72,9 @@ runSyncFromArchive opts = do
let storePathHash = opts ^. the @"storePathHash" & fromMaybe (H.hashStorePath storePath)
let scopedArchiveUris = versionedArchiveUris & each %~ (</> T.pack storePathHash)

maybeHandleRestoreList <- forM (opts ^. the @"outputRestoreList") $ \restoreListFile -> do
IO.openFile restoreListFile IO.WriteMode

CIO.putStrLn $ "Store path: " <> toText storePath
CIO.putStrLn $ "Store path hash: " <> T.pack storePathHash
forM_ archiveUris $ \archiveUri -> do
Expand Down Expand Up @@ -149,6 +153,10 @@ runSyncFromArchive opts = do
(existingArchiveFileContents, existingArchiveFile) <- ExceptT $ IO.readFirstAvailableResource envAws (foldMap L.tuple2ToList (L.zip archiveFiles scopedArchiveFiles))
CIO.putStrLn $ "Extracting: " <> toText existingArchiveFile

forM_ maybeHandleRestoreList $ \handleRestoreList -> do
liftIO $ IO.hPutStrLn handleRestoreList (T.unpack (toText existingArchiveFile))
liftIO $ IO.hFlush handleRestoreList

let tempArchiveFile = tempPath </> archiveBaseName
liftIO $ LBS.writeFile tempArchiveFile existingArchiveFileContents
IO.extractTar tempArchiveFile storePath
Expand Down Expand Up @@ -180,8 +188,9 @@ runSyncFromArchive opts = do
Left msg -> CIO.hPutStrLn IO.stderr msg
Left appError -> do
CIO.hPutStrLn IO.stderr $ "ERROR: Unable to parse plan.json file: " <> displayAppError appError
IO.exitFailure

return ()
forM_ maybeHandleRestoreList IO.hClose

cleanupStorePath :: (MonadIO m, MonadCatch m) => FilePath -> Z.PackageId -> AppError -> m ()
cleanupStorePath packageStorePath packageId e = do
Expand Down Expand Up @@ -244,6 +253,13 @@ optsSyncFromArchive = SyncFromArchiveOptions
<> metavar "AWS_LOG_LEVEL"
)
)
<*> optional
( strOption
( long "output-restore-list"
<> help "File to which a list of restored cabal store products will be written"
<> metavar "FILE"
)
)

cmdSyncFromArchive :: Mod CommandFields (IO ())
cmdSyncFromArchive = command "sync-from-archive" $ flip info idm $ runSyncFromArchive <$> optsSyncFromArchive