finished hlint pass
This commit is contained in:
parent
185f0b6870
commit
6c396a256c
29 changed files with 114 additions and 115 deletions
|
@ -39,7 +39,7 @@ seek = [withFilesNotInGit start, withFilesUnlocked start]
|
||||||
start :: CommandStartBackendFile
|
start :: CommandStartBackendFile
|
||||||
start pair@(file, _) = notAnnexed file $ do
|
start pair@(file, _) = notAnnexed file $ do
|
||||||
s <- liftIO $ getSymbolicLinkStatus file
|
s <- liftIO $ getSymbolicLinkStatus file
|
||||||
if (isSymbolicLink s) || (not $ isRegularFile s)
|
if isSymbolicLink s || not (isRegularFile s)
|
||||||
then stop
|
then stop
|
||||||
else do
|
else do
|
||||||
showStart "add" file
|
showStart "add" file
|
||||||
|
@ -58,8 +58,8 @@ perform (file, backend) = do
|
||||||
- This can be called before or after the symlink is in place. -}
|
- This can be called before or after the symlink is in place. -}
|
||||||
undo :: FilePath -> Key -> IOException -> Annex a
|
undo :: FilePath -> Key -> IOException -> Annex a
|
||||||
undo file key e = do
|
undo file key e = do
|
||||||
unlessM (inAnnex key) $ rethrow -- no cleanup to do
|
unlessM (inAnnex key) rethrow -- no cleanup to do
|
||||||
liftIO $ whenM (doesFileExist file) $ do removeFile file
|
liftIO $ whenM (doesFileExist file) $ removeFile file
|
||||||
handle tryharder $ fromAnnex key file
|
handle tryharder $ fromAnnex key file
|
||||||
logStatus key InfoMissing
|
logStatus key InfoMissing
|
||||||
rethrow
|
rethrow
|
||||||
|
|
|
@ -49,7 +49,7 @@ start (unused, unusedbad, unusedtmp) s = notBareRepo $ search
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
search [] = stop
|
search [] = stop
|
||||||
search ((m, a):rest) = do
|
search ((m, a):rest) =
|
||||||
case M.lookup s m of
|
case M.lookup s m of
|
||||||
Nothing -> search rest
|
Nothing -> search rest
|
||||||
Just key -> do
|
Just key -> do
|
||||||
|
@ -78,10 +78,9 @@ 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 do
|
then return . M.fromList . map parse . lines
|
||||||
l <- liftIO $ readFile f
|
=<< liftIO (readFile f)
|
||||||
return $ M.fromList $ map parse $ lines l
|
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)
|
||||||
where
|
where
|
||||||
|
|
|
@ -94,7 +94,7 @@ fsckKey :: Backend Annex -> Key -> Maybe FilePath -> Maybe Int -> Annex Bool
|
||||||
fsckKey backend key file numcopies = do
|
fsckKey backend key file numcopies = do
|
||||||
size_ok <- checkKeySize key
|
size_ok <- checkKeySize key
|
||||||
copies_ok <- checkKeyNumCopies key file numcopies
|
copies_ok <- checkKeyNumCopies key file numcopies
|
||||||
backend_ok <-(Types.Backend.fsckKey backend) key
|
backend_ok <- (Types.Backend.fsckKey backend) key
|
||||||
return $ size_ok && copies_ok && backend_ok
|
return $ size_ok && copies_ok && backend_ok
|
||||||
|
|
||||||
{- The size of the data for a key is checked against the size encoded in
|
{- The size of the data for a key is checked against the size encoded in
|
||||||
|
|
|
@ -25,4 +25,4 @@ start key = do
|
||||||
present <- inAnnex key
|
present <- inAnnex key
|
||||||
if present
|
if present
|
||||||
then stop
|
then stop
|
||||||
else liftIO $ exitFailure
|
else liftIO exitFailure
|
||||||
|
|
|
@ -24,7 +24,7 @@ import Messages
|
||||||
command :: [Command]
|
command :: [Command]
|
||||||
command = [repoCommand "initremote"
|
command = [repoCommand "initremote"
|
||||||
(paramPair paramName $
|
(paramPair paramName $
|
||||||
paramOptional $ paramRepeating $ paramKeyValue) seek
|
paramOptional $ paramRepeating paramKeyValue) seek
|
||||||
"sets up a special (non-git) remote"]
|
"sets up a special (non-git) remote"]
|
||||||
|
|
||||||
seek :: [CommandSeek]
|
seek :: [CommandSeek]
|
||||||
|
@ -32,7 +32,7 @@ seek = [withWords start]
|
||||||
|
|
||||||
start :: CommandStartWords
|
start :: CommandStartWords
|
||||||
start ws = do
|
start ws = do
|
||||||
when (null ws) $ needname
|
when (null ws) needname
|
||||||
|
|
||||||
(u, c) <- findByName name
|
(u, c) <- findByName name
|
||||||
let fullconfig = M.union config c
|
let fullconfig = M.union config c
|
||||||
|
@ -69,7 +69,7 @@ findByName name = do
|
||||||
maybe generate return $ findByName' name m
|
maybe generate return $ findByName' name m
|
||||||
where
|
where
|
||||||
generate = do
|
generate = do
|
||||||
uuid <- liftIO $ genUUID
|
uuid <- liftIO genUUID
|
||||||
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)
|
||||||
|
@ -85,7 +85,7 @@ findByName' n m = if null matches then Nothing else Just $ head matches
|
||||||
remoteNames :: Annex [String]
|
remoteNames :: Annex [String]
|
||||||
remoteNames = do
|
remoteNames = do
|
||||||
m <- RemoteLog.readRemoteLog
|
m <- RemoteLog.readRemoteLog
|
||||||
return $ catMaybes $ map ((M.lookup nameKey) . snd) $ M.toList m
|
return $ mapMaybe (M.lookup nameKey . snd) $ M.toList m
|
||||||
|
|
||||||
{- find the specified remote type -}
|
{- find the specified remote type -}
|
||||||
findType :: R.RemoteConfig -> Annex (R.RemoteType Annex)
|
findType :: R.RemoteConfig -> Annex (R.RemoteType Annex)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import Control.Exception.Extensible
|
||||||
import System.Cmd.Utils
|
import System.Cmd.Utils
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.List.Utils
|
import Data.List.Utils
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
@ -58,7 +59,7 @@ start = do
|
||||||
- the repositories first, followed by uuids that were not matched
|
- the repositories first, followed by uuids that were not matched
|
||||||
- to a repository.
|
- to a repository.
|
||||||
-}
|
-}
|
||||||
drawMap :: [Git.Repo] -> (M.Map UUID String) -> [UUID] -> String
|
drawMap :: [Git.Repo] -> M.Map UUID String -> [UUID] -> String
|
||||||
drawMap rs umap ts = Dot.graph $ repos ++ trusted ++ others
|
drawMap rs umap ts = Dot.graph $ repos ++ trusted ++ others
|
||||||
where
|
where
|
||||||
repos = map (node umap rs) rs
|
repos = map (node umap rs) rs
|
||||||
|
@ -78,23 +79,23 @@ basehostname r = head $ split "." $ hostname r
|
||||||
|
|
||||||
{- A name to display for a repo. Uses the name from uuid.log if available,
|
{- A name to display for a repo. Uses the name from uuid.log if available,
|
||||||
- or the remote name if not. -}
|
- or the remote name if not. -}
|
||||||
repoName :: (M.Map UUID String) -> Git.Repo -> String
|
repoName :: M.Map UUID String -> Git.Repo -> String
|
||||||
repoName umap r
|
repoName umap r
|
||||||
| null repouuid = fallback
|
| null repouuid = fallback
|
||||||
| otherwise = M.findWithDefault fallback repouuid umap
|
| otherwise = M.findWithDefault fallback repouuid umap
|
||||||
where
|
where
|
||||||
repouuid = getUncachedUUID r
|
repouuid = getUncachedUUID r
|
||||||
fallback = maybe "unknown" id $ Git.repoRemoteName r
|
fallback = fromMaybe "unknown" $ Git.repoRemoteName r
|
||||||
|
|
||||||
{- A unique id for the node for a repo. Uses the annex.uuid if available. -}
|
{- A unique id for the node for a repo. Uses the annex.uuid if available. -}
|
||||||
nodeId :: Git.Repo -> String
|
nodeId :: Git.Repo -> String
|
||||||
nodeId r =
|
nodeId r =
|
||||||
case (getUncachedUUID r) of
|
case getUncachedUUID r of
|
||||||
"" -> Git.repoLocation r
|
"" -> Git.repoLocation r
|
||||||
u -> u
|
u -> u
|
||||||
|
|
||||||
{- A node representing a repo. -}
|
{- A node representing a repo. -}
|
||||||
node :: (M.Map UUID String) -> [Git.Repo] -> Git.Repo -> String
|
node :: M.Map UUID String -> [Git.Repo] -> Git.Repo -> String
|
||||||
node umap fullinfo r = unlines $ n:edges
|
node umap fullinfo r = unlines $ n:edges
|
||||||
where
|
where
|
||||||
n = Dot.subGraph (hostname r) (basehostname r) "lightblue" $
|
n = Dot.subGraph (hostname r) (basehostname r) "lightblue" $
|
||||||
|
@ -105,14 +106,14 @@ node umap fullinfo r = unlines $ n:edges
|
||||||
| otherwise = reachable
|
| otherwise = reachable
|
||||||
|
|
||||||
{- An edge between two repos. The second repo is a remote of the first. -}
|
{- An edge between two repos. The second repo is a remote of the first. -}
|
||||||
edge :: (M.Map UUID String) -> [Git.Repo] -> Git.Repo -> Git.Repo -> String
|
edge :: M.Map UUID String -> [Git.Repo] -> Git.Repo -> Git.Repo -> String
|
||||||
edge umap fullinfo from to =
|
edge umap fullinfo from to =
|
||||||
Dot.graphEdge (nodeId from) (nodeId fullto) edgename
|
Dot.graphEdge (nodeId from) (nodeId fullto) edgename
|
||||||
where
|
where
|
||||||
-- get the full info for the remote, to get its UUID
|
-- get the full info for the remote, to get its UUID
|
||||||
fullto = findfullinfo to
|
fullto = findfullinfo to
|
||||||
findfullinfo n =
|
findfullinfo n =
|
||||||
case (filter (same n) fullinfo) of
|
case filter (same n) fullinfo of
|
||||||
[] -> n
|
[] -> n
|
||||||
(n':_) -> n'
|
(n':_) -> n'
|
||||||
{- Only name an edge if the name is different than the name
|
{- Only name an edge if the name is different than the name
|
||||||
|
@ -120,7 +121,7 @@ edge umap fullinfo from to =
|
||||||
- different from its hostname. (This reduces visual clutter.) -}
|
- different from its hostname. (This reduces visual clutter.) -}
|
||||||
edgename = maybe Nothing calcname $ Git.repoRemoteName to
|
edgename = maybe Nothing calcname $ Git.repoRemoteName to
|
||||||
calcname n
|
calcname n
|
||||||
| n == repoName umap fullto || n == hostname fullto = Nothing
|
| n `elem` [repoName umap fullto, hostname fullto] = Nothing
|
||||||
| otherwise = Just n
|
| otherwise = Just n
|
||||||
|
|
||||||
unreachable :: String -> String
|
unreachable :: String -> String
|
||||||
|
@ -188,7 +189,7 @@ tryScan r
|
||||||
| otherwise = safely $ Git.configRead r
|
| otherwise = safely $ Git.configRead r
|
||||||
where
|
where
|
||||||
safely a = do
|
safely a = do
|
||||||
result <- liftIO (try (a)::IO (Either SomeException Git.Repo))
|
result <- liftIO (try a :: IO (Either SomeException Git.Repo))
|
||||||
case result of
|
case result of
|
||||||
Left _ -> return Nothing
|
Left _ -> return Nothing
|
||||||
Right r' -> return $ Just r'
|
Right r' -> return $ Just r'
|
||||||
|
|
|
@ -124,7 +124,7 @@ fromStart src move file = isAnnexed file $ \(key, _) -> do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
u <- getUUID g
|
u <- getUUID g
|
||||||
remotes <- Remote.keyPossibilities key
|
remotes <- Remote.keyPossibilities key
|
||||||
if (u == Remote.uuid src) || (null $ filter (== src) remotes)
|
if u == Remote.uuid src || not (any (== src) remotes)
|
||||||
then stop
|
then stop
|
||||||
else do
|
else do
|
||||||
showAction move file
|
showAction move file
|
||||||
|
|
|
@ -16,7 +16,7 @@ import Content
|
||||||
import Messages
|
import Messages
|
||||||
|
|
||||||
command :: [Command]
|
command :: [Command]
|
||||||
command = [repoCommand "setkey" (paramPath) seek
|
command = [repoCommand "setkey" paramPath seek
|
||||||
"sets annexed content for a key using a temp file"]
|
"sets annexed content for a key using a temp file"]
|
||||||
|
|
||||||
seek :: [CommandSeek]
|
seek :: [CommandSeek]
|
||||||
|
@ -34,7 +34,7 @@ perform file = do
|
||||||
-- the file might be on a different filesystem, so mv is used
|
-- the file might be on a different filesystem, so mv is used
|
||||||
-- rather than simply calling moveToObjectDir; disk space is also
|
-- rather than simply calling moveToObjectDir; disk space is also
|
||||||
-- checked this way.
|
-- checked this way.
|
||||||
ok <- getViaTmp key $ \dest -> do
|
ok <- getViaTmp key $ \dest ->
|
||||||
if dest /= file
|
if dest /= file
|
||||||
then liftIO $
|
then liftIO $
|
||||||
boolSystem "mv" [File file, File dest]
|
boolSystem "mv" [File file, File dest]
|
||||||
|
|
|
@ -32,8 +32,8 @@ type Stat = StatState (Maybe (String, StatState String))
|
||||||
|
|
||||||
-- cached info that multiple Stats may need
|
-- cached info that multiple Stats may need
|
||||||
data StatInfo = StatInfo
|
data StatInfo = StatInfo
|
||||||
{ keysPresentCache :: (Maybe (SizeList Key))
|
{ keysPresentCache :: Maybe (SizeList Key)
|
||||||
, keysReferencedCache :: (Maybe (SizeList Key))
|
, keysReferencedCache :: Maybe (SizeList Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- a state monad for running Stats in
|
-- a state monad for running Stats in
|
||||||
|
@ -84,7 +84,7 @@ stat :: String -> StatState String -> Stat
|
||||||
stat desc a = return $ Just (desc, a)
|
stat desc a = return $ Just (desc, a)
|
||||||
|
|
||||||
nostat :: Stat
|
nostat :: Stat
|
||||||
nostat = return $ Nothing
|
nostat = return Nothing
|
||||||
|
|
||||||
showStat :: Stat -> StatState ()
|
showStat :: Stat -> StatState ()
|
||||||
showStat s = calc =<< s
|
showStat s = calc =<< s
|
||||||
|
@ -144,7 +144,7 @@ cachedKeysPresent = do
|
||||||
case keysPresentCache s of
|
case keysPresentCache s of
|
||||||
Just v -> return v
|
Just v -> return v
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
keys <- lift $ getKeysPresent
|
keys <- lift getKeysPresent
|
||||||
let v = sizeList keys
|
let v = sizeList keys
|
||||||
put s { keysPresentCache = Just v }
|
put s { keysPresentCache = Just v }
|
||||||
return v
|
return v
|
||||||
|
@ -155,7 +155,7 @@ cachedKeysReferenced = do
|
||||||
case keysReferencedCache s of
|
case keysReferencedCache s of
|
||||||
Just v -> return v
|
Just v -> return v
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
keys <- lift $ Command.Unused.getKeysReferenced
|
keys <- lift Command.Unused.getKeysReferenced
|
||||||
-- A given key may be referenced repeatedly.
|
-- A given key may be referenced repeatedly.
|
||||||
-- nub does not seem too slow (yet)..
|
-- nub does not seem too slow (yet)..
|
||||||
let v = sizeList $ nub keys
|
let v = sizeList $ nub keys
|
||||||
|
@ -164,9 +164,9 @@ cachedKeysReferenced = do
|
||||||
|
|
||||||
keySizeSum :: SizeList Key -> StatState String
|
keySizeSum :: SizeList Key -> StatState String
|
||||||
keySizeSum (keys, len) = do
|
keySizeSum (keys, len) = do
|
||||||
let knownsize = catMaybes $ map keySize keys
|
let knownsizes = mapMaybe keySize keys
|
||||||
let total = roughSize storageUnits False $ foldl (+) 0 knownsize
|
let total = roughSize storageUnits False $ sum knownsizes
|
||||||
let missing = len - genericLength knownsize
|
let missing = len - genericLength knownsizes
|
||||||
return $ total ++
|
return $ total ++
|
||||||
if missing > 0
|
if missing > 0
|
||||||
then aside $ "but " ++ show missing ++ " keys have unknown size"
|
then aside $ "but " ++ show missing ++ " keys have unknown size"
|
||||||
|
|
|
@ -52,8 +52,9 @@ cleanup = do
|
||||||
liftIO $ removeDirectoryRecursive (gitAnnexDir g)
|
liftIO $ removeDirectoryRecursive (gitAnnexDir g)
|
||||||
-- avoid normal shutdown
|
-- avoid normal shutdown
|
||||||
saveState
|
saveState
|
||||||
liftIO $ Git.run g "branch" [Param "-D", Param Branch.name]
|
liftIO $ do
|
||||||
liftIO $ exitSuccess
|
Git.run g "branch" [Param "-D", Param Branch.name]
|
||||||
|
exitSuccess
|
||||||
|
|
||||||
gitPreCommitHookUnWrite :: Git.Repo -> Annex ()
|
gitPreCommitHookUnWrite :: Git.Repo -> Annex ()
|
||||||
gitPreCommitHookUnWrite repo = do
|
gitPreCommitHookUnWrite repo = do
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
module Command.Unused where
|
module Command.Unused where
|
||||||
|
|
||||||
import Control.Monad (filterM, unless, forM_, when)
|
import Control.Monad (filterM, unless, forM_)
|
||||||
import Control.Monad.State (liftIO)
|
import Control.Monad.State (liftIO)
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
@ -55,9 +55,9 @@ checkUnused = do
|
||||||
where
|
where
|
||||||
list file msg l c = do
|
list file msg l c = do
|
||||||
let unusedlist = number c l
|
let unusedlist = number c l
|
||||||
when (not $ null l) $ do
|
unless (null l) $ do
|
||||||
showLongNote $ msg unusedlist
|
showLongNote $ msg unusedlist
|
||||||
showLongNote $ "\n"
|
showLongNote "\n"
|
||||||
writeUnusedFile file unusedlist
|
writeUnusedFile file unusedlist
|
||||||
return $ c + length l
|
return $ c + length l
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ checkRemoteUnused name = do
|
||||||
|
|
||||||
checkRemoteUnused' :: Remote.Remote Annex -> Annex ()
|
checkRemoteUnused' :: Remote.Remote Annex -> Annex ()
|
||||||
checkRemoteUnused' r = do
|
checkRemoteUnused' r = do
|
||||||
showNote $ "checking for unused data..."
|
showNote "checking for unused data..."
|
||||||
referenced <- getKeysReferenced
|
referenced <- getKeysReferenced
|
||||||
remotehas <- filterM isthere =<< loggedKeys
|
remotehas <- filterM isthere =<< loggedKeys
|
||||||
let remoteunused = remotehas `exclude` referenced
|
let remoteunused = remotehas `exclude` referenced
|
||||||
|
@ -76,7 +76,7 @@ checkRemoteUnused' r = do
|
||||||
writeUnusedFile "" list
|
writeUnusedFile "" list
|
||||||
unless (null remoteunused) $ do
|
unless (null remoteunused) $ do
|
||||||
showLongNote $ remoteUnusedMsg r list
|
showLongNote $ remoteUnusedMsg r list
|
||||||
showLongNote $ "\n"
|
showLongNote "\n"
|
||||||
where
|
where
|
||||||
isthere k = do
|
isthere k = do
|
||||||
us <- keyLocations k
|
us <- keyLocations k
|
||||||
|
@ -90,14 +90,14 @@ writeUnusedFile prefix l = do
|
||||||
unlines $ map (\(n, k) -> show n ++ " " ++ show k) l
|
unlines $ map (\(n, k) -> show n ++ " " ++ show k) l
|
||||||
|
|
||||||
table :: [(Int, Key)] -> [String]
|
table :: [(Int, Key)] -> [String]
|
||||||
table l = [" NUMBER KEY"] ++ map cols l
|
table l = " NUMBER KEY" : map cols l
|
||||||
where
|
where
|
||||||
cols (n,k) = " " ++ pad 6 (show n) ++ " " ++ show k
|
cols (n,k) = " " ++ pad 6 (show n) ++ " " ++ show k
|
||||||
pad n s = s ++ replicate (n - length s) ' '
|
pad n s = s ++ replicate (n - length s) ' '
|
||||||
|
|
||||||
number :: Int -> [a] -> [(Int, a)]
|
number :: Int -> [a] -> [(Int, a)]
|
||||||
number _ [] = []
|
number _ [] = []
|
||||||
number n (x:xs) = (n+1, x):(number (n+1) xs)
|
number n (x:xs) = (n+1, x) : number (n+1) xs
|
||||||
|
|
||||||
staleTmpMsg :: [(Int, Key)] -> String
|
staleTmpMsg :: [(Int, Key)] -> String
|
||||||
staleTmpMsg t = unlines $
|
staleTmpMsg t = unlines $
|
||||||
|
@ -210,4 +210,4 @@ staleKeys dirspec = do
|
||||||
contents <- liftIO $ getDirectoryContents dir
|
contents <- liftIO $ getDirectoryContents dir
|
||||||
files <- liftIO $ filterM doesFileExist $
|
files <- liftIO $ filterM doesFileExist $
|
||||||
map (dir </>) contents
|
map (dir </>) contents
|
||||||
return $ catMaybes $ map (fileKey . takeFileName) files
|
return $ mapMaybe (fileKey . takeFileName) files
|
||||||
|
|
|
@ -31,4 +31,4 @@ start = do
|
||||||
liftIO $ putStrLn $ "upgrade supported from repository versions: " ++ vs upgradableVersions
|
liftIO $ putStrLn $ "upgrade supported from repository versions: " ++ vs upgradableVersions
|
||||||
stop
|
stop
|
||||||
where
|
where
|
||||||
vs l = join " " l
|
vs = join " "
|
||||||
|
|
|
@ -30,11 +30,11 @@ perform key = do
|
||||||
uuids <- keyLocations key
|
uuids <- keyLocations key
|
||||||
let num = length uuids
|
let num = length uuids
|
||||||
showNote $ show num ++ " " ++ copiesplural num
|
showNote $ show num ++ " " ++ copiesplural num
|
||||||
if null $ uuids
|
if null uuids
|
||||||
then stop
|
then stop
|
||||||
else do
|
else do
|
||||||
pp <- prettyPrintUUIDs uuids
|
pp <- prettyPrintUUIDs uuids
|
||||||
showLongNote $ pp
|
showLongNote pp
|
||||||
showProgress
|
showProgress
|
||||||
next $ return True
|
next $ return True
|
||||||
where
|
where
|
||||||
|
|
|
@ -167,8 +167,8 @@ display_32bits_as_dir w = trim $ swap_pairs cs
|
||||||
-- a real word, use letters that appear less frequently.
|
-- a real word, use letters that appear less frequently.
|
||||||
chars = ['0'..'9'] ++ "zqjxkmvwgpfZQJXKMVWGPF"
|
chars = ['0'..'9'] ++ "zqjxkmvwgpfZQJXKMVWGPF"
|
||||||
cs = map (\x -> getc $ (shiftR w (6*x)) .&. 31) [0..7]
|
cs = map (\x -> getc $ (shiftR w (6*x)) .&. 31) [0..7]
|
||||||
getc n = chars !! (fromIntegral n)
|
getc n = chars !! fromIntegral n
|
||||||
swap_pairs (x1:x2:xs) = x2:x1:swap_pairs xs
|
swap_pairs (x1:x2:xs) = x2:x1:swap_pairs xs
|
||||||
swap_pairs _ = []
|
swap_pairs _ = []
|
||||||
-- Last 2 will always be 00, so omit.
|
-- Last 2 will always be 00, so omit.
|
||||||
trim s = take 6 s
|
trim = take 6
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
module Remote.Bup (remote) where
|
module Remote.Bup (remote) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy.Char8 as L
|
import qualified Data.ByteString.Lazy.Char8 as L
|
||||||
import IO
|
import System.IO
|
||||||
|
import System.IO.Error
|
||||||
import Control.Exception.Extensible (IOException)
|
import Control.Exception.Extensible (IOException)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
|
@ -16,6 +17,7 @@ import Control.Monad.State (liftIO)
|
||||||
import System.Process
|
import System.Process
|
||||||
import System.Exit
|
import System.Exit
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
import Data.Maybe
|
||||||
import Data.List.Utils
|
import Data.List.Utils
|
||||||
import System.Cmd.Utils
|
import System.Cmd.Utils
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ gen r u c = do
|
||||||
bupSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
bupSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
bupSetup u c = do
|
bupSetup u c = do
|
||||||
-- verify configuration is sane
|
-- verify configuration is sane
|
||||||
let buprepo = maybe (error "Specify buprepo=") id $
|
let buprepo = fromMaybe (error "Specify buprepo=") $
|
||||||
M.lookup "buprepo" c
|
M.lookup "buprepo" c
|
||||||
c' <- encryptionSetup c
|
c' <- encryptionSetup c
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ bupSetup u c = do
|
||||||
|
|
||||||
bupParams :: String -> BupRepo -> [CommandParam] -> [CommandParam]
|
bupParams :: String -> BupRepo -> [CommandParam] -> [CommandParam]
|
||||||
bupParams command buprepo params =
|
bupParams command buprepo params =
|
||||||
(Param command) : [Param "-r", Param buprepo] ++ params
|
Param command : [Param "-r", Param buprepo] ++ params
|
||||||
|
|
||||||
bup :: String -> BupRepo -> [CommandParam] -> Annex Bool
|
bup :: String -> BupRepo -> [CommandParam] -> Annex Bool
|
||||||
bup command buprepo params = do
|
bup command buprepo params = do
|
||||||
|
@ -123,8 +125,8 @@ storeEncrypted r buprepo (cipher, enck) k = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
let src = gitAnnexLocation g k
|
let src = gitAnnexLocation g k
|
||||||
params <- bupSplitParams r buprepo enck (Param "-")
|
params <- bupSplitParams r buprepo enck (Param "-")
|
||||||
liftIO $ catchBool $ do
|
liftIO $ catchBool $
|
||||||
withEncryptedHandle cipher (L.readFile src) $ \h -> do
|
withEncryptedHandle cipher (L.readFile src) $ \h ->
|
||||||
pipeBup params (Just h) Nothing
|
pipeBup params (Just h) Nothing
|
||||||
|
|
||||||
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
|
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
|
||||||
|
@ -184,7 +186,7 @@ onBupRemote :: Git.Repo -> (FilePath -> [CommandParam] -> IO a) -> FilePath -> [
|
||||||
onBupRemote r a command params = do
|
onBupRemote r a command params = do
|
||||||
let dir = shellEscape (Git.workTree r)
|
let dir = shellEscape (Git.workTree r)
|
||||||
sshparams <- sshToRepo r [Param $
|
sshparams <- sshToRepo r [Param $
|
||||||
"cd " ++ dir ++ " && " ++ (unwords $ command : toCommand params)]
|
"cd " ++ dir ++ " && " ++ unwords (command : toCommand params)]
|
||||||
liftIO $ a "ssh" sshparams
|
liftIO $ a "ssh" sshparams
|
||||||
|
|
||||||
{- Allow for bup repositories on removable media by checking
|
{- Allow for bup repositories on removable media by checking
|
||||||
|
@ -215,20 +217,20 @@ bup2GitRemote "" = do
|
||||||
Git.repoFromAbsPath $ h </> ".bup"
|
Git.repoFromAbsPath $ h </> ".bup"
|
||||||
bup2GitRemote r
|
bup2GitRemote r
|
||||||
| bupLocal r =
|
| bupLocal r =
|
||||||
if r !! 0 == '/'
|
if head r == '/'
|
||||||
then Git.repoFromAbsPath r
|
then Git.repoFromAbsPath r
|
||||||
else error "please specify an absolute path"
|
else error "please specify an absolute path"
|
||||||
| otherwise = Git.repoFromUrl $ "ssh://" ++ host ++ slash dir
|
| otherwise = Git.repoFromUrl $ "ssh://" ++ host ++ slash dir
|
||||||
where
|
where
|
||||||
bits = split ":" r
|
bits = split ":" r
|
||||||
host = bits !! 0
|
host = head bits
|
||||||
dir = join ":" $ drop 1 bits
|
dir = join ":" $ drop 1 bits
|
||||||
-- "host:~user/dir" is not supported specially by bup;
|
-- "host:~user/dir" is not supported specially by bup;
|
||||||
-- "host:dir" is relative to the home directory;
|
-- "host:dir" is relative to the home directory;
|
||||||
-- "host:" goes in ~/.bup
|
-- "host:" goes in ~/.bup
|
||||||
slash d
|
slash d
|
||||||
| d == "" = "/~/.bup"
|
| d == "" = "/~/.bup"
|
||||||
| d !! 0 == '/' = d
|
| head d == '/' = d
|
||||||
| otherwise = "/~/" ++ d
|
| otherwise = "/~/" ++ d
|
||||||
|
|
||||||
bupLocal :: BupRepo -> Bool
|
bupLocal :: BupRepo -> Bool
|
||||||
|
|
|
@ -8,13 +8,14 @@
|
||||||
module Remote.Directory (remote) where
|
module Remote.Directory (remote) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy.Char8 as L
|
import qualified Data.ByteString.Lazy.Char8 as L
|
||||||
import IO
|
import System.IO.Error
|
||||||
import Control.Exception.Extensible (IOException)
|
import Control.Exception.Extensible (IOException)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
import Control.Monad.State (liftIO)
|
import Control.Monad.State (liftIO)
|
||||||
import System.Directory hiding (copyFile)
|
import System.Directory hiding (copyFile)
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import Types.Remote
|
import Types.Remote
|
||||||
|
@ -60,7 +61,7 @@ gen r u c = do
|
||||||
directorySetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
directorySetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
directorySetup u c = do
|
directorySetup u c = do
|
||||||
-- verify configuration is sane
|
-- verify configuration is sane
|
||||||
let dir = maybe (error "Specify directory=") id $
|
let dir = fromMaybe (error "Specify directory=") $
|
||||||
M.lookup "directory" c
|
M.lookup "directory" c
|
||||||
liftIO $ doesDirectoryExist dir
|
liftIO $ doesDirectoryExist dir
|
||||||
>>! error $ "Directory does not exist: " ++ dir
|
>>! error $ "Directory does not exist: " ++ dir
|
||||||
|
|
|
@ -56,10 +56,10 @@ encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r =
|
||||||
where
|
where
|
||||||
store k = cip k >>= maybe
|
store k = cip k >>= maybe
|
||||||
(storeKey r k)
|
(storeKey r k)
|
||||||
(\x -> storeKeyEncrypted x k)
|
(`storeKeyEncrypted` k)
|
||||||
retrieve k f = cip k >>= maybe
|
retrieve k f = cip k >>= maybe
|
||||||
(retrieveKeyFile r k f)
|
(retrieveKeyFile r k f)
|
||||||
(\x -> retrieveKeyFileEncrypted x f)
|
(`retrieveKeyFileEncrypted` f)
|
||||||
withkey a k = cip k >>= maybe (a k) (a . snd)
|
withkey a k = cip k >>= maybe (a k) (a . snd)
|
||||||
cip = cipherKey c
|
cip = cipherKey c
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ gen r u _ = do
|
||||||
let defcst = if cheap then cheapRemoteCost else expensiveRemoteCost
|
let defcst = if cheap then cheapRemoteCost else expensiveRemoteCost
|
||||||
cst <- remoteCost r' defcst
|
cst <- remoteCost r' defcst
|
||||||
|
|
||||||
return $ Remote {
|
return Remote {
|
||||||
uuid = u',
|
uuid = u',
|
||||||
cost = cst,
|
cost = cst,
|
||||||
name = Git.repoDescribe r',
|
name = Git.repoDescribe r',
|
||||||
|
@ -81,7 +81,7 @@ tryGitConfigRead r
|
||||||
-- Reading config can fail due to IO error or
|
-- Reading config can fail due to IO error or
|
||||||
-- for other reasons; catch all possible exceptions.
|
-- for other reasons; catch all possible exceptions.
|
||||||
safely a = do
|
safely a = do
|
||||||
result <- liftIO (try (a)::IO (Either SomeException Git.Repo))
|
result <- liftIO (try a :: IO (Either SomeException Git.Repo))
|
||||||
case result of
|
case result of
|
||||||
Left _ -> return r
|
Left _ -> return r
|
||||||
Right r' -> return r'
|
Right r' -> return r'
|
||||||
|
@ -154,7 +154,7 @@ copyToRemote r key
|
||||||
rsyncHelper =<< rsyncParamsRemote r False key keysrc
|
rsyncHelper =<< rsyncParamsRemote r False key keysrc
|
||||||
| otherwise = error "copying to non-ssh repo not supported"
|
| otherwise = error "copying to non-ssh repo not supported"
|
||||||
|
|
||||||
rsyncHelper :: [CommandParam] -> Annex (Bool)
|
rsyncHelper :: [CommandParam] -> Annex Bool
|
||||||
rsyncHelper p = do
|
rsyncHelper p = do
|
||||||
showProgress -- make way for progress bar
|
showProgress -- make way for progress bar
|
||||||
res <- liftIO $ rsync p
|
res <- liftIO $ rsync p
|
||||||
|
|
|
@ -17,6 +17,7 @@ import System.Posix.IO
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.IO.Error (try)
|
import System.IO.Error (try)
|
||||||
import System.Exit
|
import System.Exit
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import Types.Remote
|
import Types.Remote
|
||||||
|
@ -61,7 +62,7 @@ gen r u c = do
|
||||||
|
|
||||||
hookSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
hookSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
hookSetup u c = do
|
hookSetup u c = do
|
||||||
let hooktype = maybe (error "Specify hooktype=") id $
|
let hooktype = fromMaybe (error "Specify hooktype=") $
|
||||||
M.lookup "hooktype" c
|
M.lookup "hooktype" c
|
||||||
c' <- encryptionSetup c
|
c' <- encryptionSetup c
|
||||||
gitConfigSpecialRemote u c' "hooktype" hooktype
|
gitConfigSpecialRemote u c' "hooktype" hooktype
|
||||||
|
@ -73,12 +74,13 @@ hookEnv k f = Just $ fileenv f ++ keyenv
|
||||||
env s v = ("ANNEX_" ++ s, v)
|
env s v = ("ANNEX_" ++ s, v)
|
||||||
keyenv =
|
keyenv =
|
||||||
[ env "KEY" (show k)
|
[ env "KEY" (show k)
|
||||||
, env "HASH_1" (hashbits !! 0)
|
, env "HASH_1" hash_1
|
||||||
, env "HASH_2" (hashbits !! 1)
|
, env "HASH_2" hash_2
|
||||||
]
|
]
|
||||||
fileenv Nothing = []
|
fileenv Nothing = []
|
||||||
fileenv (Just file) = [env "FILE" file]
|
fileenv (Just file) = [env "FILE" file]
|
||||||
hashbits = map takeDirectory $ splitPath $ hashDirMixed k
|
[hash_1, hash_2, _rest] =
|
||||||
|
map takeDirectory $ splitPath $ hashDirMixed k
|
||||||
|
|
||||||
lookupHook :: String -> String -> Annex (Maybe String)
|
lookupHook :: String -> String -> Annex (Maybe String)
|
||||||
lookupHook hooktype hook =do
|
lookupHook hooktype hook =do
|
||||||
|
@ -127,7 +129,7 @@ retrieveEncrypted h (cipher, enck) f = withTmp enck $ \tmp ->
|
||||||
return True
|
return True
|
||||||
|
|
||||||
remove :: String -> Key -> Annex Bool
|
remove :: String -> Key -> Annex Bool
|
||||||
remove h k = runHook h "remove" k Nothing $ do return True
|
remove h k = runHook h "remove" k Nothing $ return True
|
||||||
|
|
||||||
checkPresent :: Git.Repo -> String -> Key -> Annex (Either IOException Bool)
|
checkPresent :: Git.Repo -> String -> Key -> Annex (Either IOException Bool)
|
||||||
checkPresent r h k = do
|
checkPresent r h k = do
|
||||||
|
@ -135,7 +137,7 @@ checkPresent r h k = do
|
||||||
v <- lookupHook h "checkpresent"
|
v <- lookupHook h "checkpresent"
|
||||||
liftIO (try (check v) ::IO (Either IOException Bool))
|
liftIO (try (check v) ::IO (Either IOException Bool))
|
||||||
where
|
where
|
||||||
findkey s = (show k) `elem` (lines s)
|
findkey s = show k `elem` lines s
|
||||||
env = hookEnv k Nothing
|
env = hookEnv k Nothing
|
||||||
check Nothing = error "checkpresent hook misconfigured"
|
check Nothing = error "checkpresent hook misconfigured"
|
||||||
check (Just hook) = do
|
check (Just hook) = do
|
||||||
|
@ -150,5 +152,5 @@ checkPresent r h k = do
|
||||||
hClose fromh
|
hClose fromh
|
||||||
s <- getProcessStatus True False pid
|
s <- getProcessStatus True False pid
|
||||||
case s of
|
case s of
|
||||||
Just (Exited (ExitSuccess)) -> return $ findkey reply
|
Just (Exited ExitSuccess) -> return $ findkey reply
|
||||||
_ -> error "checkpresent hook failed"
|
_ -> error "checkpresent hook failed"
|
||||||
|
|
|
@ -15,6 +15,7 @@ import System.FilePath
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.Posix.Files
|
import System.Posix.Files
|
||||||
import System.Posix.Process
|
import System.Posix.Process
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import Types.Remote
|
import Types.Remote
|
||||||
|
@ -82,7 +83,7 @@ genRsyncOpts r = do
|
||||||
rsyncSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
rsyncSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
rsyncSetup u c = do
|
rsyncSetup u c = do
|
||||||
-- verify configuration is sane
|
-- verify configuration is sane
|
||||||
let url = maybe (error "Specify rsyncurl=") id $
|
let url = fromMaybe (error "Specify rsyncurl=") $
|
||||||
M.lookup "rsyncurl" c
|
M.lookup "rsyncurl" c
|
||||||
c' <- encryptionSetup c
|
c' <- encryptionSetup c
|
||||||
|
|
||||||
|
@ -160,10 +161,10 @@ partialParams = Params "--no-inplace --partial --partial-dir=.rsync-partial"
|
||||||
withRsyncScratchDir :: (FilePath -> Annex Bool) -> Annex Bool
|
withRsyncScratchDir :: (FilePath -> Annex Bool) -> Annex Bool
|
||||||
withRsyncScratchDir a = do
|
withRsyncScratchDir a = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
pid <- liftIO $ getProcessID
|
pid <- liftIO getProcessID
|
||||||
let tmp = gitAnnexTmpDir g </> "rsynctmp" </> show pid
|
let tmp = gitAnnexTmpDir g </> "rsynctmp" </> show pid
|
||||||
nuke tmp
|
nuke tmp
|
||||||
liftIO $ createDirectoryIfMissing True $ tmp
|
liftIO $ createDirectoryIfMissing True tmp
|
||||||
res <- a tmp
|
res <- a tmp
|
||||||
nuke tmp
|
nuke tmp
|
||||||
return res
|
return res
|
||||||
|
@ -189,15 +190,14 @@ rsyncRemote o params = do
|
||||||
rsyncSend :: RsyncOpts -> Key -> FilePath -> Annex Bool
|
rsyncSend :: RsyncOpts -> Key -> FilePath -> Annex Bool
|
||||||
rsyncSend o k src = withRsyncScratchDir $ \tmp -> do
|
rsyncSend o k src = withRsyncScratchDir $ \tmp -> do
|
||||||
let dest = tmp </> hashDirMixed k </> f </> f
|
let dest = tmp </> hashDirMixed k </> f </> f
|
||||||
liftIO $ createDirectoryIfMissing True $ parentDir $ dest
|
liftIO $ createDirectoryIfMissing True $ parentDir dest
|
||||||
liftIO $ createLink src dest
|
liftIO $ createLink src dest
|
||||||
res <- rsyncRemote o
|
rsyncRemote o
|
||||||
[ Param "--recursive"
|
[ Param "--recursive"
|
||||||
, partialParams
|
, partialParams
|
||||||
-- tmp/ to send contents of tmp dir
|
-- tmp/ to send contents of tmp dir
|
||||||
, Param $ addTrailingPathSeparator tmp
|
, Param $ addTrailingPathSeparator tmp
|
||||||
, Param $ rsyncUrl o
|
, Param $ rsyncUrl o
|
||||||
]
|
]
|
||||||
return res
|
|
||||||
where
|
where
|
||||||
f = keyFile k
|
f = keyFile k
|
||||||
|
|
|
@ -52,7 +52,7 @@ gen r u c = do
|
||||||
cst <- remoteCost r expensiveRemoteCost
|
cst <- remoteCost r expensiveRemoteCost
|
||||||
return $ gen' r u c cst
|
return $ gen' r u c cst
|
||||||
gen' :: Git.Repo -> UUID -> Maybe RemoteConfig -> Int -> Remote Annex
|
gen' :: Git.Repo -> UUID -> Maybe RemoteConfig -> Int -> Remote Annex
|
||||||
gen' r u c cst = do
|
gen' r u c cst =
|
||||||
encryptableRemote c
|
encryptableRemote c
|
||||||
(storeEncrypted this)
|
(storeEncrypted this)
|
||||||
(retrieveEncrypted this)
|
(retrieveEncrypted this)
|
||||||
|
@ -85,7 +85,7 @@ s3Setup u c = handlehost $ M.lookup "host" c
|
||||||
|
|
||||||
handlehost Nothing = defaulthost
|
handlehost Nothing = defaulthost
|
||||||
handlehost (Just h)
|
handlehost (Just h)
|
||||||
| ".archive.org" `isSuffixOf` (map toLower h) = archiveorg
|
| ".archive.org" `isSuffixOf` map toLower h = archiveorg
|
||||||
| otherwise = defaulthost
|
| otherwise = defaulthost
|
||||||
|
|
||||||
use fullconfig = do
|
use fullconfig = do
|
||||||
|
@ -99,7 +99,7 @@ s3Setup u c = handlehost $ M.lookup "host" c
|
||||||
use fullconfig
|
use fullconfig
|
||||||
|
|
||||||
archiveorg = do
|
archiveorg = do
|
||||||
showNote $ "Internet Archive mode"
|
showNote "Internet Archive mode"
|
||||||
maybe (error "specify bucket=") (const $ return ()) $
|
maybe (error "specify bucket=") (const $ return ()) $
|
||||||
M.lookup "bucket" archiveconfig
|
M.lookup "bucket" archiveconfig
|
||||||
use archiveconfig
|
use archiveconfig
|
||||||
|
@ -203,10 +203,8 @@ s3Error :: ReqError -> a
|
||||||
s3Error e = error $ prettyReqError e
|
s3Error e = error $ prettyReqError e
|
||||||
|
|
||||||
s3Bool :: AWSResult () -> Annex Bool
|
s3Bool :: AWSResult () -> Annex Bool
|
||||||
s3Bool res = do
|
s3Bool (Right _) = return True
|
||||||
case res of
|
s3Bool (Left e) = s3Warning e
|
||||||
Right _ -> return True
|
|
||||||
Left e -> s3Warning e
|
|
||||||
|
|
||||||
s3Action :: Remote Annex -> a -> ((AWSConnection, String) -> Annex a) -> Annex a
|
s3Action :: Remote Annex -> a -> ((AWSConnection, String) -> Annex a) -> Annex a
|
||||||
s3Action r noconn action = do
|
s3Action r noconn action = do
|
||||||
|
@ -219,7 +217,7 @@ s3Action r noconn action = do
|
||||||
_ -> return noconn
|
_ -> return noconn
|
||||||
|
|
||||||
bucketFile :: Remote Annex -> Key -> FilePath
|
bucketFile :: Remote Annex -> Key -> FilePath
|
||||||
bucketFile r k = (munge $ show k)
|
bucketFile r = munge . show
|
||||||
where
|
where
|
||||||
munge s = case M.lookup "mungekeys" $ fromJust $ config r of
|
munge s = case M.lookup "mungekeys" $ fromJust $ config r of
|
||||||
Just "ia" -> iaMunge s
|
Just "ia" -> iaMunge s
|
||||||
|
@ -271,8 +269,8 @@ s3Connection c = do
|
||||||
warning $ "Set both " ++ s3AccessKey ++ " and " ++ s3SecretKey ++ " to use S3"
|
warning $ "Set both " ++ s3AccessKey ++ " and " ++ s3SecretKey ++ " to use S3"
|
||||||
return Nothing
|
return Nothing
|
||||||
where
|
where
|
||||||
host = fromJust $ (M.lookup "host" c)
|
host = fromJust $ M.lookup "host" c
|
||||||
port = let s = fromJust $ (M.lookup "port" c) in
|
port = let s = fromJust $ M.lookup "port" c in
|
||||||
case reads s of
|
case reads s of
|
||||||
[(p, _)] -> p
|
[(p, _)] -> p
|
||||||
_ -> error $ "bad S3 port value: " ++ s
|
_ -> error $ "bad S3 port value: " ++ s
|
||||||
|
@ -283,7 +281,7 @@ s3GetCreds :: RemoteConfig -> Annex (Maybe (String, String))
|
||||||
s3GetCreds c = do
|
s3GetCreds c = do
|
||||||
ak <- getEnvKey s3AccessKey
|
ak <- getEnvKey s3AccessKey
|
||||||
sk <- getEnvKey s3SecretKey
|
sk <- getEnvKey s3SecretKey
|
||||||
if (null ak || null sk)
|
if null ak || null sk
|
||||||
then do
|
then do
|
||||||
mcipher <- remoteCipher c
|
mcipher <- remoteCipher c
|
||||||
case (M.lookup "s3creds" c, mcipher) of
|
case (M.lookup "s3creds" c, mcipher) of
|
||||||
|
@ -291,9 +289,7 @@ s3GetCreds c = do
|
||||||
s <- liftIO $ withDecryptedContent cipher
|
s <- liftIO $ withDecryptedContent cipher
|
||||||
(return $ L.pack $ fromB64 encrypted)
|
(return $ L.pack $ fromB64 encrypted)
|
||||||
(return . L.unpack)
|
(return . L.unpack)
|
||||||
let line = lines s
|
let [ak', sk', _rest] = lines s
|
||||||
let ak' = line !! 0
|
|
||||||
let sk' = line !! 1
|
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
setEnv s3AccessKey ak True
|
setEnv s3AccessKey ak True
|
||||||
setEnv s3SecretKey sk True
|
setEnv s3SecretKey sk True
|
||||||
|
|
|
@ -38,7 +38,7 @@ gitConfigSpecialRemote u c k v = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
Git.run g "config" [Param (configsetting $ "annex-"++k), Param v]
|
Git.run g "config" [Param (configsetting $ "annex-"++k), Param v]
|
||||||
Git.run g "config" [Param (configsetting $ "annex-uuid"), Param u]
|
Git.run g "config" [Param (configsetting "annex-uuid"), Param u]
|
||||||
where
|
where
|
||||||
remotename = fromJust (M.lookup "name" c)
|
remotename = fromJust (M.lookup "name" c)
|
||||||
configsetting s = "remote." ++ remotename ++ "." ++ s
|
configsetting s = "remote." ++ remotename ++ "." ++ s
|
||||||
|
|
|
@ -39,7 +39,7 @@ git_annex_shell r command params
|
||||||
where
|
where
|
||||||
dir = Git.workTree r
|
dir = Git.workTree r
|
||||||
shellcmd = "git-annex-shell"
|
shellcmd = "git-annex-shell"
|
||||||
shellopts = (Param command):(File dir):params
|
shellopts = Param command : File dir : params
|
||||||
sshcmd = shellcmd ++ " " ++
|
sshcmd = shellcmd ++ " " ++
|
||||||
unwords (map shellEscape $ toCommand shellopts)
|
unwords (map shellEscape $ toCommand shellopts)
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ webUUID = "00000000-0000-0000-0000-000000000001"
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex (Remote Annex)
|
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex (Remote Annex)
|
||||||
gen r _ _ =
|
gen r _ _ =
|
||||||
return $ Remote {
|
return Remote {
|
||||||
uuid = webUUID,
|
uuid = webUUID,
|
||||||
cost = expensiveRemoteCost,
|
cost = expensiveRemoteCost,
|
||||||
name = Git.repoDescribe r,
|
name = Git.repoDescribe r,
|
||||||
|
@ -111,7 +111,7 @@ checkKey' (u:us) = do
|
||||||
if e then return e else checkKey' us
|
if e then return e else checkKey' us
|
||||||
|
|
||||||
urlexists :: URLString -> IO Bool
|
urlexists :: URLString -> IO Bool
|
||||||
urlexists url = do
|
urlexists url =
|
||||||
case parseURI url of
|
case parseURI url of
|
||||||
Nothing -> return False
|
Nothing -> return False
|
||||||
Just u -> do
|
Just u -> do
|
||||||
|
|
|
@ -15,6 +15,7 @@ module Touch (
|
||||||
|
|
||||||
import Foreign
|
import Foreign
|
||||||
import Foreign.C
|
import Foreign.C
|
||||||
|
import Control.Monad (when)
|
||||||
|
|
||||||
newtype TimeSpec = TimeSpec CTime
|
newtype TimeSpec = TimeSpec CTime
|
||||||
|
|
||||||
|
@ -66,9 +67,7 @@ touchBoth file atime mtime follow =
|
||||||
withCString file $ \f -> do
|
withCString file $ \f -> do
|
||||||
pokeArray ptr [atime, mtime]
|
pokeArray ptr [atime, mtime]
|
||||||
r <- c_utimensat at_fdcwd f ptr flags
|
r <- c_utimensat at_fdcwd f ptr flags
|
||||||
if (r /= 0)
|
when (r /= 0) $ throwErrno "touchBoth"
|
||||||
then throwErrno "touchBoth"
|
|
||||||
else return ()
|
|
||||||
where
|
where
|
||||||
flags = if follow
|
flags = if follow
|
||||||
then 0
|
then 0
|
||||||
|
|
|
@ -20,10 +20,8 @@ copyFile src dest = do
|
||||||
removeFile dest
|
removeFile dest
|
||||||
boolSystem "cp" [params, File src, File dest]
|
boolSystem "cp" [params, File src, File dest]
|
||||||
where
|
where
|
||||||
params = if SysConfig.cp_reflink_auto
|
params
|
||||||
then Params "--reflink=auto"
|
| SysConfig.cp_reflink_auto = Params "--reflink=auto"
|
||||||
else if SysConfig.cp_a
|
| SysConfig.cp_a = Params "-a"
|
||||||
then Params "-a"
|
| SysConfig.cp_p = Params "-p"
|
||||||
else if SysConfig.cp_p
|
| otherwise = Params ""
|
||||||
then Params "-p"
|
|
||||||
else Params ""
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ oldSchoolUnits = map mingle $ zip storageUnits memoryUnits
|
||||||
{- approximate display of a particular number of bytes -}
|
{- approximate display of a particular number of bytes -}
|
||||||
roughSize :: [Unit] -> Bool -> ByteSize -> String
|
roughSize :: [Unit] -> Bool -> ByteSize -> String
|
||||||
roughSize units abbrev i
|
roughSize units abbrev i
|
||||||
| i < 0 = "-" ++ findUnit units' (negate i)
|
| i < 0 = '-' : findUnit units' (negate i)
|
||||||
| otherwise = findUnit units' i
|
| otherwise = findUnit units' i
|
||||||
where
|
where
|
||||||
units' = reverse $ sort units -- largest first
|
units' = reverse $ sort units -- largest first
|
||||||
|
@ -139,10 +139,10 @@ readSize :: [Unit] -> String -> Maybe ByteSize
|
||||||
readSize units input
|
readSize units input
|
||||||
| null parsednum = Nothing
|
| null parsednum = Nothing
|
||||||
| null parsedunit = Nothing
|
| null parsedunit = Nothing
|
||||||
| otherwise = Just $ round $ number * (fromIntegral multiplier)
|
| otherwise = Just $ round $ number * fromIntegral multiplier
|
||||||
where
|
where
|
||||||
(number, rest) = head parsednum
|
(number, rest) = head parsednum
|
||||||
multiplier = head $ parsedunit
|
multiplier = head parsedunit
|
||||||
unitname = takeWhile isAlpha $ dropWhile isSpace rest
|
unitname = takeWhile isAlpha $ dropWhile isSpace rest
|
||||||
|
|
||||||
parsednum = reads input :: [(Double, String)]
|
parsednum = reads input :: [(Double, String)]
|
||||||
|
|
|
@ -20,13 +20,13 @@ graphNode nodeid desc = label desc $ quote nodeid
|
||||||
|
|
||||||
{- an edge between two nodes -}
|
{- an edge between two nodes -}
|
||||||
graphEdge :: String -> String -> Maybe String -> String
|
graphEdge :: String -> String -> Maybe String -> String
|
||||||
graphEdge fromid toid desc = indent $ maybe edge (\d -> label d edge) desc
|
graphEdge fromid toid desc = indent $ maybe edge (`label` edge) desc
|
||||||
where
|
where
|
||||||
edge = quote fromid ++ " -> " ++ quote toid
|
edge = quote fromid ++ " -> " ++ quote toid
|
||||||
|
|
||||||
{- adds a label to a node or edge -}
|
{- adds a label to a node or edge -}
|
||||||
label :: String -> String -> String
|
label :: String -> String -> String
|
||||||
label l s = attr "label" l s
|
label = attr "label"
|
||||||
|
|
||||||
{- adds an attribute to a node or edge
|
{- adds an attribute to a node or edge
|
||||||
- (can be called multiple times for multiple attributes) -}
|
- (can be called multiple times for multiple attributes) -}
|
||||||
|
@ -35,7 +35,7 @@ attr a v s = s ++ " [ " ++ a ++ "=" ++ quote v ++ " ]"
|
||||||
|
|
||||||
{- fills a node with a color -}
|
{- fills a node with a color -}
|
||||||
fillColor :: String -> String -> String
|
fillColor :: String -> String -> String
|
||||||
fillColor color s = attr "fillcolor" color $ attr "style" "filled" $ s
|
fillColor color s = attr "fillcolor" color $ attr "style" "filled" s
|
||||||
|
|
||||||
{- apply to graphNode to put the node in a labeled box -}
|
{- apply to graphNode to put the node in a labeled box -}
|
||||||
subGraph :: String -> String -> String -> String -> String
|
subGraph :: String -> String -> String -> String -> String
|
||||||
|
@ -52,10 +52,10 @@ subGraph subid l color s =
|
||||||
setlabel = "label=" ++ quote l
|
setlabel = "label=" ++ quote l
|
||||||
setfilled = "style=" ++ quote "filled"
|
setfilled = "style=" ++ quote "filled"
|
||||||
setcolor = "fillcolor=" ++ quote color
|
setcolor = "fillcolor=" ++ quote color
|
||||||
ii x = (indent $ indent x) ++ "\n"
|
ii x = indent (indent x) ++ "\n"
|
||||||
|
|
||||||
indent ::String -> String
|
indent ::String -> String
|
||||||
indent s = "\t" ++ s
|
indent s = '\t' : s
|
||||||
|
|
||||||
quote :: String -> String
|
quote :: String -> String
|
||||||
quote s = "\"" ++ s' ++ "\""
|
quote s = "\"" ++ s' ++ "\""
|
||||||
|
|
|
@ -19,7 +19,7 @@ rsyncShell command = [Param "-e", Param $ unwords $ map escape (toCommand comman
|
||||||
{- rsync requires some weird, non-shell like quoting in
|
{- rsync requires some weird, non-shell like quoting in
|
||||||
- here. A doubled single quote inside the single quoted
|
- here. A doubled single quote inside the single quoted
|
||||||
- string is a single quote. -}
|
- string is a single quote. -}
|
||||||
escape s = "'" ++ (join "''" $ split "'" s) ++ "'"
|
escape s = "'" ++ join "''" (split "'" s) ++ "'"
|
||||||
|
|
||||||
{- Runs rsync in server mode to send a file, and exits. -}
|
{- Runs rsync in server mode to send a file, and exits. -}
|
||||||
rsyncServerSend :: FilePath -> IO ()
|
rsyncServerSend :: FilePath -> IO ()
|
||||||
|
|
Loading…
Add table
Reference in a new issue