Skip to content

Commit

Permalink
Don't unzip zero bytes archives (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmspzz authored Mar 4, 2019
1 parent 4b49099 commit 3a90d98
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 61 deletions.
7 changes: 4 additions & 3 deletions src/Caches/Local/Downloading.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,15 @@ getAndUnzipFrameworkFromLocalCache lCacheDir reverseRomeMap fVersion@(FrameworkV
<> " in local cache at: "
<> frameworkLocalCachePath prefix
deleteFrameworkDirectory fVersion platform verbose
unzipBinary binary fwn frameworkZipName verbose <* makeExecutable platform f
unzipBinary binary fwn frameworkZipName verbose
<* ifExists frameworkExecutablePath (makeExecutable frameworkExecutablePath)
where
frameworkLocalCachePath cPrefix =
lCacheDir </> cPrefix </> remoteFrameworkUploadPath
remoteFrameworkUploadPath =
remoteFrameworkPath platform reverseRomeMap f version
frameworkZipName = frameworkArchiveName f version

frameworkExecutablePath = frameworkBuildBundleForPlatform platform f </> fwn



Expand Down Expand Up @@ -355,7 +356,7 @@ getAndUnzipDSYMFromLocalCache lCacheDir reverseRomeMap fVersion@(FrameworkVersio
<> " in local cache at: "
<> finalDSYMLocalPath
deleteDSYMDirectory fVersion platform verbose
unzipBinary binary fwn dSYMZipName verbose <* makeExecutable platform f
unzipBinary binary fwn dSYMZipName verbose
where
dSYMLocalCachePath cPrefix = lCacheDir </> cPrefix </> remotedSYMUploadPath
remotedSYMUploadPath = remoteDsymPath platform reverseRomeMap f version
Expand Down
11 changes: 8 additions & 3 deletions src/Caches/S3/Downloading.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Data.Romefile (Framework (..))
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 Types hiding (version)
import Utils
Expand Down Expand Up @@ -61,7 +62,7 @@ getDSYMFromS3
String
(ReaderT (AWS.Env, CachePrefix, Bool) IO)
LBS.ByteString
getDSYMFromS3 s3BucketName reverseRomeMap (FrameworkVersion f@(Framework fwn fwt fwps) version) platform
getDSYMFromS3 s3BucketName reverseRomeMap (FrameworkVersion f@(Framework fwn fwt fwps) version) platform
= do
(env, CachePrefix prefix, verbose) <- ask
let finalRemoteDSYMUploadPath = prefix </> remoteDSYMUploadPath
Expand Down Expand Up @@ -136,8 +137,12 @@ getAndUnzipFrameworkFromS3 s3BucketName reverseRomeMap fVersion@(FrameworkVersio
platform
deleteFrameworkDirectory fVersion platform verbose
unzipBinary frameworkBinary fwn frameworkZipName verbose
<* makeExecutable platform f
where frameworkZipName = frameworkArchiveName f version
<* ifExists
frameworkExecutablePath
(makeExecutable frameworkExecutablePath)
where
frameworkZipName = frameworkArchiveName f version
frameworkExecutablePath = frameworkBuildBundleForPlatform platform f </> fwn



Expand Down
89 changes: 49 additions & 40 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ runUDCCommand command absoluteRomefilePath verbose romeVersion = do
concatMap (snd . romeFileEntryToTuple) filteredCurrentMapEntries
let currentFrameworkVersions =
map (flip FrameworkVersion currentVersion) currentFrameworks
let currentInvertedMap = toInvertedRepositoryMap filteredCurrentMapEntries
let currentInvertedMap =
toInvertedRepositoryMap filteredCurrentMapEntries

runReaderT
(listArtifacts
Expand Down Expand Up @@ -269,44 +270,46 @@ performWithDefaultFlow flowFunc (verbose, noIgnoreFlag, skipLocalCache, noSkipCu

if null gitRepoNames
then
let derivedFrameworkVersions =
deriveFrameworkNamesAndVersion repositoryMap cartfileEntries
cachePrefix = CachePrefix cachePrefixString
in do
let
derivedFrameworkVersions =
deriveFrameworkNamesAndVersion repositoryMap cartfileEntries
cachePrefix = CachePrefix cachePrefixString
in
do
runReaderT
(flowFunc
mS3BucketName
mlCacheDir
reverseRepositoryMap
(derivedFrameworkVersions
`filterOutFrameworksAndVersionsIfNotIn` finalIgnoreNames
)
platforms
)
(cachePrefix, skipLocalCache, verbose)
when (_noSkipCurrent noSkipCurrentFlag) $ do
currentVersion <- deriveCurrentVersion
let filteredCurrentMapEntries =
currentMapEntries
`filterRomeFileEntriesByPlatforms` ignoreMapEntries
let currentFrameworks = concatMap (snd . romeFileEntryToTuple)
filteredCurrentMapEntries
let currentFrameworkVersions = map
(flip FrameworkVersion currentVersion)
currentFrameworks
let currentInvertedMap =
toInvertedRepositoryMap filteredCurrentMapEntries
runReaderT
(flowFunc
mS3BucketName
mlCacheDir
reverseRepositoryMap
(derivedFrameworkVersions
currentInvertedMap
(currentFrameworkVersions
`filterOutFrameworksAndVersionsIfNotIn` finalIgnoreNames
)
platforms
)
(cachePrefix, skipLocalCache, verbose)
when (_noSkipCurrent noSkipCurrentFlag) $ do
currentVersion <- deriveCurrentVersion
let filteredCurrentMapEntries =
currentMapEntries
`filterRomeFileEntriesByPlatforms` ignoreMapEntries
let currentFrameworks =
concatMap (snd . romeFileEntryToTuple) filteredCurrentMapEntries
let currentFrameworkVersions = map
(flip FrameworkVersion currentVersion)
currentFrameworks
let currentInvertedMap =
toInvertedRepositoryMap filteredCurrentMapEntries
runReaderT
(flowFunc
mS3BucketName
mlCacheDir
currentInvertedMap
(currentFrameworkVersions
`filterOutFrameworksAndVersionsIfNotIn` finalIgnoreNames
)
platforms
)
(cachePrefix, skipLocalCache, verbose)
else do
currentVersion <- deriveCurrentVersion
let filteredCurrentMapEntries =
Expand All @@ -316,14 +319,16 @@ performWithDefaultFlow flowFunc (verbose, noIgnoreFlag, skipLocalCache, noSkipCu
concatMap (snd . romeFileEntryToTuple) filteredCurrentMapEntries
let currentFrameworkVersions =
map (flip FrameworkVersion currentVersion) currentFrameworks
let derivedFrameworkVersions = deriveFrameworkNamesAndVersion
repositoryMap
(filterCartfileEntriesByGitRepoNames gitRepoNames cartfileEntries)
frameworkVersions =
(derivedFrameworkVersions <> currentFrameworkVersions)
`filterOutFrameworksAndVersionsIfNotIn` finalIgnoreNames
cachePrefix = CachePrefix cachePrefixString
currentInvertedMap = toInvertedRepositoryMap filteredCurrentMapEntries
let
derivedFrameworkVersions = deriveFrameworkNamesAndVersion
repositoryMap
(filterCartfileEntriesByGitRepoNames gitRepoNames cartfileEntries)
frameworkVersions =
(derivedFrameworkVersions <> currentFrameworkVersions)
`filterOutFrameworksAndVersionsIfNotIn` finalIgnoreNames
cachePrefix = CachePrefix cachePrefixString
currentInvertedMap =
toInvertedRepositoryMap filteredCurrentMapEntries
runReaderT
(flowFunc mS3BucketName
mlCacheDir
Expand Down Expand Up @@ -946,7 +951,9 @@ downloadFrameworkAndArtifactsFromCaches s3BucketName (Just lCacheDir) reverseRom
verbose
deleteFrameworkDirectory fVersion platform verbose
unzipBinary frameworkBinary fwn frameworkZipName verbose
<* makeExecutable platform f
<* ifExists
frameworkExecutablePath
(makeExecutable frameworkExecutablePath)
whenLeft sayFunc e2
)
remoteReaderEnv
Expand Down Expand Up @@ -1034,7 +1041,9 @@ downloadFrameworkAndArtifactsFromCaches s3BucketName (Just lCacheDir) reverseRom
remotedSYMUploadPath = remoteDsymPath platform reverseRomeMap f version
platformBuildDirectory =
carthageArtifactsBuildDirectoryForPlatform platform f
dSYMName = fwn <> ".dSYM"
dSYMName = fwn <> ".dSYM"
frameworkExecutablePath = frameworkBuildBundleForPlatform platform f </> fwn



downloadFrameworkAndArtifactsFromCaches s3BucketName Nothing reverseRomeMap fVersion@(FrameworkVersion (Framework fwn fwt fwps) _) platform
Expand Down
39 changes: 24 additions & 15 deletions src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,15 @@ createZipArchive filePath verbose = do
-- | Adds executable permissions to a Framework. See https://github.com/blender/Rome/issues/57
makeExecutable
:: MonadIO m
=> TargetPlatform -- ^ The `TargetPlatform` to limit the operation to
-> Framework -- ^ The Framework
=> String -- ^ Path to the file
-> m Turtle.Permissions
makeExecutable p f = Turtle.chmod
Turtle.executable
(Turtle.fromString $ frameworkBuildBundleForPlatform p f </> _frameworkName f)

makeExecutable path = Turtle.chmod Turtle.executable $ Turtle.fromString path

-- | Perform an action on a file if it exists
ifExists :: MonadIO m => String -> m a -> m (Maybe a)
ifExists path fileAction = do
fileExists <- liftIO $ doesFileExist path
if fileExists then Just <$> fileAction else return Nothing

-- | Delete a directory an all it's contents
deleteDirectory
Expand Down Expand Up @@ -667,15 +668,23 @@ unzipBinary
-> m ()
unzipBinary objectBinary objectName objectZipName verbose = do
when verbose $ sayLnWithTime $ "Starting to unzip " <> objectZipName
liftIO $ Zip.extractFilesFromArchive
[Zip.OptRecursive, Zip.OptPreserveSymbolicLinks]
(Zip.toArchive objectBinary)
when verbose
$ sayLnWithTime
$ "Unzipped "
<> objectName
<> " from: "
<> objectZipName
if LBS.length objectBinary == 0
then
when verbose
$ sayLnWithTime
$ "Warning: "
<> objectZipName
<> " is ZERO bytes"
else do
liftIO $ Zip.extractFilesFromArchive
[Zip.OptRecursive, Zip.OptPreserveSymbolicLinks]
(Zip.toArchive objectBinary)
when verbose
$ sayLnWithTime
$ "Unzipped "
<> objectName
<> " from: "
<> objectZipName



Expand Down

0 comments on commit 3a90d98

Please sign in to comment.