cleanup
This commit is contained in:
parent
00988bcf36
commit
3d2a9f8405
11 changed files with 48 additions and 54 deletions
|
@ -38,11 +38,10 @@ start p@(_, file) = notBareRepo $ notAnnexed file $ do
|
|||
next $ perform p
|
||||
|
||||
perform :: BackendFile -> CommandPerform
|
||||
perform (backend, file) = do
|
||||
k <- Backend.genKey file backend
|
||||
case k of
|
||||
Nothing -> stop
|
||||
Just (key, _) -> do
|
||||
perform (backend, file) = Backend.genKey file backend >>= go
|
||||
where
|
||||
go Nothing = stop
|
||||
go (Just (key, _)) = do
|
||||
handle (undo file key) $ moveAnnex key file
|
||||
next $ cleanup file key True
|
||||
|
||||
|
@ -75,9 +74,9 @@ cleanup file key hascontent = do
|
|||
|
||||
-- touch the symlink to have the same mtime as the
|
||||
-- file it points to
|
||||
s <- liftIO $ getFileStatus file
|
||||
let mtime = modificationTime s
|
||||
liftIO $ touch file (TimeSpec mtime) False
|
||||
liftIO $ do
|
||||
mtime <- modificationTime <$> getFileStatus file
|
||||
touch file (TimeSpec mtime) False
|
||||
|
||||
force <- Annex.getState Annex.force
|
||||
if force
|
||||
|
|
|
@ -26,11 +26,10 @@ seek :: [CommandSeek]
|
|||
seek = [withStrings start]
|
||||
|
||||
start :: String -> CommandStart
|
||||
start s = notBareRepo $ do
|
||||
let u = parseURI s
|
||||
case u of
|
||||
Nothing -> error $ "bad url " ++ s
|
||||
Just url -> do
|
||||
start s = notBareRepo $ go $ parseURI s
|
||||
where
|
||||
go Nothing = error $ "bad url " ++ s
|
||||
go (Just url) = do
|
||||
file <- liftIO $ url2file url
|
||||
showStart "addurl" file
|
||||
next $ perform s file
|
||||
|
@ -64,7 +63,6 @@ nodownload :: String -> FilePath -> CommandPerform
|
|||
nodownload url file = do
|
||||
let key = Backend.URL.fromUrl url
|
||||
setUrlPresent key url
|
||||
|
||||
next $ Command.Add.cleanup file key False
|
||||
|
||||
url2file :: URI -> IO FilePath
|
||||
|
|
|
@ -20,15 +20,11 @@ seek :: [CommandSeek]
|
|||
seek = [withWords start]
|
||||
|
||||
start :: [String] -> CommandStart
|
||||
start ws = do
|
||||
let (name, description) =
|
||||
case ws of
|
||||
(n:d) -> (n,unwords d)
|
||||
_ -> error "Specify a repository and a description."
|
||||
|
||||
start (name:description) = do
|
||||
showStart "describe" name
|
||||
u <- Remote.nameToUUID name
|
||||
next $ perform u description
|
||||
next $ perform u $ unwords description
|
||||
start _ = do error "Specify a repository and a description."
|
||||
|
||||
perform :: UUID -> String -> CommandPerform
|
||||
perform u description = do
|
||||
|
|
|
@ -23,14 +23,16 @@ seek = [withKeys start]
|
|||
start :: Key -> CommandStart
|
||||
start key = do
|
||||
present <- inAnnex key
|
||||
force <- Annex.getState Annex.force
|
||||
if not present
|
||||
then stop
|
||||
else if not force
|
||||
then error "dropkey is can cause data loss; use --force if you're sure you want to do this"
|
||||
else do
|
||||
showStart "dropkey" (show key)
|
||||
next $ perform key
|
||||
else do
|
||||
checkforced
|
||||
showStart "dropkey" (show key)
|
||||
next $ perform key
|
||||
where
|
||||
checkforced =
|
||||
unlessM (Annex.getState Annex.force) $
|
||||
error "dropkey can cause data loss; use --force if you're sure you want to do this"
|
||||
|
||||
perform :: Key -> CommandPerform
|
||||
perform key = do
|
||||
|
|
|
@ -71,8 +71,7 @@ readUnusedLog prefix = do
|
|||
let f = gitAnnexUnusedLog prefix g
|
||||
e <- liftIO $ doesFileExist f
|
||||
if e
|
||||
then return . M.fromList . map parse . lines
|
||||
=<< liftIO (readFile f)
|
||||
then M.fromList . map parse . lines <$> liftIO (readFile f)
|
||||
else return M.empty
|
||||
where
|
||||
parse line = (head ws, fromJust $ readKey $ unwords $ tail ws)
|
||||
|
|
|
@ -67,7 +67,9 @@ findByName name = do
|
|||
return (uuid, M.insert nameKey name M.empty)
|
||||
|
||||
findByName' :: String -> M.Map UUID R.RemoteConfig -> Maybe (UUID, R.RemoteConfig)
|
||||
findByName' n m = if null matches then Nothing else Just $ head matches
|
||||
findByName' n m
|
||||
| null matches = Nothing
|
||||
| otherwise = Just $ head matches
|
||||
where
|
||||
matches = filter (matching . snd) $ M.toList m
|
||||
matching c = case M.lookup nameKey c of
|
||||
|
|
|
@ -56,11 +56,7 @@ perform file oldkey newbackend = do
|
|||
case k of
|
||||
Nothing -> stop
|
||||
Just (newkey, _) -> do
|
||||
ok <- getViaTmpUnchecked newkey $ \t -> do
|
||||
-- Make a hard link to the old backend's
|
||||
-- cached key, to avoid wasting disk space.
|
||||
liftIO $ unlessM (doesFileExist t) $ createLink src t
|
||||
return True
|
||||
ok <- link src newkey
|
||||
if ok
|
||||
then do
|
||||
-- Update symlink to use the new key.
|
||||
|
@ -77,3 +73,8 @@ perform file oldkey newbackend = do
|
|||
else stop
|
||||
where
|
||||
cleantmp t = whenM (doesFileExist t) $ removeFile t
|
||||
link src newkey = getViaTmpUnchecked newkey $ \t -> do
|
||||
-- Make a hard link to the old backend's
|
||||
-- cached key, to avoid wasting disk space.
|
||||
liftIO $ unlessM (doesFileExist t) $ createLink src t
|
||||
return True
|
||||
|
|
|
@ -21,9 +21,11 @@ seek :: [CommandSeek]
|
|||
seek = [withWords start]
|
||||
|
||||
start :: [FilePath] -> CommandStart
|
||||
start (src:dest:[]) = do
|
||||
showStart "reinject" dest
|
||||
next $ perform src dest
|
||||
start (src:dest:[])
|
||||
| src == dest = stop
|
||||
| otherwise = do
|
||||
showStart "reinject" dest
|
||||
next $ perform src dest
|
||||
start _ = error "specify a src file and a dest file"
|
||||
|
||||
perform :: FilePath -> FilePath -> CommandPerform
|
||||
|
@ -36,9 +38,7 @@ perform src dest = isAnnexed dest $ \(key, backend) -> do
|
|||
-- moveToObjectDir; disk space is also
|
||||
-- checked this way.
|
||||
move key = getViaTmp key $ \tmp ->
|
||||
if dest /= src
|
||||
then liftIO $ boolSystem "mv" [File src, File tmp]
|
||||
else return True
|
||||
liftIO $ boolSystem "mv" [File src, File tmp]
|
||||
|
||||
cleanup :: Key -> Backend Annex -> CommandCleanup
|
||||
cleanup key backend = do
|
||||
|
|
|
@ -21,12 +21,13 @@ seek = [withNothing start]
|
|||
|
||||
start :: CommandStart
|
||||
start = do
|
||||
liftIO $ putStrLn $ "git-annex version: " ++ SysConfig.packageversion
|
||||
v <- getVersion
|
||||
liftIO $ putStrLn $ "local repository version: " ++ fromMaybe "unknown" v
|
||||
liftIO $ putStrLn $ "default repository version: " ++ defaultVersion
|
||||
liftIO $ putStrLn $ "supported repository versions: " ++ vs supportedVersions
|
||||
liftIO $ putStrLn $ "upgrade supported from repository versions: " ++ vs upgradableVersions
|
||||
liftIO $ do
|
||||
putStrLn $ "git-annex version: " ++ SysConfig.packageversion
|
||||
putStrLn $ "local repository version: " ++ fromMaybe "unknown" v
|
||||
putStrLn $ "default repository version: " ++ defaultVersion
|
||||
putStrLn $ "supported repository versions: " ++ vs supportedVersions
|
||||
putStrLn $ "upgrade supported from repository versions: " ++ vs upgradableVersions
|
||||
stop
|
||||
where
|
||||
vs = join " "
|
||||
|
|
|
@ -31,11 +31,9 @@ perform key = do
|
|||
let num = length safelocations
|
||||
showNote $ show num ++ " " ++ copiesplural num
|
||||
pp <- prettyPrintUUIDs "whereis" safelocations
|
||||
unless (null safelocations) $
|
||||
showLongNote pp
|
||||
unless (null safelocations) $ showLongNote pp
|
||||
pp' <- prettyPrintUUIDs "untrusted" untrustedlocations
|
||||
unless (null untrustedlocations) $
|
||||
showLongNote $ untrustedheader ++ pp'
|
||||
unless (null untrustedlocations) $ showLongNote $ untrustedheader ++ pp'
|
||||
if null safelocations then stop else next $ return True
|
||||
where
|
||||
copiesplural 1 = "copy"
|
||||
|
|
4
Init.hs
4
Init.hs
|
@ -65,9 +65,7 @@ gitPreCommitHookUnWrite = unlessBare $ do
|
|||
" Edit it to remove call to git annex."
|
||||
|
||||
unlessBare :: Annex () -> Annex ()
|
||||
unlessBare a = do
|
||||
g <- gitRepo
|
||||
unless (Git.repoIsLocalBare g) a
|
||||
unlessBare = unlessM $ Git.repoIsLocalBare <$> gitRepo
|
||||
|
||||
preCommitHook :: Annex FilePath
|
||||
preCommitHook = do
|
||||
|
|
Loading…
Add table
Reference in a new issue