This commit is contained in:
Joey Hess 2010-10-13 03:30:51 -04:00
parent 4b801b265a
commit cc5cf0093e

View file

@ -41,20 +41,24 @@ startAnnex = do
backends = parseBackendList $ gitConfig r' "annex.backends" "" backends = parseBackendList $ gitConfig r' "annex.backends" ""
} }
inBackend file yes no = do
r <- lookupFile file
case (r) of
Just v -> yes v
Nothing -> no
notinBackend file yes no = inBackend file no yes
{- Annexes a file, storing it in a backend, and then moving it into {- Annexes a file, storing it in a backend, and then moving it into
- the annex directory and setting up the symlink pointing to its content. -} - the annex directory and setting up the symlink pointing to its content. -}
annexFile :: State -> FilePath -> IO () annexFile :: State -> FilePath -> IO ()
annexFile state file = do annexFile state file = inBackend file err $ do
r <- lookupFile file
case (r) of
Just _ -> error $ "already annexed " ++ file
Nothing -> do
checkLegal file checkLegal file
stored <- storeFile state file stored <- storeFile state file
case (stored) of case (stored) of
Nothing -> error $ "no backend could store: " ++ file Nothing -> error $ "no backend could store: " ++ file
Just (key, backend) -> setup key backend Just (key, backend) -> setup key backend
where where
err = error $ "already annexed " ++ file
checkLegal file = do checkLegal file = do
s <- getSymbolicLinkStatus file s <- getSymbolicLinkStatus file
if ((isSymbolicLink s) || (not $ isRegularFile s)) if ((isSymbolicLink s) || (not $ isRegularFile s))
@ -82,21 +86,19 @@ annexFile state file = do
{- Inverse of annexFile. -} {- Inverse of annexFile. -}
unannexFile :: State -> FilePath -> IO () unannexFile :: State -> FilePath -> IO ()
unannexFile state file = do unannexFile state file = notinBackend file err $ \(key, backend) -> do
r <- lookupFile file
case (r) of
Nothing -> error $ "not annexed " ++ file
Just (key, backend) -> do
dropped <- dropFile state backend key dropped <- dropFile state backend key
if (not dropped) if (not dropped)
then error $ "backend refused to drop " ++ file then error $ "backend refused to drop " ++ file
else do else cleanup key backend
where
err = error $ "not annexed " ++ file
cleanup key backend = do
let src = annexLocation state backend key let src = annexLocation state backend key
removeFile file removeFile file
gitRun (repo state) ["rm", file] gitRun (repo state) ["rm", file]
gitRun (repo state) ["commit", "-m", gitRun (repo state) ["commit", "-m",
("git-annex unannexed " ++ file), ("git-annex unannexed " ++ file), file]
file]
-- git rm deletes empty directories; -- git rm deletes empty directories;
-- put them back -- put them back
createDirectoryIfMissing True (parentDir file) createDirectoryIfMissing True (parentDir file)