also check diskreserve for quvi downloads
This commit is contained in:
parent
c7618a9a1d
commit
78c7c54fdb
2 changed files with 30 additions and 22 deletions
|
@ -222,7 +222,6 @@ checkDiskSpace destination key alreadythere = do
|
||||||
reserve <- annexDiskReserve <$> Annex.getGitConfig
|
reserve <- annexDiskReserve <$> Annex.getGitConfig
|
||||||
free <- liftIO . getDiskFree =<< dir
|
free <- liftIO . getDiskFree =<< dir
|
||||||
force <- Annex.getState Annex.force
|
force <- Annex.getState Annex.force
|
||||||
liftIO $ print (free, keySize key)
|
|
||||||
case (free, keySize key) of
|
case (free, keySize key) of
|
||||||
(Just have, Just need) -> do
|
(Just have, Just need) -> do
|
||||||
let ok = (need + reserve <= have + alreadythere) || force
|
let ok = (need + reserve <= have + alreadythere) || force
|
||||||
|
|
|
@ -107,14 +107,21 @@ addUrlFileQuvi relaxed quviurl videourl file = do
|
||||||
ifM (pure relaxed <||> Annex.getState Annex.fast)
|
ifM (pure relaxed <||> Annex.getState Annex.fast)
|
||||||
( cleanup quviurl file key Nothing
|
( cleanup quviurl file key Nothing
|
||||||
, do
|
, do
|
||||||
tmp <- fromRepo $ gitAnnexTmpLocation key
|
{- Get the size, and use that to check
|
||||||
showOutput
|
- disk space. However, the size info is not
|
||||||
ok <- Transfer.download webUUID key (Just file) Transfer.forwardRetry $ const $ do
|
- retained, because the size of a video stream
|
||||||
liftIO $ createDirectoryIfMissing True (parentDir tmp)
|
- might change and we want to be able to download
|
||||||
downloadUrl [videourl] tmp
|
- it later. -}
|
||||||
if ok
|
sizedkey <- addSizeUrlKey videourl key
|
||||||
then cleanup quviurl file key (Just tmp)
|
prepGetViaTmpChecked sizedkey $ do
|
||||||
else return False
|
tmp <- fromRepo $ gitAnnexTmpLocation key
|
||||||
|
showOutput
|
||||||
|
ok <- Transfer.download webUUID key (Just file) Transfer.forwardRetry $ const $ do
|
||||||
|
liftIO $ createDirectoryIfMissing True (parentDir tmp)
|
||||||
|
downloadUrl [videourl] tmp
|
||||||
|
if ok
|
||||||
|
then cleanup quviurl file key (Just tmp)
|
||||||
|
else return False
|
||||||
)
|
)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -151,7 +158,10 @@ addUrlFile relaxed url file = do
|
||||||
|
|
||||||
download :: URLString -> FilePath -> Annex Bool
|
download :: URLString -> FilePath -> Annex Bool
|
||||||
download url file = do
|
download url file = do
|
||||||
dummykey <- genkey
|
{- Generate a dummy key to use for this download, before we can
|
||||||
|
- examine the file and find its real key. This allows resuming
|
||||||
|
- downloads, as the dummy key for a given url is stable. -}
|
||||||
|
dummykey <- addSizeUrlKey url =<< Backend.URL.fromUrl url Nothing
|
||||||
prepGetViaTmpChecked dummykey $ do
|
prepGetViaTmpChecked dummykey $ do
|
||||||
tmp <- fromRepo $ gitAnnexTmpLocation dummykey
|
tmp <- fromRepo $ gitAnnexTmpLocation dummykey
|
||||||
showOutput
|
showOutput
|
||||||
|
@ -170,23 +180,22 @@ download url file = do
|
||||||
, return False
|
, return False
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
{- Generate a dummy key to use for this download, before we can
|
|
||||||
- examine the file and find its real key. This allows resuming
|
|
||||||
- downloads, as the dummy key for a given url is stable.
|
|
||||||
-
|
|
||||||
- Actually hits the url here, to get the size. This is needed to
|
|
||||||
- avoid exceeding the diskreserve, and so the assistant can
|
|
||||||
- display a pretty progress bar.
|
|
||||||
-}
|
|
||||||
genkey = do
|
|
||||||
headers <- getHttpHeaders
|
|
||||||
size <- snd <$> Url.withUserAgent (Url.exists url headers)
|
|
||||||
Backend.URL.fromUrl url size
|
|
||||||
runtransfer dummykey tmp =
|
runtransfer dummykey tmp =
|
||||||
Transfer.download webUUID dummykey (Just file) Transfer.forwardRetry $ const $ do
|
Transfer.download webUUID dummykey (Just file) Transfer.forwardRetry $ const $ do
|
||||||
liftIO $ createDirectoryIfMissing True (parentDir tmp)
|
liftIO $ createDirectoryIfMissing True (parentDir tmp)
|
||||||
downloadUrl [url] tmp
|
downloadUrl [url] tmp
|
||||||
|
|
||||||
|
{- Hits the url to get the size, if available.
|
||||||
|
-
|
||||||
|
- This is needed to avoid exceeding the diskreserve when downloading,
|
||||||
|
- and so the assistant can display a pretty progress bar.
|
||||||
|
-}
|
||||||
|
addSizeUrlKey :: URLString -> Key -> Annex Key
|
||||||
|
addSizeUrlKey url key = do
|
||||||
|
headers <- getHttpHeaders
|
||||||
|
size <- snd <$> Url.withUserAgent (Url.exists url headers)
|
||||||
|
return $ key { keySize = size }
|
||||||
|
|
||||||
cleanup :: URLString -> FilePath -> Key -> Maybe FilePath -> Annex Bool
|
cleanup :: URLString -> FilePath -> Key -> Maybe FilePath -> Annex Bool
|
||||||
cleanup url file key mtmp = do
|
cleanup url file key mtmp = do
|
||||||
when (isJust mtmp) $
|
when (isJust mtmp) $
|
||||||
|
|
Loading…
Reference in a new issue