{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
module Pantry.Storage
( SqlBackend
, initStorage
, withStorage
, migrateAll
, storeBlob
, loadBlob
, loadBlobById
, loadBlobBySHA
, allBlobsSource
, allHackageCabalRawPackageLocations
, allBlobsCount
, allHackageCabalCount
, getBlobKey
, loadURLBlob
, storeURLBlob
, clearHackageRevisions
, storeHackageRevision
, loadHackagePackageVersions
, loadHackagePackageVersion
, loadLatestCacheUpdate
, storeCacheUpdate
, storeHackageTarballInfo
, loadHackageTarballInfo
, getHPackBlobKeyById
, storeTree
, loadTree
, storeHPack
, loadPackageById
, getPackageNameById
, getPackageNameId
, getVersionId
, getTreeForKey
, storeHackageTree
, loadHackageTree
, loadHackageTreeKey
, storeArchiveCache
, loadArchiveCache
, storeRepoCache
, loadRepoCache
, storePreferredVersion
, loadPreferredVersion
, sinkHackagePackageNames
, loadCabalBlobKey
, hpackToCabal
, countHackageCabals
, getSnapshotCacheByHash
, getSnapshotCacheId
, storeSnapshotModuleCache
, loadExposedModulePackages
, findOrGenerateCabalFile
, PackageNameId
, PackageName
, VersionId
, ModuleNameId
, Version
, versionVersion
, Unique(..)
, EntityField(..)
, BlobId
, Key(unBlobKey)
, HackageCabalId
, HackageCabal(..)
, HackageTarballId
, CacheUpdateId
, FilePathId
, Tree(..)
, TreeId
, TreeEntry(..)
, TreeEntryId
, ArchiveCacheId
, RepoCacheId
, PreferredVersionsId
, UrlBlobId
, SnapshotCacheId
, PackageExposedModuleId
, loadCachedTree
, CachedTree (..)
, unCachedTree
) where
import Conduit ( ConduitT, (.|), concatMapMC, mapC, runConduit )
import Data.Acquire ( with )
import Database.Persist ( ( !=.), (=.), (==.), (>.) )
import Database.Persist.Class.PersistEntity
( Entity (..), EntityField, Filter (..), Key, SelectOpt (..)
, Unique
)
import Database.Persist.Class.PersistField ( PersistField (..) )
import Database.Persist.Class.PersistQuery
( count, deleteWhere, selectFirst, selectKeysList, selectList
, selectSource, selectSourceRes, updateWhere
)
import Database.Persist.Class.PersistStore
( get, getJust, insert, insert_, update, )
import Database.Persist.Class.PersistUnique ( getBy, insertBy )
import Database.Persist.Sql ( Single (..), rawExecute, rawSql )
import Database.Persist.SqlBackend ( SqlBackend )
import Database.Persist.TH
( mkMigrate, mkPersist, persistLowerCase, share, sqlSettings
)
import Pantry.HPack ( hpack, hpackVersion )
import qualified Pantry.SHA256 as SHA256
import qualified Pantry.SQLite as SQLite
import Pantry.Types
( BlobKey, FileSize (..), FileType (..), HasPantryConfig
, Package (..), PackageNameP (..), Repo (..), Revision (..)
, SHA256, SafeFilePath, SnapshotCacheHash (..), TreeKey
, VersionP (..), connRDBMS
)
import qualified Pantry.Types as P
import Path
( Abs, Dir, File, Path, filename, fromAbsFile, fromRelFile
, parseAbsDir, toFilePath
)
import Path.IO ( createTempDir, getTempDir, listDir, removeDirRecur )
import RIO hiding ( FilePath )
import qualified RIO.ByteString as B
import RIO.Directory
( createDirectoryIfMissing, getPermissions
, setOwnerExecutable, setPermissions
)
import RIO.FilePath ( (</>), takeDirectory )
import qualified RIO.FilePath as FilePath
import qualified RIO.List as List
import qualified RIO.Map as Map
import RIO.Orphans ( HasResourceMap )
import RIO.Process ( HasProcessContext )
import qualified RIO.Text as T
import RIO.Time ( UTCTime, getCurrentTime )