switch to using main ingest code

Fixes at least one bug, in populating existing worktree files that use the
same key that's ingested.
This commit is contained in:
Joey Hess 2016-01-01 14:16:40 -04:00
parent 4eab4bdb01
commit 43b1333216
Failed to extract signature

View file

@ -11,13 +11,8 @@ import Common.Annex
import Command import Command
import Annex.Content import Annex.Content
import Annex.Link import Annex.Link
import Annex.MetaData
import Annex.FileMatcher import Annex.FileMatcher
import Annex.InodeSentinal
import Annex.Ingest import Annex.Ingest
import Utility.InodeCache
import Types.KeySource
import Backend
import Logs.Location import Logs.Location
import qualified Database.Keys import qualified Database.Keys
@ -75,41 +70,21 @@ clean file = do
if isJust (parseLinkOrPointer b) if isJust (parseLinkOrPointer b)
then liftIO $ B.hPut stdout b then liftIO $ B.hPut stdout b
else ifM (shouldAnnex file) else ifM (shouldAnnex file)
( liftIO . emitPointer =<< ingestLocal file ( liftIO . emitPointer
=<< go =<< ingest =<< lockDown False file
, liftIO $ B.hPut stdout b , liftIO $ B.hPut stdout b
) )
stop stop
where
go (Just k, _) = do
logStatus k InfoPresent
return k
go _ = error "could not add file to the annex"
shouldAnnex :: FilePath -> Annex Bool shouldAnnex :: FilePath -> Annex Bool
shouldAnnex file = do shouldAnnex file = do
matcher <- largeFilesMatcher matcher <- largeFilesMatcher
checkFileMatcher matcher file checkFileMatcher matcher file
-- TODO: Use main ingest code instead?
ingestLocal :: FilePath -> Annex Key
ingestLocal file = do
backend <- chooseBackend file
ic <- withTSDelta (liftIO . genInodeCache file)
let source = KeySource
{ keyFilename = file
, contentLocation = file
, inodeCache = ic
}
k <- fst . fromMaybe (error "failed to generate a key")
<$> genKey source backend
-- Hard link (or copy) file content to annex object
-- to prevent it from being lost when git checks out
-- a branch not containing this file.
r <- linkToAnnex k file ic
case r of
LinkAnnexFailed -> error "Problem adding file to the annex"
LinkAnnexOk -> logStatus k InfoPresent
LinkAnnexNoop -> noop
genMetaData k file
=<< liftIO (getFileStatus file)
cleanOldKeys file k
Database.Keys.addAssociatedFile k file
return k
emitPointer :: Key -> IO () emitPointer :: Key -> IO ()
emitPointer = putStr . formatPointer emitPointer = putStr . formatPointer