darcs-2.16.5: a distributed, interactive, smart revision control system

Safe Haskell | Safe-Inferred
Language | Haskell2010

Darcs.Repository.Cache

Synopsis

- cacheHash :: ByteString -> String
- okayHash :: String -> Bool
- data Cache
- mkCache :: [CacheLoc] -> Cache
- cacheEntries :: Cache -> [CacheLoc]
- data CacheType
  - = Repo
  - | Directory
- data CacheLoc = Cache {
  - cacheType :: !CacheType
  - cacheWritable :: !WritableOrNot
  - cacheSource :: !String
  }
- data WritableOrNot
  - = Writable
  - | NotWritable
- data HashedDir
  - = HashedPristineDir
  - | HashedPatchesDir
  - | HashedInventoriesDir
- hashedDir :: HashedDir -> String
- bucketFolder :: String -> String
- unionCaches :: Cache -> Cache -> Cache
- unionRemoteCaches :: Cache -> Cache -> String -> IO Cache
- cleanCaches :: Cache -> HashedDir -> IO ()
- cleanCachesWithHint :: Cache -> HashedDir -> [String] -> IO ()
- fetchFileUsingCache :: Cache -> HashedDir -> String -> IO (String, ByteString)
- speculateFileUsingCache :: Cache -> HashedDir -> String -> IO ()
- speculateFilesUsingCache :: Cache -> HashedDir -> [String] -> IO ()
- writeFileUsingCache :: Cache -> Compression -> HashedDir -> ByteString -> IO String
- peekInCache :: Cache -> HashedDir -> String -> IO Bool
- repo2cache :: String -> Cache
- writable :: CacheLoc -> Bool
- isThisRepo :: CacheLoc -> Bool
- hashedFilePath :: CacheLoc -> HashedDir -> String -> String
- allHashedDirs :: [HashedDir]
- reportBadSources :: IO ()
- closestWritableDirectory :: Cache -> Maybe String
- dropNonRepos :: Cache -> Cache

# Documentation

cacheHash :: ByteString -> String #

`cacheHash` computes the cache hash (i.e. filename) of a packed string.

okayHash :: String -> Bool #

data Cache #

Cache is an abstract type for hiding the underlying cache locations

#### Instances

Instances details

Show Cache # |
Instance details Defined in Darcs.Repository.Cache Methods showsPrec :: Int -> Cache -> ShowS # show :: Cache -> String # showList :: [Cache] -> ShowS #

mkCache :: [CacheLoc] -> Cache #

cacheEntries :: Cache -> [CacheLoc] #

data CacheType #

Constructors

Repo |
Directory |

#### Instances

Instances details

Show CacheType # |
Instance details Defined in Darcs.Repository.Cache Methods showsPrec :: Int -> CacheType -> ShowS # show :: CacheType -> String # showList :: [CacheType] -> ShowS #
Eq CacheType # |
Instance details Defined in Darcs.Repository.Cache Methods (==) :: CacheType -> CacheType -> Bool # (/=) :: CacheType -> CacheType -> Bool #

data CacheLoc #

Constructors

Cache |
Fields cacheType :: !CacheType cacheWritable :: !WritableOrNot cacheSource :: !String

#### Instances

Instances details

Show CacheLoc # |
Instance details Defined in Darcs.Repository.Cache Methods showsPrec :: Int -> CacheLoc -> ShowS # show :: CacheLoc -> String # showList :: [CacheLoc] -> ShowS #
Eq CacheLoc # |
Instance details Defined in Darcs.Repository.Cache Methods (==) :: CacheLoc -> CacheLoc -> Bool # (/=) :: CacheLoc -> CacheLoc -> Bool #

data WritableOrNot #

Constructors

Writable |
NotWritable |

#### Instances

Instances details

Show WritableOrNot # |
Instance details Defined in Darcs.Repository.Cache Methods showsPrec :: Int -> WritableOrNot -> ShowS # show :: WritableOrNot -> String # showList :: [WritableOrNot] -> ShowS #
Eq WritableOrNot # |
Instance details Defined in Darcs.Repository.Cache Methods (==) :: WritableOrNot -> WritableOrNot -> Bool # (/=) :: WritableOrNot -> WritableOrNot -> Bool #

data HashedDir #

Constructors

HashedPristineDir |
HashedPatchesDir |
HashedInventoriesDir |

hashedDir :: HashedDir -> String #

bucketFolder :: String -> String #

unionCaches :: Cache -> Cache -> Cache #

unionRemoteCaches :: Cache -> Cache -> String -> IO Cache #

unionRemoteCaches merges caches. It tries to do better than just blindly copying remote cache entries:

- If remote repository is accessed through network, do not copy any cache entries from it. Taking local entries does not make sense and using network entries can lead to darcs hang when it tries to get to unaccessible host.
- If remote repository is local, copy all network cache entries. For local cache entries if the cache directory exists and is writable it is added as writable cache, if it exists but is not writable it is added as read-only cache.

This approach should save us from bogus cache entries. One case it does not work very well is when you fetch from partial repository over network. Hopefully this is not a common case.

cleanCaches :: Cache -> HashedDir -> IO () #

cleanCachesWithHint :: Cache -> HashedDir -> [String] -> IO () #

fetchFileUsingCache :: Cache -> HashedDir -> String -> IO (String, ByteString) #

`fetchFileUsingCache cache dir hash` receives a list of caches `cache`, the directory for which that file belongs `dir` and the `hash` of the file to fetch. It tries to fetch the file from one of the sources, trying them in order one by one. If the file cannot be fetched from any of the sources, this operation fails.

speculateFileUsingCache :: Cache -> HashedDir -> String -> IO () #

`speculateFileUsingCache cache subdirectory name` takes note that the file `name` is likely to be useful soon: pipelined downloads will add it to the (low-priority) queue, for the rest it is a noop.

speculateFilesUsingCache :: Cache -> HashedDir -> [String] -> IO () #

Note that the files are likely to be useful soon: pipelined downloads will add them to the (low-priority) queue, for the rest it is a noop.

writeFileUsingCache :: Cache -> Compression -> HashedDir -> ByteString -> IO String #

`writeFileUsingCache cache compression subdir contents` write the string `contents` to the directory subdir, except if it is already in the cache, in which case it is a noop. Warning (?) this means that in case of a hash collision, writing using writeFileUsingCache is a noop. The returned value is the filename that was given to the string.

peekInCache :: Cache -> HashedDir -> String -> IO Bool #

`peekInCache cache subdir hash` tells whether `cache` and contains an object with hash `hash` in a writable position. Florent: why do we want it to be in a writable position?

repo2cache :: String -> Cache #

writable :: CacheLoc -> Bool #

isThisRepo :: CacheLoc -> Bool #

hashedFilePath :: CacheLoc -> HashedDir -> String -> String #

`hashedFilePath cachelocation subdir hash` returns the physical filename of hash `hash` in the `subdir` section of `cachelocation`.

allHashedDirs :: [HashedDir] #

reportBadSources :: IO () #

Prints an error message with a list of bad caches.

closestWritableDirectory :: Cache -> Maybe String #

dropNonRepos :: Cache -> Cache #

This keeps only `Repo` `NotWritable` entries.