Skip to content

Commit

Permalink
use temp_versionFileLocalPath and temp_versionFileRemotePath for down…
Browse files Browse the repository at this point in the history
…loding as well
  • Loading branch information
fabb committed Mar 24, 2019
1 parent 17a409d commit e5216c4
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 142 deletions.
108 changes: 62 additions & 46 deletions src/Caches/Local/Downloading.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,34 @@ getVersionFileFromLocalCache
:: MonadIO m
=> FilePath -- ^ The cache definition
-> CachePrefix -- ^ A prefix for folders at top level in the cache.
-> ProjectNameAndVersion -- ^ The `ProjectNameAndVersion` used to identify the .version file
-> InvertedRepositoryMap -- ^ The map used to resolve from a `FrameworkVersion` to the path of the Framework in the cache
-> FrameworkVector -- ^ The `FrameworkVector` used to identify the .version file
-> ExceptT String m LBS.ByteString
getVersionFileFromLocalCache lCacheDir (CachePrefix prefix) projectNameAndVersion
getVersionFileFromLocalCache lCacheDir (CachePrefix prefix) reverseRomeMap fVector
= do
versionFileExistsInLocalCache <-
liftIO . doesFileExist $ versionFileLocalCachePath

if versionFileExistsInLocalCache
then
liftIO
. runResourceT
. C.runConduit
$ C.sourceFile versionFileLocalCachePath
C..| C.sinkLbs
else
throwError
$ "Error: could not find "
<> versionFileName
<> " in local cache at : "
<> versionFileLocalCachePath
where
versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion
versionFileRemotePath = remoteVersionFilePath projectNameAndVersion
versionFileLocalCachePath = lCacheDir </> prefix </> versionFileRemotePath
case temp_versionFileRemotePath reverseRomeMap fVector of
Just versionFileRemotePath -> do
versionFileExistsInLocalCache <-
liftIO . doesFileExist $ versionFileLocalCachePath

if versionFileExistsInLocalCache
then
liftIO
. runResourceT
. C.runConduit
$ C.sourceFile versionFileLocalCachePath
C..| C.sinkLbs
else
throwError
$ "Error: could not find "
<> verboseDebugFileName
<> " in local cache at : "
<> versionFileLocalCachePath
where
verboseDebugFileName = takeFileName $ versionFileRemotePath
versionFileLocalCachePath =
lCacheDir </> prefix </> versionFileRemotePath
_ -> pure mempty



Expand Down Expand Up @@ -404,10 +408,11 @@ getAndUnzipDSYMFromLocalCache buildTypeConfig lCacheDir reverseRomeMap fVector p
getAndSaveVersionFilesFromLocalCache
:: MonadIO m
=> FilePath -- ^ The cache definition.
-> [ProjectNameAndVersion] -- ^ A list of `ProjectNameAndVersion` identifying the .version files
-> InvertedRepositoryMap
-> [FrameworkVector] -- ^ A list of `FrameworkVector` identifying the .version files
-> [ExceptT String (ReaderT (CachePrefix, Bool) m) ()]
getAndSaveVersionFilesFromLocalCache lCacheDir =
map (getAndSaveVersionFileFromLocalCache lCacheDir)
getAndSaveVersionFilesFromLocalCache lCacheDir reverseRomeMap =
map (getAndSaveVersionFileFromLocalCache lCacheDir reverseRomeMap)



Expand All @@ -416,28 +421,39 @@ getAndSaveVersionFilesFromLocalCache lCacheDir =
getAndSaveVersionFileFromLocalCache
:: MonadIO m
=> FilePath -- ^ The cache definition.
-> ProjectNameAndVersion -- ^ The `ProjectNameAndVersion` identifying the .version file
-> InvertedRepositoryMap
-> FrameworkVector -- ^ The `FrameworkVector` used to indentify the .version file
-> ExceptT String (ReaderT (CachePrefix, Bool) m) ()
getAndSaveVersionFileFromLocalCache lCacheDir projectNameAndVersion = do
(cachePrefix@(CachePrefix prefix), verbose) <- ask
let finalVersionFileLocalCachePath = versionFileLocalCachePath prefix
let sayFunc = if verbose then sayLnWithTime else sayLn
versionFileBinary <- getVersionFileFromLocalCache lCacheDir
cachePrefix
projectNameAndVersion
sayFunc
$ "Found "
<> versionFileName
<> " in local cache at: "
<> finalVersionFileLocalCachePath
liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath
sayFunc $ "Copied " <> versionFileName <> " to: " <> versionFileLocalPath
where
versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion
versionFileRemotePath = remoteVersionFilePath projectNameAndVersion
versionFileLocalPath = carthageBuildDirectory </> versionFileName
versionFileLocalCachePath cPrefix =
lCacheDir </> cPrefix </> versionFileRemotePath
getAndSaveVersionFileFromLocalCache lCacheDir reverseRomeMap fVector = do
case
( temp_versionFileLocalPath reverseRomeMap fVector
, temp_versionFileRemotePath reverseRomeMap fVector
)
of
(Just versionFileLocalPath, Just versionFileRemotePath) -> do
(cachePrefix@(CachePrefix prefix), verbose) <- ask
let finalVersionFileLocalCachePath = versionFileLocalCachePath prefix
let sayFunc = if verbose then sayLnWithTime else sayLn
versionFileBinary <- getVersionFileFromLocalCache lCacheDir
cachePrefix
reverseRomeMap
fVector
sayFunc
$ "Found "
<> verboseDebugFileName
<> " in local cache at: "
<> finalVersionFileLocalCachePath
liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath
sayFunc
$ "Copied "
<> verboseDebugFileName
<> " to: "
<> versionFileLocalPath
where
verboseDebugFileName = takeFileName $ versionFileRemotePath
versionFileLocalCachePath cPrefix =
lCacheDir </> cPrefix </> versionFileRemotePath
_ -> pure mempty



29 changes: 16 additions & 13 deletions src/Caches/S3/Downloading.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import qualified Data.Text as T
import qualified Network.AWS as AWS
import qualified Network.AWS.S3 as S3
import System.Directory ( doesFileExist )
import System.FilePath ( (</>) )
import System.FilePath ( (</>)
, takeFileName
)
import Types hiding ( version )
import Utils
import Xcode.DWARF
Expand Down Expand Up @@ -93,22 +95,23 @@ getDSYMFromS3 s3BucketName reverseRomeMap fVector platform = do
-- | Carthage only, not necessary for PodBuilder
getVersionFileFromS3
:: S3.BucketName
-> ProjectNameAndVersion
-> InvertedRepositoryMap
-> FrameworkVector
-> ExceptT
String
(ReaderT (AWS.Env, CachePrefix, Bool) IO)
LBS.ByteString
getVersionFileFromS3 s3BucketName projectNameAndVersion = do
(env, CachePrefix prefix, verbose) <- ask
let finalVersionFileRemotePath = prefix </> versionFileRemotePath
mapExceptT (withReaderT (const (env, verbose))) $ getArtifactFromS3
s3BucketName
finalVersionFileRemotePath
versionFileName
where
versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion
versionFileRemotePath = remoteVersionFilePath projectNameAndVersion

getVersionFileFromS3 s3BucketName reverseRomeMap fVector = do
case temp_versionFileRemotePath reverseRomeMap fVector of
Just versionFileRemotePath -> do
(env, CachePrefix prefix, verbose) <- ask
let finalVersionFileRemotePath = prefix </> versionFileRemotePath
mapExceptT (withReaderT (const (env, verbose))) $ getArtifactFromS3
s3BucketName
finalVersionFileRemotePath
verboseDebugFileName
where verboseDebugFileName = takeFileName $ versionFileRemotePath
_ -> pure mempty


-- | Retrieves a bcsymbolmap from an S3 Cache
Expand Down
168 changes: 85 additions & 83 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ downloadArtifacts buildTypeConfig mS3BucketName mlCacheDir reverseRepositoryMap
CarthageConfig{} -> runReaderT
(downloadVersionFilesFromCaches s3BucketName
lCacheDir
gitRepoNamesAndVersions
reverseRepositoryMap
frameworkVectors
)
uploadDownloadEnv
PodBuilderConfig{} -> mempty -- PodBuilder does not have .version files, rather PodBuilder.plist files that are part of the .framework
Expand All @@ -496,25 +497,17 @@ downloadArtifacts buildTypeConfig mS3BucketName mlCacheDir reverseRepositoryMap
mapM_ (whenLeft sayFunc) errors
)
readerEnv
case buildTypeConfig of
CarthageConfig{} -> do
runReaderT
(do
errors <- mapM runExceptT $ getAndSaveVersionFilesFromLocalCache
lCacheDir
gitRepoNamesAndVersions
mapM_ (whenLeft sayFunc) errors
)
readerEnv
PodBuilderConfig{} -> liftIO mempty -- PodBuilder does not have .version files, rather PodBuilder.plist files that are part of the .framework
runReaderT
(do
errors <- mapM runExceptT $ getAndSaveVersionFilesFromLocalCache
lCacheDir
reverseRepositoryMap
frameworkVectors
mapM_ (whenLeft sayFunc) errors
)
readerEnv

(Nothing, Nothing) -> throwError bothCacheKeysMissingMessage
where

gitRepoNamesAndVersions :: [ProjectNameAndVersion]
gitRepoNamesAndVersions = repoNamesAndVersionForFrameworkVectors
reverseRepositoryMap
frameworkVectors



Expand Down Expand Up @@ -841,10 +834,11 @@ saveFrameworkAndArtifactsToLocalCache buildTypeConfig lCacheDir reverseRomeMap f
downloadVersionFilesFromCaches
:: S3.BucketName -- ^ The cache definition.
-> Maybe FilePath -- ^ Just the local cache path or Nothing
-> [ProjectNameAndVersion] -- ^ A list of `ProjectName`s and `Version`s information.
-> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s.
-> [FrameworkVector] -- ^ A list of `FrameworkVector` used to derive the name and path of the .version files.
-> ReaderT UploadDownloadCmdEnv IO ()
downloadVersionFilesFromCaches s3BucketName lDir =
mapM_ (downloadVersionFileFromCaches s3BucketName lDir)
downloadVersionFilesFromCaches s3BucketName lDir reverseRomeMap =
mapM_ (downloadVersionFileFromCaches s3BucketName lDir reverseRomeMap)



Expand All @@ -855,71 +849,79 @@ downloadVersionFilesFromCaches s3BucketName lDir =
downloadVersionFileFromCaches
:: S3.BucketName -- ^ The cache definition.
-> Maybe FilePath -- ^ Just the local cache path or Nothing
-> ProjectNameAndVersion -- ^ The `ProjectName` and `Version` information.
-> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s.
-> FrameworkVector -- ^ A `FrameworkVector` used to derive the name and path of the .version file.
-> ReaderT UploadDownloadCmdEnv IO ()
downloadVersionFileFromCaches s3BucketName (Just lCacheDir) projectNameAndVersion
= do
(env, cachePrefix@(CachePrefix prefix), SkipLocalCacheFlag skipLocalCache, _, verbose) <-
ask

when skipLocalCache $ downloadVersionFileFromCaches s3BucketName
Nothing
projectNameAndVersion
downloadVersionFileFromCaches s3BucketName (Just lCacheDir) reverseRomeMap fVector
=
case
( temp_versionFileLocalPath reverseRomeMap fVector
, temp_versionFileRemotePath reverseRomeMap fVector
)
of
(Just versionFileLocalPath, Just versionFileRemotePath) -> do
(env, cachePrefix@(CachePrefix prefix), SkipLocalCacheFlag skipLocalCache, _, verbose) <- ask

when skipLocalCache $ downloadVersionFileFromCaches s3BucketName
Nothing
reverseRomeMap
fVector

unless skipLocalCache $ do
eitherSuccess <- runReaderT
(runExceptT $ getAndSaveVersionFileFromLocalCache
lCacheDir
reverseRomeMap
fVector
)
(cachePrefix, verbose)
case eitherSuccess of
Right _ -> return ()
Left e -> liftIO $ do
let sayFunc :: MonadIO m => String -> m ()
sayFunc = if verbose then sayLnWithTime else sayLn
sayFunc e
runReaderT
(do
e2 <- runExceptT $ do
versionFileBinary <- getVersionFileFromS3
s3BucketName
reverseRomeMap
fVector
saveBinaryToLocalCache lCacheDir
versionFileBinary
(prefix </> versionFileRemotePath)
verboseDebugFileName
verbose
liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath
sayFunc
$ "Copied "
<> verboseDebugFileName
<> " to: "
<> versionFileLocalPath
whenLeft sayFunc e2
)
(env, cachePrefix, verbose)
where verboseDebugFileName = takeFileName $ versionFileRemotePath
_ -> pure mempty

unless skipLocalCache $ do
eitherSuccess <- runReaderT
(runExceptT $ getAndSaveVersionFileFromLocalCache
lCacheDir
projectNameAndVersion
downloadVersionFileFromCaches s3BucketName Nothing reverseRomeMap fVector = do
case temp_versionFileLocalPath reverseRomeMap fVector of
Just versionFileLocalPath -> do
(env, cachePrefix, _, _, verbose) <- ask
let sayFunc :: MonadIO m => String -> m ()
sayFunc = if verbose then sayLnWithTime else sayLn
eitherError <- liftIO $ runReaderT
(runExceptT $ do
versionFileBinary <- getVersionFileFromS3 s3BucketName reverseRomeMap fVector
liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath
sayFunc $ "Copied " <> verboseDebugFileName <> " to: " <> versionFileLocalPath
)
(cachePrefix, verbose)
case eitherSuccess of
Right _ -> return ()
Left e -> liftIO $ do
let sayFunc :: MonadIO m => String -> m ()
sayFunc = if verbose then sayLnWithTime else sayLn
sayFunc e
runReaderT
(do
e2 <- runExceptT $ do
versionFileBinary <- getVersionFileFromS3
s3BucketName
projectNameAndVersion
saveBinaryToLocalCache lCacheDir
versionFileBinary
(prefix </> versionFileRemotePath)
versionFileName
verbose
liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath
sayFunc
$ "Copied "
<> versionFileName
<> " to: "
<> versionFileLocalPath
whenLeft sayFunc e2
)
(env, cachePrefix, verbose)
where
versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion
versionFileLocalPath = carthageBuildDirectory </> versionFileName
versionFileRemotePath = remoteVersionFilePath projectNameAndVersion

downloadVersionFileFromCaches s3BucketName Nothing projectNameAndVersion = do
(env, cachePrefix, _, _, verbose) <- ask
let sayFunc :: MonadIO m => String -> m ()
sayFunc = if verbose then sayLnWithTime else sayLn
eitherError <- liftIO $ runReaderT
(runExceptT $ do
versionFileBinary <- getVersionFileFromS3 s3BucketName
projectNameAndVersion
liftIO $ saveBinaryToFile versionFileBinary versionFileLocalPath
sayFunc $ "Copied " <> versionFileName <> " to: " <> versionFileLocalPath
)
(env, cachePrefix, verbose)
whenLeft sayFunc eitherError
where
versionFileName = versionFileNameForProjectName $ fst projectNameAndVersion
versionFileLocalPath = carthageBuildDirectory </> versionFileName
(env, cachePrefix, verbose)
whenLeft sayFunc eitherError
where
verboseDebugFileName = takeFileName $ versionFileLocalPath
_ -> pure mempty



Expand Down

0 comments on commit e5216c4

Please sign in to comment.