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 checkLegal file
case (r) of stored <- storeFile state file
Just _ -> error $ "already annexed " ++ file case (stored) of
Nothing -> do Nothing -> error $ "no backend could store: " ++ file
checkLegal file Just (key, backend) -> setup key backend
stored <- storeFile state file
case (stored) of
Nothing -> error $ "no backend could store: " ++ file
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,27 +86,25 @@ 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 dropped <- dropFile state backend key
case (r) of if (not dropped)
Nothing -> error $ "not annexed " ++ file then error $ "backend refused to drop " ++ file
Just (key, backend) -> do else cleanup key backend
dropped <- dropFile state backend key where
if (not dropped) err = error $ "not annexed " ++ file
then error $ "backend refused to drop " ++ file cleanup key backend = do
else 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), file]
("git-annex unannexed " ++ file), -- git rm deletes empty directories;
file] -- put them back
-- git rm deletes empty directories; createDirectoryIfMissing True (parentDir file)
-- put them back renameFile src file
createDirectoryIfMissing True (parentDir file) logStatus state key ValueMissing
renameFile src file return ()
logStatus state key ValueMissing
return ()
{- Transfers the file from a remote. -} {- Transfers the file from a remote. -}
annexGetFile :: State -> FilePath -> IO () annexGetFile :: State -> FilePath -> IO ()