Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Put the cache file in subdir .hackport

  • Loading branch information...
commit 36ee45237de043e30ad8aeb10fb35eff5eaed567 1 parent 98948bb
@kolmodin kolmodin authored
Showing with 23 additions and 8 deletions.
  1. +2 −1  Bash.hs
  2. +9 −7 Cache.hs
  3. +12 −0 CacheFile.hs
View
3  Bash.hs
@@ -9,6 +9,7 @@ import System.Exit
import Action
import Error
+import CacheFile
getOverlay :: HPAction String
getOverlay = do
@@ -22,7 +23,7 @@ getOverlay = do
search mul = do
let loop [] = throwError $ MultipleOverlays mul
loop (x:xs) = (do
- found <- liftIO (doesFileExist (x ++ "/00-index.tar.gz"))
+ found <- liftIO (doesFileExist (cacheFile x))
`sayDebug` ("Checking '"++x++"'...\n",\res->if res then "found.\n" else "not found.")
if found
then return x
View
16 Cache.hs
@@ -2,6 +2,7 @@ module Cache where
import Action
import Portage
+import CacheFile
import Config
import Error
import Index
@@ -14,7 +15,7 @@ import System.FilePath
import Control.Monad.Error(throwError)
import Control.Monad.Trans(liftIO)
import Control.Monad (unless)
-import System.Directory (doesFileExist)
+import System.Directory (doesFileExist,createDirectoryIfMissing)
-- | A long time. Used in checkCacheDate
alarmingLongTime :: TimeDiff
@@ -29,23 +30,24 @@ alarmingLongTime = TimeDiff
}
cacheURI :: URI -> URI
-cacheURI uri = uri {uriPath = uriPath uri </> "00-index.tar.gz"}
+cacheURI uri = uri {uriPath = uriPath uri </> indexFile}
updateCache :: HPAction ()
updateCache = do
tree <- getPortageTree
- let cacheFile = tree </> "00-index.tar.gz"
cfg <- getCfg
let cache = cacheURI $ server cfg
res <- (liftIO $ simpleHTTP (Request cache GET [] "")) `sayNormal` ("Fetching cache from "++show cache++"...",const "done.")
case res of
Left err -> throwError (ConnectionFailed (show cache) (show err))
- Right resp -> liftIO $ Prelude.writeFile cacheFile (rspBody resp)
+ Right resp -> liftIO $ do
+ createDirectoryIfMissing False (tree </> hackportDir)
+ Prelude.writeFile (cacheFile tree) (rspBody resp)
readCache :: FilePath -> HPAction Index
readCache portdir = do
- let cacheFile = portdir </> "00-index.tar.gz"
- exists <- liftIO $ doesFileExist cacheFile
+ let cachePath = cacheFile portdir
+ exists <- liftIO $ doesFileExist cachePath
unless exists $ throwError NoCache
- str <- liftIO $ BS.readFile cacheFile
+ str <- liftIO $ BS.readFile cachePath
return $ readIndex str
View
12 CacheFile.hs
@@ -0,0 +1,12 @@
+module CacheFile where
+
+import System.FilePath
+
+indexFile :: String
+indexFile = "00-index.tar.gz"
+
+hackportDir :: String
+hackportDir = ".hackport"
+
+cacheFile :: FilePath -> FilePath
+cacheFile tree = tree </> hackportDir </> indexFile
Please sign in to comment.
Something went wrong with that request. Please try again.