From 29b1e4c69e96b1dab8ce8ae0579e988b17d33325 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 28 Dec 2017 11:46:39 -0400 Subject: Added inprogress command for accessing files as they are being downloaded. Chose to make this only handle files actively being downloaded, not temp files for downloads that were interrupted or files that have been fully downloaded. This commit was sponsored by Ole-Morten Duesund on Patreon. --- CHANGELOG | 2 ++ CmdLine/GitAnnex.hs | 2 ++ Command/Inprogress.hs | 60 +++++++++++++++++++++++++++++++++++++++++++ doc/git-annex-inprogress.mdwn | 53 ++++++++++++++++++++++++++++++++++++++ doc/git-annex.mdwn | 6 +++++ git-annex.cabal | 2 ++ 6 files changed, 125 insertions(+) create mode 100644 Command/Inprogress.hs create mode 100644 doc/git-annex-inprogress.mdwn diff --git a/CHANGELOG b/CHANGELOG index afc9c28ee..d3524d766 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ git-annex (6.20171215) UNRELEASED; urgency=medium * Removed the testsuite build flag; test suite is always included. + * Added inprogress command for accessing files as they are being + downloaded. -- Joey Hess Wed, 20 Dec 2017 12:11:46 -0400 diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs index da4e54be3..e2f28e39c 100644 --- a/CmdLine/GitAnnex.hs +++ b/CmdLine/GitAnnex.hs @@ -73,6 +73,7 @@ import qualified Command.Merge import qualified Command.ResolveMerge import qualified Command.Info import qualified Command.Status +import qualified Command.Inprogress import qualified Command.Migrate import qualified Command.Uninit import qualified Command.Reinit @@ -203,6 +204,7 @@ cmds testoptparser testrunner = , Command.ResolveMerge.cmd , Command.Info.cmd , Command.Status.cmd + , Command.Inprogress.cmd , Command.Migrate.cmd , Command.Map.cmd , Command.Direct.cmd diff --git a/Command/Inprogress.hs b/Command/Inprogress.hs new file mode 100644 index 000000000..f1a8345ae --- /dev/null +++ b/Command/Inprogress.hs @@ -0,0 +1,60 @@ +{- git-annex command + - + - Copyright 2017 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Command.Inprogress where + +import Command +import Annex.Transfer + +import qualified Data.Set as S + +cmd :: Command +cmd = noCommit $ noMessages $ command "inprogress" SectionQuery + "access files while they're being downloaded" + paramPaths (seek <$$> optParser) + +data InprogressOptions = InprogressOptions + { inprogressFiles :: CmdParams + , allOption :: Bool + } + +optParser :: CmdParamsDesc -> Parser InprogressOptions +optParser desc = InprogressOptions + <$> cmdParams desc + <*> switch + ( long "all" + <> short 'A' + <> help "access all files currently being downloaded" + ) + +seek :: InprogressOptions -> CommandSeek +seek o = do + ts <- map (transferKey . fst) <$> getTransfers + if allOption o + then forM_ ts $ commandAction . start' + else do + let s = S.fromList ts + withFilesInGit (whenAnnexed (start s)) + =<< workTreeItems (inprogressFiles o) + +start :: S.Set Key -> FilePath -> Key -> CommandStart +start s _file k + | S.member k s = start' k + | otherwise = notInprogress + +start' :: Key -> CommandStart +start' k = do + tmpf <- fromRepo $ gitAnnexTmpObjectLocation k + ifM (liftIO $ doesFileExist tmpf) + ( next $ next $ do + liftIO $ putStrLn tmpf + return True + , notInprogress + ) + +notInprogress :: CommandStart +notInprogress = next stop diff --git a/doc/git-annex-inprogress.mdwn b/doc/git-annex-inprogress.mdwn new file mode 100644 index 000000000..1a595cba1 --- /dev/null +++ b/doc/git-annex-inprogress.mdwn @@ -0,0 +1,53 @@ +# NAME + +git-annex inprogress - access files while they're being downloaded + +# SYNOPSIS + +git annex inprogress `[path ...]` + +# DESCRIPTION + +This command allows accessing the content of an annexed file while +it is still being downloaded. It outputs to standard output the +name of the temporary file that is being used to download the specified +annexed file. + +This can sometimes be used to stream a file before it's been fully +downloaded, for example: + + git annex get video.mpeg & + vlc $(git annex inprogress video.mpeg) + +Of course if the file is downloading too slowly, the media player will +reach the end too soon and not show the whole thing. And of course, only +some file formats can be usefully streamed in this way. + +# OPTIONS + +* file matching options + + The [[git-annex-matching-options]](1) + can be used to specify files to access. + +* `--all` + + Rather than specifying a filename or path, this option can be + used to access all files that are currently being downloaded. + +# EXIT STATUS + +If any of the requested files are not currently being downloaded, +the exit status will be 1. + +# SEE ALSO + +[[git-annex]](1) + +[[git-annex-get]](1) + +# AUTHOR + +Joey Hess + +Warning: Automatically converted into a man page by mdwn2man. Edit with care. diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index 8f84f1d9e..d4502cdfa 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -461,6 +461,12 @@ subdirectories). See [[git-annex-map]](1) for details. +* `inprogress` + + Access files while they're being downloaded. + + See [[git-annex-inprogress]](1) for details. + # METADATA COMMANDS * `metadata [path ...]` diff --git a/git-annex.cabal b/git-annex.cabal index f2a8b47f5..6b2fec439 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -79,6 +79,7 @@ Extra-Source-Files: doc/git-annex-info.mdwn doc/git-annex-init.mdwn doc/git-annex-initremote.mdwn + doc/git-annex-inprogress.mdwn doc/git-annex-list.mdwn doc/git-annex-lock.mdwn doc/git-annex-log.mdwn @@ -717,6 +718,7 @@ Executable git-annex Command.Info Command.Init Command.InitRemote + Command.Inprogress Command.List Command.Lock Command.LockContent -- cgit v1.2.3