convert rsync special backend to using both hash directory types

This commit is contained in:
Joey Hess 2011-12-02 15:50:27 -04:00
parent db5b479f3f
commit fb68a7881f
3 changed files with 45 additions and 29 deletions

View file

@ -21,6 +21,7 @@ module Locations (
gitAnnexJournalDir, gitAnnexJournalDir,
gitAnnexJournalLock, gitAnnexJournalLock,
isLinkToAnnex, isLinkToAnnex,
annexHashes,
hashDirMixed, hashDirMixed,
hashDirLower, hashDirLower,

View file

@ -86,13 +86,26 @@ rsyncEscape o s
| rsyncUrlIsShell (rsyncUrl o) = shellEscape s | rsyncUrlIsShell (rsyncUrl o) = shellEscape s
| otherwise = s | otherwise = s
rsyncKey :: RsyncOpts -> Key -> String rsyncUrls :: RsyncOpts -> Key -> [String]
rsyncKey o k = rsyncUrl o </> hashDirMixed k </> rsyncEscape o (f </> f) rsyncUrls o k = map use annexHashes
where where
use h = rsyncUrl o </> h k </> rsyncEscape o (f </> f)
f = keyFile k f = keyFile k
rsyncKeyDir :: RsyncOpts -> Key -> String rsyncUrlDirs :: RsyncOpts -> Key -> [String]
rsyncKeyDir o k = rsyncUrl o </> hashDirMixed k </> rsyncEscape o (keyFile k) rsyncUrlDirs o k = map use annexHashes
where
use h = rsyncUrl o </> h k </> rsyncEscape o (keyFile k)
withRsyncUrl :: RsyncOpts -> Key -> (FilePath -> Annex Bool) -> Annex Bool
withRsyncUrl o k a = go $ rsyncUrls o k
where
go [] = return False
go (u:us) = do
ok <- a u
if ok
then return ok
else go us
store :: RsyncOpts -> Key -> Annex Bool store :: RsyncOpts -> Key -> Annex Bool
store o k = rsyncSend o k =<< inRepo (gitAnnexLocation k) store o k = rsyncSend o k =<< inRepo (gitAnnexLocation k)
@ -104,10 +117,10 @@ storeEncrypted o (cipher, enck) k = withTmp enck $ \tmp -> do
rsyncSend o enck tmp rsyncSend o enck tmp
retrieve :: RsyncOpts -> Key -> FilePath -> Annex Bool retrieve :: RsyncOpts -> Key -> FilePath -> Annex Bool
retrieve o k f = rsyncRemote o retrieve o k f = withRsyncUrl o k $ \u -> rsyncRemote o
-- use inplace when retrieving to support resuming -- use inplace when retrieving to support resuming
[ Param "--inplace" [ Param "--inplace"
, Param $ rsyncKey o k , Param u
, Param f , Param f
] ]
@ -121,27 +134,30 @@ retrieveEncrypted o (cipher, enck) f = withTmp enck $ \tmp -> do
else return res else return res
remove :: RsyncOpts -> Key -> Annex Bool remove :: RsyncOpts -> Key -> Annex Bool
remove o k = withRsyncScratchDir $ \tmp -> do remove o k = any (== True) <$> sequence (map go (rsyncUrlDirs o k))
{- Send an empty directory to rysnc as the parent directory where
- of the file to remove. -} go d = withRsyncScratchDir $ \tmp -> liftIO $ do
{- Send an empty directory to rysnc as the
- parent directory of the file to remove. -}
let dummy = tmp </> keyFile k let dummy = tmp </> keyFile k
liftIO $ createDirectoryIfMissing True dummy createDirectoryIfMissing True dummy
liftIO $ rsync $ rsyncOptions o ++ rsync $ rsyncOptions o ++
[ Params "--delete --recursive" [ Params "--quiet --delete --recursive"
, partialParams , partialParams
, Param $ addTrailingPathSeparator dummy , Param $ addTrailingPathSeparator dummy
, Param $ rsyncKeyDir o k , Param d
] ]
checkPresent :: Git.Repo -> RsyncOpts -> Key -> Annex (Either String Bool) checkPresent :: Git.Repo -> RsyncOpts -> Key -> Annex (Either String Bool)
checkPresent r o k = do checkPresent r o k = do
showAction $ "checking " ++ Git.repoDescribe r showAction $ "checking " ++ Git.repoDescribe r
-- note: Does not currently differnetiate between rsync failing -- note: Does not currently differentiate between rsync failing
-- to connect, and the file not being present. -- to connect, and the file not being present.
res <- liftIO $ boolSystem "sh" [Param "-c", Param cmd] Right <$> check
return $ Right res
where where
cmd = "rsync --quiet " ++ shellEscape (rsyncKey o k) ++ " 2>/dev/null" check = withRsyncUrl o k $ \u ->
liftIO $ boolSystem "sh" [Param "-c", Param (cmd u)]
cmd u = "rsync --quiet " ++ shellEscape u ++ " 2>/dev/null"
{- Rsync params to enable resumes of sending files safely, {- Rsync params to enable resumes of sending files safely,
- ensure that files are only moved into place once complete - ensure that files are only moved into place once complete
@ -182,7 +198,7 @@ rsyncRemote o params = do
directories. -} directories. -}
rsyncSend :: RsyncOpts -> Key -> FilePath -> Annex Bool rsyncSend :: RsyncOpts -> Key -> FilePath -> Annex Bool
rsyncSend o k src = withRsyncScratchDir $ \tmp -> do rsyncSend o k src = withRsyncScratchDir $ \tmp -> do
let dest = tmp </> hashDirMixed k </> f </> f let dest = tmp </> head (keyPaths k)
liftIO $ createDirectoryIfMissing True $ parentDir dest liftIO $ createDirectoryIfMissing True $ parentDir dest
liftIO $ createLink src dest liftIO $ createLink src dest
rsyncRemote o rsyncRemote o
@ -192,5 +208,3 @@ rsyncSend o k src = withRsyncScratchDir $ \tmp -> do
, Param $ addTrailingPathSeparator tmp , Param $ addTrailingPathSeparator tmp
, Param $ rsyncUrl o , Param $ rsyncUrl o
] ]
where
f = keyFile k

9
debian/changelog vendored
View file

@ -2,10 +2,11 @@ git-annex (3.20111123) UNRELEASED; urgency=low
* The VFAT filesystem on recent versions of Linux, when mounted with * The VFAT filesystem on recent versions of Linux, when mounted with
shortname=mixed, does not get along well with git-annex's mixed case shortname=mixed, does not get along well with git-annex's mixed case
.git/annex/objects hash directories. To avoid this problem, bare .git/annex/objects hash directories. To avoid this problem, new content
repositories (and the directory special remote) now store new content is now stored in all-lowercase hash directories. Except for non-bare
in all-lowercase hash directories. Mixed case hash directories are repositories which would be a pain to transition and cannot be put on FAT.
still used for non-bare repositories, which cannot be put on FAT. (Old mixed-case hash directories are still tried for backwards
compatibility.)
* Flush json output, avoiding a buffering problem that could result in * Flush json output, avoiding a buffering problem that could result in
doubled output. doubled output.
* Avoid needing haskell98 and other fixes for new ghc. Thanks, Mark Wright. * Avoid needing haskell98 and other fixes for new ghc. Thanks, Mark Wright.