use lowercase hash by default; non-bare repos are a special case

Directory special remotes will now always store keys in the lowercase name,
which avoids the complication of catching failures to create the mixed case
name.

Git remotes using http will now try the lowercase name first.
This commit is contained in:
Joey Hess 2011-12-02 14:56:48 -04:00
parent 0815cc2fc1
commit db5b479f3f
2 changed files with 14 additions and 18 deletions

View file

@ -21,7 +21,6 @@ module Locations (
gitAnnexJournalDir, gitAnnexJournalDir,
gitAnnexJournalLock, gitAnnexJournalLock,
isLinkToAnnex, isLinkToAnnex,
annexHashes,
hashDirMixed, hashDirMixed,
hashDirLower, hashDirLower,
@ -80,8 +79,7 @@ gitAnnexLocation key r
| Git.repoIsLocalBare r = | Git.repoIsLocalBare r =
{- Bare repositories default to hashDirLower for new {- Bare repositories default to hashDirLower for new
- content, as it's more portable. -} - content, as it's more portable. -}
go (Git.workTree r) $ go (Git.workTree r) (annexLocations key)
map (annexLocation key) [hashDirLower, hashDirMixed]
| otherwise = | otherwise =
{- Non-bare repositories only use hashDirMixed, so {- Non-bare repositories only use hashDirMixed, so
- don't need to do any work to check if the file is - don't need to do any work to check if the file is
@ -189,10 +187,10 @@ prop_idempotent_fileKey s = Just k == fileKey (keyFile k)
- came first, and is fine, except for the problem of case-strict - came first, and is fine, except for the problem of case-strict
- filesystems such as Linux VFAT (mounted with shortname=mixed), - filesystems such as Linux VFAT (mounted with shortname=mixed),
- which do not allow using a directory "XX" when "xx" already exists. - which do not allow using a directory "XX" when "xx" already exists.
- To support that, some repositories will use a lower case hash. -} - To support that, most repositories use the lower case hash for new data. -}
type Hasher = Key -> FilePath type Hasher = Key -> FilePath
annexHashes :: [Hasher] annexHashes :: [Hasher]
annexHashes = [hashDirMixed, hashDirLower] annexHashes = [hashDirLower, hashDirMixed]
hashDirMixed :: Hasher hashDirMixed :: Hasher
hashDirMixed k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir hashDirMixed k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir

View file

@ -64,7 +64,7 @@ directorySetup u c = do
{- Locations to try to access a given Key in the Directory. -} {- Locations to try to access a given Key in the Directory. -}
locations :: FilePath -> Key -> [FilePath] locations :: FilePath -> Key -> [FilePath]
locations d k = map (d </>) (keyLocations k) locations d k = map (d </>) (keyPaths k)
withCheckedFile :: (FilePath -> IO Bool) -> FilePath -> Key -> (FilePath -> IO Bool) -> IO Bool withCheckedFile :: (FilePath -> IO Bool) -> FilePath -> Key -> (FilePath -> IO Bool) -> IO Bool
withCheckedFile _ [] _ _ = return False withCheckedFile _ [] _ _ = return False
@ -95,18 +95,16 @@ storeEncrypted d (cipher, enck) k = do
return True return True
storeHelper :: FilePath -> Key -> (FilePath -> IO Bool) -> IO Bool storeHelper :: FilePath -> Key -> (FilePath -> IO Bool) -> IO Bool
storeHelper d key a = withCheckedFile check d key go storeHelper d key a = do
where let dest = head $ locations d key
check dest = isJust <$> mkdir (parentDir dest) let dir = parentDir dest
mkdir = catchMaybeIO . createDirectoryIfMissing True createDirectoryIfMissing True dir
go dest = do allowWrite dir
let dir = parentDir dest ok <- a dest
allowWrite dir when ok $ do
ok <- a dest preventWrite dest
when ok $ do preventWrite dir
preventWrite dest return ok
preventWrite dir
return ok
retrieve :: FilePath -> Key -> FilePath -> Annex Bool retrieve :: FilePath -> Key -> FilePath -> Annex Bool
retrieve d k f = liftIO $ withStoredFile d k $ \file -> copyFileExternal file f retrieve d k f = liftIO $ withStoredFile d k $ \file -> copyFileExternal file f