@@ -21,6 +21,7 @@ installation and introspection of files/versions etc.
21
21
-}
22
22
module GHCup.Utils
23
23
( module GHCup.Utils.Dirs
24
+ , module GHCup.Utils.Tar
24
25
, module GHCup.Utils
25
26
#if defined(IS_WINDOWS)
26
27
, module GHCup.Prelude.Windows
@@ -42,14 +43,14 @@ import GHCup.Types
42
43
import GHCup.Types.Optics
43
44
import GHCup.Types.JSON ( )
44
45
import GHCup.Utils.Dirs
46
+ import GHCup.Utils.Tar
45
47
import GHCup.Version
46
48
import GHCup.Prelude
47
49
import GHCup.Prelude.File
48
50
import GHCup.Prelude.Logger.Internal
49
51
import GHCup.Prelude.MegaParsec
50
52
import GHCup.Prelude.Process
51
53
import GHCup.Prelude.String.QQ
52
- import Codec.Archive hiding ( Directory )
53
54
import Control.Applicative
54
55
import Control.Exception.Safe
55
56
import Control.Monad
@@ -79,10 +80,6 @@ import Text.Regex.Posix
79
80
import Text.PrettyPrint.HughesPJClass (prettyShow )
80
81
import URI.ByteString
81
82
82
- import qualified Codec.Compression.BZip as BZip
83
- import qualified Codec.Compression.GZip as GZip
84
- import qualified Codec.Compression.Lzma as Lzma
85
- import qualified Data.ByteString.Lazy as BL
86
83
import qualified Data.Map.Strict as Map
87
84
import qualified Data.Text as T
88
85
import qualified Data.Text.Encoding as E
@@ -783,99 +780,6 @@ getLatestToolFor tool target pvpIn dls = do
783
780
784
781
785
782
786
-
787
-
788
- -----------------
789
- -- [ Unpacking ]--
790
- -----------------
791
-
792
-
793
-
794
- -- | Unpack an archive to a temporary directory and return that path.
795
- unpackToDir :: (MonadReader env m , HasLog env , MonadIO m , MonadThrow m )
796
- => FilePath -- ^ destination dir
797
- -> FilePath -- ^ archive path
798
- -> Excepts '[UnknownArchive
799
- , ArchiveResult
800
- ] m ()
801
- unpackToDir dfp av = do
802
- let fn = takeFileName av
803
- lift $ logInfo $ " Unpacking: " <> T. pack fn <> " to " <> T. pack dfp
804
-
805
- let untar :: MonadIO m => BL. ByteString -> Excepts '[ArchiveResult ] m ()
806
- untar = lEM . liftIO . runArchiveM . unpackToDirLazy dfp
807
-
808
- rf :: MonadIO m => FilePath -> Excepts '[ArchiveResult ] m BL. ByteString
809
- rf = liftIO . BL. readFile
810
-
811
- -- extract, depending on file extension
812
- if
813
- | " .tar.gz" `isSuffixOf` fn -> liftE
814
- (untar . GZip. decompress =<< rf av)
815
- | " .tar.xz" `isSuffixOf` fn -> do
816
- filecontents <- liftE $ rf av
817
- let decompressed = Lzma. decompressWith (Lzma. defaultDecompressParams { Lzma. decompressAutoDecoder= True }) filecontents
818
- liftE $ untar decompressed
819
- | " .tar.bz2" `isSuffixOf` fn ->
820
- liftE (untar . BZip. decompress =<< rf av)
821
- | " .tar" `isSuffixOf` fn -> liftE (untar =<< rf av)
822
- | " .zip" `isSuffixOf` fn -> liftE (untar =<< rf av)
823
- | otherwise -> throwE $ UnknownArchive fn
824
-
825
-
826
- getArchiveFiles :: (MonadReader env m , HasLog env , MonadIO m , MonadThrow m )
827
- => FilePath -- ^ archive path
828
- -> Excepts '[UnknownArchive
829
- , ArchiveResult
830
- ] m [FilePath ]
831
- getArchiveFiles av = do
832
- let fn = takeFileName av
833
-
834
- let entries :: Monad m => BL. ByteString -> Excepts '[ArchiveResult ] m [FilePath ]
835
- entries = (fmap . fmap ) filepath . lE . readArchiveBSL
836
-
837
- rf :: MonadIO m => FilePath -> Excepts '[ArchiveResult ] m BL. ByteString
838
- rf = liftIO . BL. readFile
839
-
840
- -- extract, depending on file extension
841
- if
842
- | " .tar.gz" `isSuffixOf` fn -> liftE
843
- (entries . GZip. decompress =<< rf av)
844
- | " .tar.xz" `isSuffixOf` fn -> do
845
- filecontents <- liftE $ rf av
846
- let decompressed = Lzma. decompressWith (Lzma. defaultDecompressParams { Lzma. decompressAutoDecoder= True }) filecontents
847
- liftE $ entries decompressed
848
- | " .tar.bz2" `isSuffixOf` fn ->
849
- liftE (entries . BZip. decompress =<< rf av)
850
- | " .tar" `isSuffixOf` fn -> liftE (entries =<< rf av)
851
- | " .zip" `isSuffixOf` fn -> liftE (entries =<< rf av)
852
- | otherwise -> throwE $ UnknownArchive fn
853
-
854
-
855
- intoSubdir :: (MonadReader env m , HasLog env , MonadIO m , MonadThrow m , MonadCatch m )
856
- => GHCupPath -- ^ unpacked tar dir
857
- -> TarDir -- ^ how to descend
858
- -> Excepts '[TarDirDoesNotExist ] m GHCupPath
859
- intoSubdir bdir tardir = case tardir of
860
- RealDir pr -> do
861
- whenM (fmap not . liftIO . doesDirectoryExist $ fromGHCupPath (bdir `appendGHCupPath` pr))
862
- (throwE $ TarDirDoesNotExist tardir)
863
- pure (bdir `appendGHCupPath` pr)
864
- RegexDir r -> do
865
- let rs = split (`elem` pathSeparators) r
866
- foldlM
867
- (\ y x ->
868
- (handleIO (\ _ -> pure [] ) . liftIO . findFiles (fromGHCupPath y) . regex $ x) >>= (\ case
869
- [] -> throwE $ TarDirDoesNotExist tardir
870
- (p : _) -> pure (y `appendGHCupPath` p)) . sort
871
- )
872
- bdir
873
- rs
874
- where regex = makeRegexOpts compIgnoreCase execBlank
875
-
876
-
877
-
878
-
879
783
------------
880
784
-- [ Tags ]--
881
785
------------
@@ -929,6 +833,28 @@ getLatestBaseVersion av pvpVer =
929
833
-- [ Other ]--
930
834
-------------
931
835
836
+
837
+ intoSubdir :: (MonadReader env m , HasLog env , MonadIO m , MonadThrow m , MonadCatch m )
838
+ => GHCupPath -- ^ unpacked tar dir
839
+ -> TarDir -- ^ how to descend
840
+ -> Excepts '[TarDirDoesNotExist ] m GHCupPath
841
+ intoSubdir bdir tardir = case tardir of
842
+ RealDir pr -> do
843
+ whenM (fmap not . liftIO . doesDirectoryExist $ fromGHCupPath (bdir `appendGHCupPath` pr))
844
+ (throwE $ TarDirDoesNotExist tardir)
845
+ pure (bdir `appendGHCupPath` pr)
846
+ RegexDir r -> do
847
+ let rs = split (`elem` pathSeparators) r
848
+ foldlM
849
+ (\ y x ->
850
+ (handleIO (\ _ -> pure [] ) . liftIO . findFiles (fromGHCupPath y) . regex $ x) >>= (\ case
851
+ [] -> throwE $ TarDirDoesNotExist tardir
852
+ (p : _) -> pure (y `appendGHCupPath` p)) . sort
853
+ )
854
+ bdir
855
+ rs
856
+ where regex = makeRegexOpts compIgnoreCase execBlank
857
+
932
858
-- | Usually @~\/.ghcup\/ghc\/\<ver\>\/bin\/@
933
859
ghcInternalBinDir :: (MonadReader env m , HasDirs env , MonadThrow m , MonadFail m , MonadIO m )
934
860
=> GHCTargetVersion
0 commit comments