use the ~/.config/git-annex/program file to find command when running transfers
This commit is contained in:
parent
b12db9ef92
commit
2433f6ca5a
5 changed files with 21 additions and 15 deletions
|
@ -18,6 +18,7 @@ import Logs.Location
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import Types.Key
|
import Types.Key
|
||||||
|
import Locations.UserConfig
|
||||||
|
|
||||||
import System.Process (create_group)
|
import System.Process (create_group)
|
||||||
|
|
||||||
|
@ -30,23 +31,23 @@ maxTransfers = 1
|
||||||
|
|
||||||
{- Dispatches transfers from the queue. -}
|
{- Dispatches transfers from the queue. -}
|
||||||
transfererThread :: ThreadState -> DaemonStatusHandle -> TransferQueue -> TransferSlots -> IO ()
|
transfererThread :: ThreadState -> DaemonStatusHandle -> TransferQueue -> TransferSlots -> IO ()
|
||||||
transfererThread st dstatus transferqueue slots = go
|
transfererThread st dstatus transferqueue slots = go =<< readProgramFile
|
||||||
where
|
where
|
||||||
go = getNextTransfer transferqueue dstatus notrunning >>= handle
|
go program = getNextTransfer transferqueue dstatus notrunning >>= handle program
|
||||||
handle Nothing = go
|
handle program Nothing = go program
|
||||||
handle (Just (t, info)) = do
|
handle program (Just (t, info)) = do
|
||||||
ifM (runThreadState st $ shouldTransfer t info)
|
ifM (runThreadState st $ shouldTransfer t info)
|
||||||
( do
|
( do
|
||||||
debug thisThread [ "Transferring:" , show t ]
|
debug thisThread [ "Transferring:" , show t ]
|
||||||
notifyTransfer dstatus
|
notifyTransfer dstatus
|
||||||
transferThread dstatus slots t info inTransferSlot
|
transferThread dstatus slots t info inTransferSlot program
|
||||||
, do
|
, do
|
||||||
debug thisThread [ "Skipping unnecessary transfer:" , show t ]
|
debug thisThread [ "Skipping unnecessary transfer:" , show t ]
|
||||||
-- getNextTransfer added t to the
|
-- getNextTransfer added t to the
|
||||||
-- daemonstatus's transfer map.
|
-- daemonstatus's transfer map.
|
||||||
void $ removeTransfer dstatus t
|
void $ removeTransfer dstatus t
|
||||||
)
|
)
|
||||||
go
|
go program
|
||||||
{- Skip transfers that are already running. -}
|
{- Skip transfers that are already running. -}
|
||||||
notrunning i = startedTime i == Nothing
|
notrunning i = startedTime i == Nothing
|
||||||
|
|
||||||
|
@ -79,8 +80,8 @@ shouldTransfer t info
|
||||||
- the transfer info; the thread will also be killed when a transfer is
|
- the transfer info; the thread will also be killed when a transfer is
|
||||||
- stopped, to avoid it displaying any alert about the transfer having
|
- stopped, to avoid it displaying any alert about the transfer having
|
||||||
- failed. -}
|
- failed. -}
|
||||||
transferThread :: DaemonStatusHandle -> TransferSlots -> Transfer -> TransferInfo -> TransferSlotRunner -> IO ()
|
transferThread :: DaemonStatusHandle -> TransferSlots -> Transfer -> TransferInfo -> TransferSlotRunner -> FilePath -> IO ()
|
||||||
transferThread dstatus slots t info runner = case (transferRemote info, associatedFile info) of
|
transferThread dstatus slots t info runner program = case (transferRemote info, associatedFile info) of
|
||||||
(Nothing, _) -> noop
|
(Nothing, _) -> noop
|
||||||
(_, Nothing) -> noop
|
(_, Nothing) -> noop
|
||||||
(Just remote, Just file) -> do
|
(Just remote, Just file) -> do
|
||||||
|
@ -93,14 +94,13 @@ transferThread dstatus slots t info runner = case (transferRemote info, associat
|
||||||
|
|
||||||
transferprocess remote file = void $ do
|
transferprocess remote file = void $ do
|
||||||
(_, _, _, pid)
|
(_, _, _, pid)
|
||||||
<- createProcess (proc command $ toCommand params)
|
<- createProcess (proc program $ toCommand params)
|
||||||
{ create_group = True }
|
{ create_group = True }
|
||||||
status <- waitForProcess pid
|
status <- waitForProcess pid
|
||||||
addAlert dstatus $
|
addAlert dstatus $
|
||||||
makeAlertFiller (status == ExitSuccess) $
|
makeAlertFiller (status == ExitSuccess) $
|
||||||
transferFileAlert direction file
|
transferFileAlert direction file
|
||||||
where
|
where
|
||||||
command = "git-annex"
|
|
||||||
params =
|
params =
|
||||||
[ Param "transferkey"
|
[ Param "transferkey"
|
||||||
, Param $ key2file $ transferKey t
|
, Param $ key2file $ transferKey t
|
||||||
|
|
|
@ -26,6 +26,7 @@ import Utility.DataUnits
|
||||||
import Types.Key
|
import Types.Key
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import qualified Git
|
import qualified Git
|
||||||
|
import Locations.UserConfig
|
||||||
|
|
||||||
import Yesod
|
import Yesod
|
||||||
import Text.Hamlet
|
import Text.Hamlet
|
||||||
|
@ -211,6 +212,7 @@ startTransfer t = do
|
||||||
{ transferPid = Nothing }
|
{ transferPid = Nothing }
|
||||||
liftIO $ Transferrer.transferThread
|
liftIO $ Transferrer.transferThread
|
||||||
dstatus slots t info inImmediateTransferSlot
|
dstatus slots t info inImmediateTransferSlot
|
||||||
|
=<< readProgramFile
|
||||||
|
|
||||||
getCurrentTransfers :: Handler TransferMap
|
getCurrentTransfers :: Handler TransferMap
|
||||||
getCurrentTransfers = currentTransfers
|
getCurrentTransfers = currentTransfers
|
||||||
|
|
|
@ -37,7 +37,7 @@ autostart command = genDesktopEntry
|
||||||
(command ++ " assistant --autostart")
|
(command ++ " assistant --autostart")
|
||||||
[]
|
[]
|
||||||
|
|
||||||
writeDesktop :: String -> IO ()
|
writeDesktop :: FilePath -> IO ()
|
||||||
writeDesktop command = do
|
writeDesktop command = do
|
||||||
destdir <- catchDefaultIO (getEnv "DESTDIR") ""
|
destdir <- catchDefaultIO (getEnv "DESTDIR") ""
|
||||||
uid <- fromIntegral <$> getRealUserID
|
uid <- fromIntegral <$> getRealUserID
|
||||||
|
|
|
@ -55,8 +55,7 @@ autoStart = do
|
||||||
ifM (doesFileExist autostartfile)
|
ifM (doesFileExist autostartfile)
|
||||||
( do
|
( do
|
||||||
dirs <- lines <$> readFile autostartfile
|
dirs <- lines <$> readFile autostartfile
|
||||||
programfile <- programFile
|
program <- readProgramFile
|
||||||
program <- catchDefaultIO (readFile programfile) "git-annex"
|
|
||||||
when (null dirs) nothing
|
when (null dirs) nothing
|
||||||
forM_ dirs $ \d -> do
|
forM_ dirs $ \d -> do
|
||||||
putStrLn $ "git-annex autostart in " ++ d
|
putStrLn $ "git-annex autostart in " ++ d
|
||||||
|
|
|
@ -7,10 +7,9 @@
|
||||||
|
|
||||||
module Locations.UserConfig where
|
module Locations.UserConfig where
|
||||||
|
|
||||||
|
import Common
|
||||||
import Utility.FreeDesktop
|
import Utility.FreeDesktop
|
||||||
|
|
||||||
import System.FilePath
|
|
||||||
|
|
||||||
{- ~/.config/git-annex/file -}
|
{- ~/.config/git-annex/file -}
|
||||||
userConfigFile :: FilePath -> IO FilePath
|
userConfigFile :: FilePath -> IO FilePath
|
||||||
userConfigFile file = do
|
userConfigFile file = do
|
||||||
|
@ -24,3 +23,9 @@ autoStartFile = userConfigFile "autostart"
|
||||||
- has installed it to some aweful non-PATH location. -}
|
- has installed it to some aweful non-PATH location. -}
|
||||||
programFile :: IO FilePath
|
programFile :: IO FilePath
|
||||||
programFile = userConfigFile "program"
|
programFile = userConfigFile "program"
|
||||||
|
|
||||||
|
{- Returns a command to run for git-annex. -}
|
||||||
|
readProgramFile :: IO FilePath
|
||||||
|
readProgramFile = do
|
||||||
|
programfile <- programFile
|
||||||
|
catchDefaultIO (readFile programfile) "git-annex"
|
||||||
|
|
Loading…
Add table
Reference in a new issue