add routes to pause/start/cancel transfers
This commit includes a paydown on technical debt incurred two years ago, when I didn't know that it was bad to make custom Read and Show instances for types. As the routes need Read and Show for Transfer, which includes a Key, and deriving my own Read instance of key was not practical, I had to finally clean that up. So the compact Key read and show functions are now file2key and key2file, and Read and Show are now derived instances. Changed all code that used the old instances, compiler checked. (There were a few places, particularly in Command.Unused, and the test suite where the Show instance continue to be used for legitimate comparisons; ie show key_x == show key_y (though really in a bloom filter))
This commit is contained in:
parent
e0cd977669
commit
94fcd0cf59
27 changed files with 118 additions and 68 deletions
|
@ -19,6 +19,7 @@ import Assistant.Alert
|
||||||
import Utility.NotificationBroadcaster
|
import Utility.NotificationBroadcaster
|
||||||
import Utility.WebApp
|
import Utility.WebApp
|
||||||
import Utility.Yesod
|
import Utility.Yesod
|
||||||
|
import Logs.Transfer
|
||||||
|
|
||||||
import Yesod
|
import Yesod
|
||||||
import Yesod.Static
|
import Yesod.Static
|
||||||
|
@ -154,6 +155,10 @@ instance PathPiece AlertId where
|
||||||
toPathPiece = pack . show
|
toPathPiece = pack . show
|
||||||
fromPathPiece = readish . unpack
|
fromPathPiece = readish . unpack
|
||||||
|
|
||||||
|
instance PathPiece Transfer where
|
||||||
|
toPathPiece = pack . show
|
||||||
|
fromPathPiece = readish . unpack
|
||||||
|
|
||||||
{- Adds the auth parameter as a hidden field on a form. Must be put into
|
{- Adds the auth parameter as a hidden field on a form. Must be put into
|
||||||
- every form. -}
|
- every form. -}
|
||||||
webAppFormAuthToken :: Widget
|
webAppFormAuthToken :: Widget
|
||||||
|
|
|
@ -42,13 +42,18 @@ transfersDisplay warnNoScript = do
|
||||||
queued <- liftIO $ getTransferQueue $ transferQueue webapp
|
queued <- liftIO $ getTransferQueue $ transferQueue webapp
|
||||||
let ident = "transfers"
|
let ident = "transfers"
|
||||||
autoUpdate ident NotifierTransfersR (10 :: Int) (10 :: Int)
|
autoUpdate ident NotifierTransfersR (10 :: Int) (10 :: Int)
|
||||||
let transfers = current ++ queued
|
let transfers = current ++ queued ++ dummy
|
||||||
if null transfers
|
if null transfers
|
||||||
then ifM (lift $ showIntro <$> getWebAppState)
|
then ifM (lift $ showIntro <$> getWebAppState)
|
||||||
( introDisplay ident
|
( introDisplay ident
|
||||||
, $(widgetFile "dashboard/transfers")
|
, $(widgetFile "dashboard/transfers")
|
||||||
)
|
)
|
||||||
else $(widgetFile "dashboard/transfers")
|
else $(widgetFile "dashboard/transfers")
|
||||||
|
where
|
||||||
|
dummy = [(t, i), (t, i)]
|
||||||
|
t = Transfer Download (UUID "00000000-0000-0000-0000-000000000001") k
|
||||||
|
k = Types.Key.Key "foo" "bar" Nothing Nothing
|
||||||
|
i = TransferInfo Nothing Nothing Nothing Nothing Nothing Nothing
|
||||||
|
|
||||||
{- Called by client to get a display of currently in process transfers.
|
{- Called by client to get a display of currently in process transfers.
|
||||||
-
|
-
|
||||||
|
@ -98,7 +103,10 @@ postFileBrowserR = void openFileBrowser
|
||||||
{- Used by non-javascript browsers, where clicking on the link actually
|
{- Used by non-javascript browsers, where clicking on the link actually
|
||||||
- opens this page, so we redirect back to the referrer. -}
|
- opens this page, so we redirect back to the referrer. -}
|
||||||
getFileBrowserR :: Handler ()
|
getFileBrowserR :: Handler ()
|
||||||
getFileBrowserR = whenM openFileBrowser $ do
|
getFileBrowserR = whenM openFileBrowser $ redirectBack
|
||||||
|
|
||||||
|
redirectBack :: Handler ()
|
||||||
|
redirectBack = do
|
||||||
clearUltDest
|
clearUltDest
|
||||||
setUltDestReferer
|
setUltDestReferer
|
||||||
redirectUltDest HomeR
|
redirectUltDest HomeR
|
||||||
|
@ -130,3 +138,27 @@ openFileBrowser = do
|
||||||
#else
|
#else
|
||||||
cmd = "xdg-open"
|
cmd = "xdg-open"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
{- Transfer controls. The GET is done in noscript mode and redirects back
|
||||||
|
- to the referring page. The POST is called by javascript. -}
|
||||||
|
getPauseTransferR :: Transfer -> Handler ()
|
||||||
|
getPauseTransferR t = pauseTransfer t >> redirectBack
|
||||||
|
postPauseTransferR :: Transfer -> Handler ()
|
||||||
|
postPauseTransferR t = pauseTransfer t
|
||||||
|
getStartTransferR :: Transfer -> Handler ()
|
||||||
|
getStartTransferR t = startTransfer t >> redirectBack
|
||||||
|
postStartTransferR :: Transfer -> Handler ()
|
||||||
|
postStartTransferR t = startTransfer t
|
||||||
|
getCancelTransferR :: Transfer -> Handler ()
|
||||||
|
getCancelTransferR t = cancelTransfer t >> redirectBack
|
||||||
|
postCancelTransferR :: Transfer -> Handler ()
|
||||||
|
postCancelTransferR t = cancelTransfer t
|
||||||
|
|
||||||
|
pauseTransfer :: Transfer -> Handler ()
|
||||||
|
pauseTransfer t = liftIO $ putStrLn "pause"
|
||||||
|
|
||||||
|
startTransfer :: Transfer -> Handler ()
|
||||||
|
startTransfer t = liftIO $ putStrLn "start"
|
||||||
|
|
||||||
|
cancelTransfer :: Transfer -> Handler ()
|
||||||
|
cancelTransfer t = liftIO $ putStrLn "cancel"
|
||||||
|
|
|
@ -15,4 +15,8 @@
|
||||||
/closealert/#AlertId CloseAlert GET
|
/closealert/#AlertId CloseAlert GET
|
||||||
/filebrowser FileBrowserR GET POST
|
/filebrowser FileBrowserR GET POST
|
||||||
|
|
||||||
|
/transfer/pause/#Transfer PauseTransferR GET POST
|
||||||
|
/transfer/start/#Transfer StartTransferR GET POST
|
||||||
|
/transfer/cancel/#Transfer CancelTransferR GET POST
|
||||||
|
|
||||||
/static StaticR Static getStatic
|
/static StaticR Static getStatic
|
||||||
|
|
|
@ -11,6 +11,7 @@ import Common.Annex
|
||||||
import Logs.Unused
|
import Logs.Unused
|
||||||
import Command
|
import Command
|
||||||
import qualified Command.Add
|
import qualified Command.Add
|
||||||
|
import Types.Key
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [command "addunused" (paramRepeating paramNumRange)
|
def = [command "addunused" (paramRepeating paramNumRange)
|
||||||
|
@ -25,7 +26,7 @@ start = startUnused "addunused" perform (performOther "bad") (performOther "tmp"
|
||||||
perform :: Key -> CommandPerform
|
perform :: Key -> CommandPerform
|
||||||
perform key = next $ Command.Add.cleanup file key True
|
perform key = next $ Command.Add.cleanup file key True
|
||||||
where
|
where
|
||||||
file = "unused." ++ show key
|
file = "unused." ++ key2file key
|
||||||
|
|
||||||
{- The content is not in the annex, but in another directory, and
|
{- The content is not in the annex, but in another directory, and
|
||||||
- it seems better to error out, rather than moving bad/tmp content into
|
- it seems better to error out, rather than moving bad/tmp content into
|
||||||
|
|
|
@ -12,6 +12,7 @@ import Command
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import Logs.Location
|
import Logs.Location
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
|
import Types.Key
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [oneShot $ command "dropkey" (paramRepeating paramKey) seek
|
def = [oneShot $ command "dropkey" (paramRepeating paramKey) seek
|
||||||
|
@ -24,7 +25,7 @@ start :: Key -> CommandStart
|
||||||
start key = stopUnless (inAnnex key) $ do
|
start key = stopUnless (inAnnex key) $ do
|
||||||
unlessM (Annex.getState Annex.force) $
|
unlessM (Annex.getState Annex.force) $
|
||||||
error "dropkey can cause data loss; use --force if you're sure you want to do this"
|
error "dropkey can cause data loss; use --force if you're sure you want to do this"
|
||||||
showStart "dropkey" (show key)
|
showStart "dropkey" (key2file key)
|
||||||
next $ perform key
|
next $ perform key
|
||||||
|
|
||||||
perform :: Key -> CommandPerform
|
perform :: Key -> CommandPerform
|
||||||
|
|
|
@ -53,7 +53,7 @@ start format file (key, _) = do
|
||||||
where
|
where
|
||||||
vars =
|
vars =
|
||||||
[ ("file", file)
|
[ ("file", file)
|
||||||
, ("key", show key)
|
, ("key", key2file key)
|
||||||
, ("backend", keyBackendName key)
|
, ("backend", keyBackendName key)
|
||||||
, ("bytesize", size show)
|
, ("bytesize", size show)
|
||||||
, ("humansize", size $ roughSize storageUnits True)
|
, ("humansize", size $ roughSize storageUnits True)
|
||||||
|
|
|
@ -22,7 +22,7 @@ seek = [withWords start]
|
||||||
|
|
||||||
start :: [String] -> CommandStart
|
start :: [String] -> CommandStart
|
||||||
start (keyname:file:[]) = notBareRepo $ do
|
start (keyname:file:[]) = notBareRepo $ do
|
||||||
let key = fromMaybe (error "bad key") $ readKey keyname
|
let key = fromMaybe (error "bad key") $ file2key keyname
|
||||||
inbackend <- inAnnex key
|
inbackend <- inAnnex key
|
||||||
unless inbackend $ error $
|
unless inbackend $ error $
|
||||||
"key ("++ keyname ++") is not present in backend"
|
"key ("++ keyname ++") is not present in backend"
|
||||||
|
|
|
@ -26,6 +26,7 @@ import Utility.DataUnits
|
||||||
import Utility.FileMode
|
import Utility.FileMode
|
||||||
import Config
|
import Config
|
||||||
import qualified Option
|
import qualified Option
|
||||||
|
import Types.Key
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [withOptions options $ command "fsck" paramPaths seek
|
def = [withOptions options $ command "fsck" paramPaths seek
|
||||||
|
@ -114,7 +115,7 @@ startBare :: Key -> CommandStart
|
||||||
startBare key = case Backend.maybeLookupBackendName (Types.Key.keyBackendName key) of
|
startBare key = case Backend.maybeLookupBackendName (Types.Key.keyBackendName key) of
|
||||||
Nothing -> stop
|
Nothing -> stop
|
||||||
Just backend -> do
|
Just backend -> do
|
||||||
showStart "fsck" (show key)
|
showStart "fsck" (key2file key)
|
||||||
next $ performBare key backend
|
next $ performBare key backend
|
||||||
|
|
||||||
{- Note that numcopies cannot be checked in a bare repository, because
|
{- Note that numcopies cannot be checked in a bare repository, because
|
||||||
|
@ -122,7 +123,7 @@ startBare key = case Backend.maybeLookupBackendName (Types.Key.keyBackendName ke
|
||||||
- files. -}
|
- files. -}
|
||||||
performBare :: Key -> Backend -> CommandPerform
|
performBare :: Key -> Backend -> CommandPerform
|
||||||
performBare key backend = check
|
performBare key backend = check
|
||||||
[ verifyLocationLog key (show key)
|
[ verifyLocationLog key (key2file key)
|
||||||
, checkKeySize key
|
, checkKeySize key
|
||||||
, checkBackend backend key
|
, checkBackend backend key
|
||||||
]
|
]
|
||||||
|
|
|
@ -26,7 +26,7 @@ seek = [withPairs start]
|
||||||
start :: (FilePath, String) -> CommandStart
|
start :: (FilePath, String) -> CommandStart
|
||||||
start (file, keyname) = ifAnnexed file go stop
|
start (file, keyname) = ifAnnexed file go stop
|
||||||
where
|
where
|
||||||
newkey = fromMaybe (error "bad key") $ readKey keyname
|
newkey = fromMaybe (error "bad key") $ file2key keyname
|
||||||
go (oldkey, _)
|
go (oldkey, _)
|
||||||
| oldkey == newkey = stop
|
| oldkey == newkey = stop
|
||||||
| otherwise = do
|
| otherwise = do
|
||||||
|
|
|
@ -183,8 +183,8 @@ transfer_list = stat "transfers in progress" $ nojson $ lift $ do
|
||||||
pp _ c [] = c
|
pp _ c [] = c
|
||||||
pp uuidmap c ((t, i):xs) = "\n\t" ++ line uuidmap t i ++ pp uuidmap c xs
|
pp uuidmap c ((t, i):xs) = "\n\t" ++ line uuidmap t i ++ pp uuidmap c xs
|
||||||
line uuidmap t i = unwords
|
line uuidmap t i = unwords
|
||||||
[ show (transferDirection t) ++ "ing"
|
[ showLcDirection (transferDirection t) ++ "ing"
|
||||||
, fromMaybe (show $ transferKey t) (associatedFile i)
|
, fromMaybe (key2file $ transferKey t) (associatedFile i)
|
||||||
, if transferDirection t == Upload then "to" else "from"
|
, if transferDirection t == Upload then "to" else "from"
|
||||||
, maybe (fromUUID $ transferUUID t) Remote.name $
|
, maybe (fromUUID $ transferUUID t) Remote.name $
|
||||||
M.lookup (transferUUID t) uuidmap
|
M.lookup (transferUUID t) uuidmap
|
||||||
|
|
|
@ -25,6 +25,7 @@ import qualified Git
|
||||||
import Git.Types (BlobType(..))
|
import Git.Types (BlobType(..))
|
||||||
import qualified Types.Remote
|
import qualified Types.Remote
|
||||||
import qualified Remote.Git
|
import qualified Remote.Git
|
||||||
|
import Types.Key
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
|
@ -260,8 +261,8 @@ resolveMerge' u
|
||||||
-}
|
-}
|
||||||
mergeFile :: FilePath -> Key -> FilePath
|
mergeFile :: FilePath -> Key -> FilePath
|
||||||
mergeFile file key
|
mergeFile file key
|
||||||
| doubleconflict = go $ show key
|
| doubleconflict = go $ key2file key
|
||||||
| otherwise = go $ shortHash $ show key
|
| otherwise = go $ shortHash $ key2file key
|
||||||
where
|
where
|
||||||
varmarker = ".variant-"
|
varmarker = ".variant-"
|
||||||
doubleconflict = varmarker `isSuffixOf` (dropExtension file)
|
doubleconflict = varmarker `isSuffixOf` (dropExtension file)
|
||||||
|
|
|
@ -34,6 +34,7 @@ import qualified Remote
|
||||||
import qualified Annex.Branch
|
import qualified Annex.Branch
|
||||||
import qualified Option
|
import qualified Option
|
||||||
import Annex.CatFile
|
import Annex.CatFile
|
||||||
|
import Types.Key
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [withOptions [fromOption] $ command "unused" paramNothing seek
|
def = [withOptions [fromOption] $ command "unused" paramNothing seek
|
||||||
|
@ -100,7 +101,7 @@ number n (x:xs) = (n+1, x) : number (n+1) xs
|
||||||
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) ++ " " ++ key2file k
|
||||||
pad n s = s ++ replicate (n - length s) ' '
|
pad n s = s ++ replicate (n - length s) ' '
|
||||||
|
|
||||||
staleTmpMsg :: [(Int, Key)] -> String
|
staleTmpMsg :: [(Int, Key)] -> String
|
||||||
|
|
|
@ -112,7 +112,7 @@ decryptCipher (EncryptedCipher t _) = Cipher <$> Gpg.pipeStrict decrypt t
|
||||||
- on content. It does need to be repeatable. -}
|
- on content. It does need to be repeatable. -}
|
||||||
encryptKey :: Cipher -> Key -> Key
|
encryptKey :: Cipher -> Key -> Key
|
||||||
encryptKey c k = Key
|
encryptKey c k = Key
|
||||||
{ keyName = hmacWithCipher c (show k)
|
{ keyName = hmacWithCipher c (key2file k)
|
||||||
, keyBackendName = "GPGHMACSHA1"
|
, keyBackendName = "GPGHMACSHA1"
|
||||||
, keySize = Nothing -- size and mtime omitted
|
, keySize = Nothing -- size and mtime omitted
|
||||||
, keyMtime = Nothing -- to avoid leaking data
|
, keyMtime = Nothing -- to avoid leaking data
|
||||||
|
|
|
@ -199,7 +199,7 @@ isLinkToAnnex s = ('/':d) `isInfixOf` s || d `isPrefixOf` s
|
||||||
-}
|
-}
|
||||||
keyFile :: Key -> FilePath
|
keyFile :: Key -> FilePath
|
||||||
keyFile key = replace "/" "%" $ replace ":" "&c" $
|
keyFile key = replace "/" "%" $ replace ":" "&c" $
|
||||||
replace "%" "&s" $ replace "&" "&a" $ show key
|
replace "%" "&s" $ replace "&" "&a" $ key2file key
|
||||||
|
|
||||||
{- A location to store a key on the filesystem. A directory hash is used,
|
{- A location to store a key on the filesystem. A directory hash is used,
|
||||||
- to protect against filesystems that dislike having many items in a
|
- to protect against filesystems that dislike having many items in a
|
||||||
|
@ -220,7 +220,7 @@ keyPaths key = map (keyPath key) annexHashes
|
||||||
{- Reverses keyFile, converting a filename fragment (ie, the basename of
|
{- Reverses keyFile, converting a filename fragment (ie, the basename of
|
||||||
- the symlink target) into a key. -}
|
- the symlink target) into a key. -}
|
||||||
fileKey :: FilePath -> Maybe Key
|
fileKey :: FilePath -> Maybe Key
|
||||||
fileKey file = readKey $
|
fileKey file = file2key $
|
||||||
replace "&a" "&" $ replace "&s" "%" $
|
replace "&a" "&" $ replace "&s" "%" $
|
||||||
replace "&c" ":" $ replace "%" "/" file
|
replace "&c" ":" $ replace "%" "/" file
|
||||||
|
|
||||||
|
@ -242,12 +242,12 @@ hashDirMixed :: Hasher
|
||||||
hashDirMixed k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir
|
hashDirMixed k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir
|
||||||
where
|
where
|
||||||
dir = take 4 $ display_32bits_as_dir =<< [a,b,c,d]
|
dir = take 4 $ display_32bits_as_dir =<< [a,b,c,d]
|
||||||
ABCD (a,b,c,d) = md5 $ encodeFilePath $ show k
|
ABCD (a,b,c,d) = md5 $ encodeFilePath $ key2file k
|
||||||
|
|
||||||
hashDirLower :: Hasher
|
hashDirLower :: Hasher
|
||||||
hashDirLower k = addTrailingPathSeparator $ take 3 dir </> drop 3 dir
|
hashDirLower k = addTrailingPathSeparator $ take 3 dir </> drop 3 dir
|
||||||
where
|
where
|
||||||
dir = take 6 $ md5s $ encodeFilePath $ show k
|
dir = take 6 $ md5s $ encodeFilePath $ key2file k
|
||||||
|
|
||||||
{- modified version of display_32bits_as_hex from Data.Hash.MD5
|
{- modified version of display_32bits_as_hex from Data.Hash.MD5
|
||||||
- Copyright (C) 2001 Ian Lynagh
|
- Copyright (C) 2001 Ian Lynagh
|
||||||
|
|
|
@ -30,7 +30,7 @@ data Transfer = Transfer
|
||||||
, transferUUID :: UUID
|
, transferUUID :: UUID
|
||||||
, transferKey :: Key
|
, transferKey :: Key
|
||||||
}
|
}
|
||||||
deriving (Show, Eq, Ord)
|
deriving (Eq, Ord, Read, Show)
|
||||||
|
|
||||||
{- Information about a Transfer, stored in the transfer information file.
|
{- Information about a Transfer, stored in the transfer information file.
|
||||||
-
|
-
|
||||||
|
@ -49,16 +49,16 @@ data TransferInfo = TransferInfo
|
||||||
deriving (Show, Eq, Ord)
|
deriving (Show, Eq, Ord)
|
||||||
|
|
||||||
data Direction = Upload | Download
|
data Direction = Upload | Download
|
||||||
deriving (Eq, Ord)
|
deriving (Eq, Ord, Read, Show)
|
||||||
|
|
||||||
instance Show Direction where
|
showLcDirection :: Direction -> String
|
||||||
show Upload = "upload"
|
showLcDirection Upload = "upload"
|
||||||
show Download = "download"
|
showLcDirection Download = "download"
|
||||||
|
|
||||||
readDirection :: String -> Maybe Direction
|
readLcDirection :: String -> Maybe Direction
|
||||||
readDirection "upload" = Just Upload
|
readLcDirection "upload" = Just Upload
|
||||||
readDirection "download" = Just Download
|
readLcDirection "download" = Just Download
|
||||||
readDirection _ = Nothing
|
readLcDirection _ = Nothing
|
||||||
|
|
||||||
percentComplete :: Transfer -> TransferInfo -> Maybe Percentage
|
percentComplete :: Transfer -> TransferInfo -> Maybe Percentage
|
||||||
percentComplete (Transfer { transferKey = key }) (TransferInfo { bytesComplete = Just complete }) =
|
percentComplete (Transfer { transferKey = key }) (TransferInfo { bytesComplete = Just complete }) =
|
||||||
|
@ -144,7 +144,7 @@ getTransfers = do
|
||||||
{- The transfer information file to use for a given Transfer. -}
|
{- The transfer information file to use for a given Transfer. -}
|
||||||
transferFile :: Transfer -> Git.Repo -> FilePath
|
transferFile :: Transfer -> Git.Repo -> FilePath
|
||||||
transferFile (Transfer direction u key) r = gitAnnexTransferDir r
|
transferFile (Transfer direction u key) r = gitAnnexTransferDir r
|
||||||
</> show direction
|
</> showLcDirection direction
|
||||||
</> fromUUID u
|
</> fromUUID u
|
||||||
</> keyFile key
|
</> keyFile key
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ parseTransferFile file
|
||||||
| "lck." `isPrefixOf` (takeFileName file) = Nothing
|
| "lck." `isPrefixOf` (takeFileName file) = Nothing
|
||||||
| otherwise = case drop (length bits - 3) bits of
|
| otherwise = case drop (length bits - 3) bits of
|
||||||
[direction, u, key] -> Transfer
|
[direction, u, key] -> Transfer
|
||||||
<$> readDirection direction
|
<$> readLcDirection direction
|
||||||
<*> pure (toUUID u)
|
<*> pure (toUUID u)
|
||||||
<*> fileKey key
|
<*> fileKey key
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
|
@ -25,7 +25,7 @@ writeUnusedLog :: FilePath -> [(Int, Key)] -> Annex ()
|
||||||
writeUnusedLog prefix l = do
|
writeUnusedLog prefix l = do
|
||||||
logfile <- fromRepo $ gitAnnexUnusedLog prefix
|
logfile <- fromRepo $ gitAnnexUnusedLog prefix
|
||||||
liftIO $ viaTmp writeFile logfile $
|
liftIO $ viaTmp writeFile logfile $
|
||||||
unlines $ map (\(n, k) -> show n ++ " " ++ show k) l
|
unlines $ map (\(n, k) -> show n ++ " " ++ key2file k) l
|
||||||
|
|
||||||
readUnusedLog :: FilePath -> Annex UnusedMap
|
readUnusedLog :: FilePath -> Annex UnusedMap
|
||||||
readUnusedLog prefix = do
|
readUnusedLog prefix = do
|
||||||
|
@ -37,7 +37,7 @@ readUnusedLog prefix = do
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
parse line =
|
parse line =
|
||||||
case (readish tag, readKey rest) of
|
case (readish tag, file2key rest) of
|
||||||
(Just num, Just key) -> Just (num, key)
|
(Just num, Just key) -> Just (num, key)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
where
|
where
|
||||||
|
|
|
@ -16,6 +16,7 @@ module Logs.Web (
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Logs.Presence
|
import Logs.Presence
|
||||||
import Logs.Location
|
import Logs.Location
|
||||||
|
import Types.Key
|
||||||
|
|
||||||
type URLString = String
|
type URLString = String
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ urlLog key = hashDirLower key </> keyFile key ++ ".log.web"
|
||||||
{- Used to store the urls elsewhere. -}
|
{- Used to store the urls elsewhere. -}
|
||||||
oldurlLogs :: Key -> [FilePath]
|
oldurlLogs :: Key -> [FilePath]
|
||||||
oldurlLogs key =
|
oldurlLogs key =
|
||||||
[ "remote/web" </> hashDirLower key </> show key ++ ".log"
|
[ "remote/web" </> hashDirLower key </> key2file key ++ ".log"
|
||||||
, "remote/web" </> hashDirLower key </> keyFile key ++ ".log"
|
, "remote/web" </> hashDirLower key </> keyFile key ++ ".log"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import System.Process
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Types.Remote
|
import Types.Remote
|
||||||
|
import Types.Key
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import qualified Git.Command
|
import qualified Git.Command
|
||||||
import qualified Git.Config
|
import qualified Git.Config
|
||||||
|
@ -243,7 +244,7 @@ bupRef k
|
||||||
| Git.Ref.legal True shown = shown
|
| Git.Ref.legal True shown = shown
|
||||||
| otherwise = "git-annex-" ++ showDigest (sha256 (fromString shown))
|
| otherwise = "git-annex-" ++ showDigest (sha256 (fromString shown))
|
||||||
where
|
where
|
||||||
shown = show k
|
shown = key2file k
|
||||||
|
|
||||||
bupLocal :: BupRepo -> Bool
|
bupLocal :: BupRepo -> Bool
|
||||||
bupLocal = notElem ':'
|
bupLocal = notElem ':'
|
||||||
|
|
|
@ -183,7 +183,7 @@ inAnnex r key
|
||||||
v -> return v
|
v -> return v
|
||||||
checkremote = do
|
checkremote = do
|
||||||
showAction $ "checking " ++ Git.repoDescribe r
|
showAction $ "checking " ++ Git.repoDescribe r
|
||||||
onRemote r (check, unknown) "inannex" [Param (show key)] []
|
onRemote r (check, unknown) "inannex" [Param (key2file key)] []
|
||||||
where
|
where
|
||||||
check c p = dispatch <$> safeSystem c p
|
check c p = dispatch <$> safeSystem c p
|
||||||
dispatch ExitSuccess = Right True
|
dispatch ExitSuccess = Right True
|
||||||
|
@ -228,7 +228,7 @@ dropKey r key
|
||||||
| Git.repoIsHttp r = error "dropping from http repo not supported"
|
| Git.repoIsHttp r = error "dropping from http repo not supported"
|
||||||
| otherwise = commitOnCleanup r $ onRemote r (boolSystem, False) "dropkey"
|
| otherwise = commitOnCleanup r $ onRemote r (boolSystem, False) "dropkey"
|
||||||
[ Params "--quiet --force"
|
[ Params "--quiet --force"
|
||||||
, Param $ show key
|
, Param $ key2file key
|
||||||
]
|
]
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ rsyncParamsRemote r sending key file afile = do
|
||||||
: maybe [] (\f -> [(Fields.associatedFile, f)]) afile
|
: maybe [] (\f -> [(Fields.associatedFile, f)]) afile
|
||||||
Just (shellcmd, shellparams) <- git_annex_shell r
|
Just (shellcmd, shellparams) <- git_annex_shell r
|
||||||
(if sending then "sendkey" else "recvkey")
|
(if sending then "sendkey" else "recvkey")
|
||||||
[ Param $ show key ]
|
[ Param $ key2file key ]
|
||||||
fields
|
fields
|
||||||
-- Convert the ssh command into rsync command line.
|
-- Convert the ssh command into rsync command line.
|
||||||
let eparam = rsyncShell (Param shellcmd:shellparams)
|
let eparam = rsyncShell (Param shellcmd:shellparams)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import System.Environment
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Types.Remote
|
import Types.Remote
|
||||||
|
import Types.Key
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import Config
|
import Config
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
|
@ -68,7 +69,7 @@ hookEnv k f = Just <$> mergeenv (fileenv f ++ keyenv)
|
||||||
<$> M.fromList <$> getEnvironment
|
<$> M.fromList <$> getEnvironment
|
||||||
env s v = ("ANNEX_" ++ s, v)
|
env s v = ("ANNEX_" ++ s, v)
|
||||||
keyenv =
|
keyenv =
|
||||||
[ env "KEY" (show k)
|
[ env "KEY" (key2file k)
|
||||||
, env "HASH_1" (hashbits !! 0)
|
, env "HASH_1" (hashbits !! 0)
|
||||||
, env "HASH_2" (hashbits !! 1)
|
, env "HASH_2" (hashbits !! 1)
|
||||||
]
|
]
|
||||||
|
@ -133,7 +134,7 @@ checkPresent r h k = do
|
||||||
v <- lookupHook h "checkpresent"
|
v <- lookupHook h "checkpresent"
|
||||||
liftIO $ catchMsgIO $ check v
|
liftIO $ catchMsgIO $ check v
|
||||||
where
|
where
|
||||||
findkey s = show k `elem` lines s
|
findkey s = key2file k `elem` lines s
|
||||||
check Nothing = error "checkpresent hook misconfigured"
|
check Nothing = error "checkpresent hook misconfigured"
|
||||||
check (Just hook) = do
|
check (Just hook) = do
|
||||||
env <- hookEnv k Nothing
|
env <- hookEnv k Nothing
|
||||||
|
|
|
@ -211,7 +211,7 @@ s3Action r noconn action = do
|
||||||
_ -> return noconn
|
_ -> return noconn
|
||||||
|
|
||||||
bucketFile :: Remote -> Key -> FilePath
|
bucketFile :: Remote -> Key -> FilePath
|
||||||
bucketFile r = munge . show
|
bucketFile r = munge . key2file
|
||||||
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
|
||||||
|
|
2
Seek.hs
2
Seek.hs
|
@ -82,7 +82,7 @@ withFilesUnlocked' typechanged a params = do
|
||||||
withKeys :: (Key -> CommandStart) -> CommandSeek
|
withKeys :: (Key -> CommandStart) -> CommandSeek
|
||||||
withKeys a params = return $ map (a . parse) params
|
withKeys a params = return $ map (a . parse) params
|
||||||
where
|
where
|
||||||
parse p = fromMaybe (error "bad key") $ readKey p
|
parse p = fromMaybe (error "bad key") $ file2key p
|
||||||
|
|
||||||
withValue :: Annex v -> (v -> CommandSeek) -> CommandSeek
|
withValue :: Annex v -> (v -> CommandSeek) -> CommandSeek
|
||||||
withValue v a params = do
|
withValue v a params = do
|
||||||
|
|
35
Types/Key.hs
35
Types/Key.hs
|
@ -10,9 +10,10 @@
|
||||||
module Types.Key (
|
module Types.Key (
|
||||||
Key(..),
|
Key(..),
|
||||||
stubKey,
|
stubKey,
|
||||||
readKey,
|
key2file,
|
||||||
|
file2key,
|
||||||
|
|
||||||
prop_idempotent_key_read_show
|
prop_idempotent_key_encode
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import System.Posix.Types
|
import System.Posix.Types
|
||||||
|
@ -26,7 +27,7 @@ data Key = Key {
|
||||||
keyBackendName :: String,
|
keyBackendName :: String,
|
||||||
keySize :: Maybe Integer,
|
keySize :: Maybe Integer,
|
||||||
keyMtime :: Maybe EpochTime
|
keyMtime :: Maybe EpochTime
|
||||||
} deriving (Eq, Ord)
|
} deriving (Eq, Ord, Read, Show)
|
||||||
|
|
||||||
stubKey :: Key
|
stubKey :: Key
|
||||||
stubKey = Key {
|
stubKey = Key {
|
||||||
|
@ -39,21 +40,21 @@ stubKey = Key {
|
||||||
fieldSep :: Char
|
fieldSep :: Char
|
||||||
fieldSep = '-'
|
fieldSep = '-'
|
||||||
|
|
||||||
{- Keys show as strings that are suitable for use as filenames.
|
{- Converts a key to a strings that are suitable for use as a filename.
|
||||||
- The name field is always shown last, separated by doubled fieldSeps,
|
- The name field is always shown last, separated by doubled fieldSeps,
|
||||||
- and is the only field allowed to contain the fieldSep. -}
|
- and is the only field allowed to contain the fieldSep. -}
|
||||||
instance Show Key where
|
key2file :: Key -> FilePath
|
||||||
show Key { keyBackendName = b, keySize = s, keyMtime = m, keyName = n } =
|
key2file Key { keyBackendName = b, keySize = s, keyMtime = m, keyName = n } =
|
||||||
b +++ ('s' ?: s) +++ ('m' ?: m) +++ (fieldSep : n)
|
b +++ ('s' ?: s) +++ ('m' ?: m) +++ (fieldSep : n)
|
||||||
where
|
where
|
||||||
"" +++ y = y
|
"" +++ y = y
|
||||||
x +++ "" = x
|
x +++ "" = x
|
||||||
x +++ y = x ++ fieldSep:y
|
x +++ y = x ++ fieldSep:y
|
||||||
c ?: (Just v) = c : show v
|
c ?: (Just v) = c : show v
|
||||||
_ ?: _ = ""
|
_ ?: _ = ""
|
||||||
|
|
||||||
readKey :: String -> Maybe Key
|
file2key :: FilePath -> Maybe Key
|
||||||
readKey s = if key == Just stubKey then Nothing else key
|
file2key s = if key == Just stubKey then Nothing else key
|
||||||
where
|
where
|
||||||
key = startbackend stubKey s
|
key = startbackend stubKey s
|
||||||
|
|
||||||
|
@ -73,5 +74,5 @@ readKey s = if key == Just stubKey then Nothing else key
|
||||||
addfield 'm' k v = Just k { keyMtime = readish v }
|
addfield 'm' k v = Just k { keyMtime = readish v }
|
||||||
addfield _ _ _ = Nothing
|
addfield _ _ _ = Nothing
|
||||||
|
|
||||||
prop_idempotent_key_read_show :: Key -> Bool
|
prop_idempotent_key_encode :: Key -> Bool
|
||||||
prop_idempotent_key_read_show k = Just k == (readKey . show) k
|
prop_idempotent_key_encode k = Just k == (file2key . key2file) k
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Types.UUID where
|
||||||
|
|
||||||
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
|
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
|
||||||
data UUID = NoUUID | UUID String
|
data UUID = NoUUID | UUID String
|
||||||
deriving (Eq, Ord, Show)
|
deriving (Eq, Ord, Show, Read)
|
||||||
|
|
||||||
fromUUID :: UUID -> String
|
fromUUID :: UUID -> String
|
||||||
fromUUID (UUID u) = u
|
fromUUID (UUID u) = u
|
||||||
|
|
|
@ -142,7 +142,7 @@ oldlog2key l
|
||||||
-- as the v2 key that it is.
|
-- as the v2 key that it is.
|
||||||
readKey1 :: String -> Key
|
readKey1 :: String -> Key
|
||||||
readKey1 v
|
readKey1 v
|
||||||
| mixup = fromJust $ readKey $ join ":" $ Prelude.tail bits
|
| mixup = fromJust $ file2key $ join ":" $ Prelude.tail bits
|
||||||
| otherwise = Key
|
| otherwise = Key
|
||||||
{ keyName = n
|
{ keyName = n
|
||||||
, keyBackendName = b
|
, keyBackendName = b
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
$maybe file <- associatedFile info
|
$maybe file <- associatedFile info
|
||||||
#{file}
|
#{file}
|
||||||
$nothing
|
$nothing
|
||||||
#{show $ transferKey transfer}
|
#{key2file $ transferKey transfer}
|
||||||
$case transferDirection transfer
|
$case transferDirection transfer
|
||||||
$of Upload
|
$of Upload
|
||||||
→
|
→
|
||||||
|
@ -28,10 +28,10 @@
|
||||||
<div .bar style="width: #{percent};">
|
<div .bar style="width: #{percent};">
|
||||||
<div .btn-group .span2>
|
<div .btn-group .span2>
|
||||||
$if isNothing (startedTime info)
|
$if isNothing (startedTime info)
|
||||||
<button .btn>
|
<a .btn href="@{StartTransferR transfer}" onclick="(function( $ ) { $.post('@{StartTransferR transfer}'); })( jQuery ); return false;">
|
||||||
<i .icon-play title="start"></i>
|
<i .icon-play title="start"></i>
|
||||||
$else
|
$else
|
||||||
<button .btn>
|
<a .btn href="@{PauseTransferR transfer}" onclick="(function( $ ) { $.post('@{PauseTransferR transfer}'); })( jQuery ); return false;">
|
||||||
<i .icon-pause title="pause"></i>
|
<i .icon-pause title="pause"></i>
|
||||||
<button .btn>
|
<a .btn href="@{CancelTransferR transfer}" onclick="(function( $ ) { $.post('@{CancelTransferR transfer}'); })( jQuery ); return false;">
|
||||||
<i .icon-remove title="cancel"></i>
|
<i .icon-remove title="cancel"></i>
|
||||||
|
|
8
test.hs
8
test.hs
|
@ -77,7 +77,7 @@ quickcheck = TestLabel "quickcheck" $ TestList
|
||||||
[ qctest "prop_idempotent_deencode_git" Git.Filename.prop_idempotent_deencode
|
[ qctest "prop_idempotent_deencode_git" Git.Filename.prop_idempotent_deencode
|
||||||
, qctest "prop_idempotent_deencode" Utility.Format.prop_idempotent_deencode
|
, qctest "prop_idempotent_deencode" Utility.Format.prop_idempotent_deencode
|
||||||
, qctest "prop_idempotent_fileKey" Locations.prop_idempotent_fileKey
|
, qctest "prop_idempotent_fileKey" Locations.prop_idempotent_fileKey
|
||||||
, qctest "prop_idempotent_key_read_show" Types.Key.prop_idempotent_key_read_show
|
, qctest "prop_idempotent_key_encode" Types.Key.prop_idempotent_key_encode
|
||||||
, qctest "prop_idempotent_shellEscape" Utility.SafeCommand.prop_idempotent_shellEscape
|
, qctest "prop_idempotent_shellEscape" Utility.SafeCommand.prop_idempotent_shellEscape
|
||||||
, qctest "prop_idempotent_shellEscape_multiword" Utility.SafeCommand.prop_idempotent_shellEscape_multiword
|
, qctest "prop_idempotent_shellEscape_multiword" Utility.SafeCommand.prop_idempotent_shellEscape_multiword
|
||||||
, qctest "prop_idempotent_configEscape" Logs.Remote.prop_idempotent_configEscape
|
, qctest "prop_idempotent_configEscape" Logs.Remote.prop_idempotent_configEscape
|
||||||
|
@ -175,7 +175,7 @@ test_reinject = "git-annex reinject/fromkey" ~: TestCase $ intmpclonerepo $ do
|
||||||
writeFile tmp $ content sha1annexedfile
|
writeFile tmp $ content sha1annexedfile
|
||||||
r <- annexeval $ Types.Backend.getKey backendSHA1 $
|
r <- annexeval $ Types.Backend.getKey backendSHA1 $
|
||||||
Types.KeySource.KeySource { Types.KeySource.keyFilename = tmp, Types.KeySource.contentLocation = tmp }
|
Types.KeySource.KeySource { Types.KeySource.keyFilename = tmp, Types.KeySource.contentLocation = tmp }
|
||||||
let key = show $ fromJust r
|
let key = Types.Key.key2file $ fromJust r
|
||||||
git_annex "reinject" [tmp, sha1annexedfile] @? "reinject failed"
|
git_annex "reinject" [tmp, sha1annexedfile] @? "reinject failed"
|
||||||
git_annex "fromkey" [key, sha1annexedfiledup] @? "fromkey failed"
|
git_annex "fromkey" [key, sha1annexedfiledup] @? "fromkey failed"
|
||||||
annexed_present sha1annexedfiledup
|
annexed_present sha1annexedfiledup
|
||||||
|
@ -486,7 +486,7 @@ test_unused = "git-annex unused/dropunused" ~: intmpclonerepo $ do
|
||||||
checkunused [annexedfilekey, sha1annexedfilekey]
|
checkunused [annexedfilekey, sha1annexedfilekey]
|
||||||
|
|
||||||
-- good opportunity to test dropkey also
|
-- good opportunity to test dropkey also
|
||||||
git_annex "dropkey" ["--force", show annexedfilekey]
|
git_annex "dropkey" ["--force", Types.Key.key2file annexedfilekey]
|
||||||
@? "dropkey failed"
|
@? "dropkey failed"
|
||||||
checkunused [sha1annexedfilekey]
|
checkunused [sha1annexedfilekey]
|
||||||
|
|
||||||
|
@ -840,7 +840,7 @@ checklocationlog f expected = do
|
||||||
case r of
|
case r of
|
||||||
Just (k, _) -> do
|
Just (k, _) -> do
|
||||||
uuids <- annexeval $ Remote.keyLocations k
|
uuids <- annexeval $ Remote.keyLocations k
|
||||||
assertEqual ("bad content in location log for " ++ f ++ " key " ++ (show k) ++ " uuid " ++ show thisuuid)
|
assertEqual ("bad content in location log for " ++ f ++ " key " ++ (Types.Key.key2file k) ++ " uuid " ++ show thisuuid)
|
||||||
expected (thisuuid `elem` uuids)
|
expected (thisuuid `elem` uuids)
|
||||||
_ -> assertFailure $ f ++ " failed to look up key"
|
_ -> assertFailure $ f ++ " failed to look up key"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue