From 3a90d9817390504dd73d6668c7ef16e75f8e9a09 Mon Sep 17 00:00:00 2001 From: Tommaso Piazza Date: Mon, 4 Mar 2019 07:07:45 +0100 Subject: [PATCH] Don't unzip zero bytes archives (#170) --- src/Caches/Local/Downloading.hs | 7 +-- src/Caches/S3/Downloading.hs | 11 ++-- src/Lib.hs | 89 ++++++++++++++++++--------------- src/Utils.hs | 39 +++++++++------ 4 files changed, 85 insertions(+), 61 deletions(-) diff --git a/src/Caches/Local/Downloading.hs b/src/Caches/Local/Downloading.hs index 5ff7257..fa0714a 100644 --- a/src/Caches/Local/Downloading.hs +++ b/src/Caches/Local/Downloading.hs @@ -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 @@ -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 diff --git a/src/Caches/S3/Downloading.hs b/src/Caches/S3/Downloading.hs index f59daea..9cd5c49 100644 --- a/src/Caches/S3/Downloading.hs +++ b/src/Caches/S3/Downloading.hs @@ -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 @@ -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 @@ -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 diff --git a/src/Lib.hs b/src/Lib.hs index a6c27b1..2340e5d 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -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 @@ -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 = @@ -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 @@ -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 @@ -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 diff --git a/src/Utils.hs b/src/Utils.hs index 8e4e2f1..6d61697 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -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 @@ -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