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.
This commit is contained in:
parent
d180ae039c
commit
67338fd7ac
6 changed files with 125 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
git-annex (6.20171215) UNRELEASED; urgency=medium
|
git-annex (6.20171215) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
* Removed the testsuite build flag; test suite is always included.
|
* Removed the testsuite build flag; test suite is always included.
|
||||||
|
* Added inprogress command for accessing files as they are being
|
||||||
|
downloaded.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Wed, 20 Dec 2017 12:11:46 -0400
|
-- Joey Hess <id@joeyh.name> Wed, 20 Dec 2017 12:11:46 -0400
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ import qualified Command.Merge
|
||||||
import qualified Command.ResolveMerge
|
import qualified Command.ResolveMerge
|
||||||
import qualified Command.Info
|
import qualified Command.Info
|
||||||
import qualified Command.Status
|
import qualified Command.Status
|
||||||
|
import qualified Command.Inprogress
|
||||||
import qualified Command.Migrate
|
import qualified Command.Migrate
|
||||||
import qualified Command.Uninit
|
import qualified Command.Uninit
|
||||||
import qualified Command.Reinit
|
import qualified Command.Reinit
|
||||||
|
@ -203,6 +204,7 @@ cmds testoptparser testrunner =
|
||||||
, Command.ResolveMerge.cmd
|
, Command.ResolveMerge.cmd
|
||||||
, Command.Info.cmd
|
, Command.Info.cmd
|
||||||
, Command.Status.cmd
|
, Command.Status.cmd
|
||||||
|
, Command.Inprogress.cmd
|
||||||
, Command.Migrate.cmd
|
, Command.Migrate.cmd
|
||||||
, Command.Map.cmd
|
, Command.Map.cmd
|
||||||
, Command.Direct.cmd
|
, Command.Direct.cmd
|
||||||
|
|
60
Command/Inprogress.hs
Normal file
60
Command/Inprogress.hs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
{- git-annex command
|
||||||
|
-
|
||||||
|
- Copyright 2017 Joey Hess <id@joeyh.name>
|
||||||
|
-
|
||||||
|
- 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
|
53
doc/git-annex-inprogress.mdwn
Normal file
53
doc/git-annex-inprogress.mdwn
Normal file
|
@ -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 <id@joeyh.name>
|
||||||
|
|
||||||
|
Warning: Automatically converted into a man page by mdwn2man. Edit with care.
|
|
@ -461,6 +461,12 @@ subdirectories).
|
||||||
|
|
||||||
See [[git-annex-map]](1) for details.
|
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 COMMANDS
|
||||||
|
|
||||||
* `metadata [path ...]`
|
* `metadata [path ...]`
|
||||||
|
|
|
@ -79,6 +79,7 @@ Extra-Source-Files:
|
||||||
doc/git-annex-info.mdwn
|
doc/git-annex-info.mdwn
|
||||||
doc/git-annex-init.mdwn
|
doc/git-annex-init.mdwn
|
||||||
doc/git-annex-initremote.mdwn
|
doc/git-annex-initremote.mdwn
|
||||||
|
doc/git-annex-inprogress.mdwn
|
||||||
doc/git-annex-list.mdwn
|
doc/git-annex-list.mdwn
|
||||||
doc/git-annex-lock.mdwn
|
doc/git-annex-lock.mdwn
|
||||||
doc/git-annex-log.mdwn
|
doc/git-annex-log.mdwn
|
||||||
|
@ -717,6 +718,7 @@ Executable git-annex
|
||||||
Command.Info
|
Command.Info
|
||||||
Command.Init
|
Command.Init
|
||||||
Command.InitRemote
|
Command.InitRemote
|
||||||
|
Command.Inprogress
|
||||||
Command.List
|
Command.List
|
||||||
Command.Lock
|
Command.Lock
|
||||||
Command.LockContent
|
Command.LockContent
|
||||||
|
|
Loading…
Add table
Reference in a new issue