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