2011-07-01 21:15:46 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2014-12-08 23:14:24 +00:00
|
|
|
- Copyright 2011-2014 Joey Hess <joey@kitenet.net>
|
2011-07-01 21:15:46 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-09-09 06:16:22 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2011-07-01 21:15:46 +00:00
|
|
|
module Command.AddUrl where
|
|
|
|
|
|
|
|
import Network.URI
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2011-07-01 21:15:46 +00:00
|
|
|
import Command
|
2012-06-05 23:51:03 +00:00
|
|
|
import Backend
|
2011-07-01 21:15:46 +00:00
|
|
|
import qualified Command.Add
|
2011-07-01 22:46:07 +00:00
|
|
|
import qualified Annex
|
2013-04-11 17:35:52 +00:00
|
|
|
import qualified Annex.Queue
|
2013-09-28 18:35:21 +00:00
|
|
|
import qualified Annex.Url as Url
|
2011-08-06 18:57:22 +00:00
|
|
|
import qualified Backend.URL
|
2014-12-08 23:14:24 +00:00
|
|
|
import qualified Remote
|
|
|
|
import qualified Types.Remote as Remote
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2011-10-15 20:36:56 +00:00
|
|
|
import Logs.Web
|
2012-02-10 23:40:36 +00:00
|
|
|
import Types.Key
|
2012-06-20 20:07:14 +00:00
|
|
|
import Types.KeySource
|
2014-12-11 19:32:42 +00:00
|
|
|
import Types.UrlContents
|
2012-04-22 05:13:09 +00:00
|
|
|
import Config
|
2013-01-06 21:34:44 +00:00
|
|
|
import Annex.Content.Direct
|
2013-04-11 17:35:52 +00:00
|
|
|
import Logs.Location
|
2014-12-08 23:14:24 +00:00
|
|
|
import Utility.Metered
|
2014-03-22 14:42:38 +00:00
|
|
|
import qualified Annex.Transfer as Transfer
|
2013-09-09 06:16:22 +00:00
|
|
|
#ifdef WITH_QUVI
|
2013-08-22 22:25:21 +00:00
|
|
|
import Annex.Quvi
|
|
|
|
import qualified Utility.Quvi as Quvi
|
2013-09-09 06:16:22 +00:00
|
|
|
#endif
|
2011-07-01 21:15:46 +00:00
|
|
|
|
2014-10-14 18:20:10 +00:00
|
|
|
cmd :: [Command]
|
|
|
|
cmd = [notBareRepo $ withOptions [fileOption, pathdepthOption, relaxedOption] $
|
2013-03-24 22:28:21 +00:00
|
|
|
command "addurl" (paramRepeating paramUrl) seek
|
|
|
|
SectionCommon "add urls to annex"]
|
2012-02-08 19:35:18 +00:00
|
|
|
|
|
|
|
fileOption :: Option
|
2014-01-26 20:25:55 +00:00
|
|
|
fileOption = fieldOption [] "file" paramFile "specify what file the url is added to"
|
2011-07-01 21:15:46 +00:00
|
|
|
|
2012-02-16 16:25:19 +00:00
|
|
|
pathdepthOption :: Option
|
2014-01-26 20:25:55 +00:00
|
|
|
pathdepthOption = fieldOption [] "pathdepth" paramNumber "path components to use in filename"
|
2012-02-16 16:25:19 +00:00
|
|
|
|
2013-03-11 23:55:01 +00:00
|
|
|
relaxedOption :: Option
|
2014-01-26 20:25:55 +00:00
|
|
|
relaxedOption = flagOption [] "relaxed" "skip size check"
|
2013-03-11 23:55:01 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seek :: CommandSeek
|
2014-12-11 19:32:42 +00:00
|
|
|
seek us = do
|
|
|
|
optfile <- getOptionField fileOption return
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
relaxed <- getOptionFlag relaxedOption
|
2014-12-11 19:32:42 +00:00
|
|
|
pathdepth <- getOptionField pathdepthOption (return . maybe Nothing readish)
|
|
|
|
forM_ us $ \u -> do
|
|
|
|
r <- Remote.claimingUrl u
|
|
|
|
if Remote.uuid r == webUUID
|
|
|
|
then void $ commandAction $ startWeb relaxed optfile pathdepth u
|
|
|
|
else do
|
2014-12-11 20:09:56 +00:00
|
|
|
pathmax <- liftIO $ fileNameLengthLimit "."
|
|
|
|
let deffile = fromMaybe (urlString2file u pathdepth pathmax) optfile
|
2014-12-11 19:32:42 +00:00
|
|
|
res <- tryNonAsync $ maybe
|
2014-12-11 20:09:56 +00:00
|
|
|
(error $ "unable to checkUrl of " ++ Remote.name r)
|
2014-12-11 19:32:42 +00:00
|
|
|
(flip id u)
|
|
|
|
(Remote.checkUrl r)
|
|
|
|
case res of
|
|
|
|
Left e -> void $ commandAction $ do
|
|
|
|
showStart "addurl" u
|
|
|
|
warning (show e)
|
|
|
|
next $ next $ return False
|
2014-12-11 20:09:56 +00:00
|
|
|
Right (UrlContents sz mf) -> do
|
|
|
|
void $ commandAction $
|
2014-12-12 00:08:49 +00:00
|
|
|
startRemote r relaxed (maybe deffile fromSafeFilePath mf) u sz
|
2014-12-11 20:09:56 +00:00
|
|
|
Right (UrlMulti l) ->
|
|
|
|
forM_ l $ \(u', sz, f) ->
|
|
|
|
void $ commandAction $
|
2014-12-12 00:08:49 +00:00
|
|
|
startRemote r relaxed (deffile </> fromSafeFilePath f) u' sz
|
2014-12-08 23:14:24 +00:00
|
|
|
|
2014-12-11 20:43:46 +00:00
|
|
|
startRemote :: Remote -> Bool -> FilePath -> URLString -> Maybe Integer -> CommandStart
|
|
|
|
startRemote r relaxed file uri sz = do
|
2014-12-08 23:14:24 +00:00
|
|
|
showStart "addurl" file
|
2014-12-11 22:22:40 +00:00
|
|
|
showNote $ "from " ++ Remote.name r
|
2014-12-11 20:43:46 +00:00
|
|
|
next $ performRemote r relaxed uri file sz
|
2014-12-08 23:14:24 +00:00
|
|
|
|
2014-12-11 19:32:42 +00:00
|
|
|
performRemote :: Remote -> Bool -> URLString -> FilePath -> Maybe Integer -> CommandPerform
|
|
|
|
performRemote r relaxed uri file sz = ifAnnexed file adduri geturi
|
2014-12-08 23:14:24 +00:00
|
|
|
where
|
|
|
|
loguri = setDownloader uri OtherDownloader
|
|
|
|
adduri = addUrlChecked relaxed loguri (Remote.uuid r) checkexistssize
|
2014-12-11 19:32:42 +00:00
|
|
|
checkexistssize key = return $ case sz of
|
|
|
|
Nothing -> (True, True)
|
|
|
|
Just n -> (True, n == fromMaybe n (keySize key))
|
2014-12-11 20:43:46 +00:00
|
|
|
geturi = next $ isJust <$> downloadRemoteFile r relaxed uri file sz
|
|
|
|
|
|
|
|
downloadRemoteFile :: Remote -> Bool -> URLString -> FilePath -> Maybe Integer -> Annex (Maybe Key)
|
|
|
|
downloadRemoteFile r relaxed uri file sz = do
|
|
|
|
urlkey <- Backend.URL.fromUrl uri sz
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir file)
|
|
|
|
ifM (Annex.getState Annex.fast <||> pure relaxed)
|
|
|
|
( do
|
|
|
|
cleanup (Remote.uuid r) loguri file urlkey Nothing
|
|
|
|
return (Just urlkey)
|
|
|
|
, do
|
|
|
|
-- Set temporary url for the urlkey
|
|
|
|
-- so that the remote knows what url it
|
|
|
|
-- should use to download it.
|
|
|
|
setTempUrl urlkey uri
|
|
|
|
let downloader = Remote.retrieveKeyFile r urlkey (Just file)
|
|
|
|
ret <- downloadWith downloader urlkey (Remote.uuid r) loguri file
|
|
|
|
removeTempUrl urlkey
|
|
|
|
return ret
|
|
|
|
)
|
|
|
|
where
|
|
|
|
loguri = setDownloader uri OtherDownloader
|
2014-12-08 23:14:24 +00:00
|
|
|
|
|
|
|
startWeb :: Bool -> Maybe FilePath -> Maybe Int -> String -> CommandStart
|
|
|
|
startWeb relaxed optfile pathdepth s = go $ fromMaybe bad $ parseURI s
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
(s', downloader) = getDownloader s
|
2013-08-22 22:25:21 +00:00
|
|
|
bad = fromMaybe (error $ "bad url " ++ s') $
|
|
|
|
parseURI $ escapeURIString isUnescapedInURI s'
|
|
|
|
choosefile = flip fromMaybe optfile
|
2013-08-23 03:44:13 +00:00
|
|
|
go url = case downloader of
|
|
|
|
QuviDownloader -> usequvi
|
2014-12-08 23:14:24 +00:00
|
|
|
_ ->
|
2013-09-15 20:37:03 +00:00
|
|
|
#ifdef WITH_QUVI
|
2014-02-28 18:54:02 +00:00
|
|
|
ifM (quviSupported s')
|
2013-09-09 06:16:22 +00:00
|
|
|
( usequvi
|
|
|
|
, regulardownload url
|
|
|
|
)
|
|
|
|
#else
|
|
|
|
regulardownload url
|
|
|
|
#endif
|
|
|
|
regulardownload url = do
|
|
|
|
pathmax <- liftIO $ fileNameLengthLimit "."
|
|
|
|
let file = choosefile $ url2file url pathdepth pathmax
|
|
|
|
showStart "addurl" file
|
2014-12-08 23:14:24 +00:00
|
|
|
next $ performWeb relaxed s' file
|
2013-09-09 06:16:22 +00:00
|
|
|
#ifdef WITH_QUVI
|
|
|
|
badquvi = error $ "quvi does not know how to download url " ++ s'
|
2013-08-22 22:25:21 +00:00
|
|
|
usequvi = do
|
|
|
|
page <- fromMaybe badquvi
|
|
|
|
<$> withQuviOptions Quvi.forceQuery [Quvi.quiet, Quvi.httponly] s'
|
|
|
|
let link = fromMaybe badquvi $ headMaybe $ Quvi.pageLinks page
|
2013-10-05 17:32:42 +00:00
|
|
|
pathmax <- liftIO $ fileNameLengthLimit "."
|
|
|
|
let file = choosefile $ truncateFilePath pathmax $ sanitizeFilePath $
|
2013-08-22 22:25:21 +00:00
|
|
|
Quvi.pageTitle page ++ "." ++ Quvi.linkSuffix link
|
2012-11-12 05:05:04 +00:00
|
|
|
showStart "addurl" file
|
2013-08-22 22:25:21 +00:00
|
|
|
next $ performQuvi relaxed s' (Quvi.linkUrl link) file
|
2013-09-09 06:16:22 +00:00
|
|
|
#else
|
|
|
|
usequvi = error "not built with quvi support"
|
|
|
|
#endif
|
2013-08-22 22:25:21 +00:00
|
|
|
|
2014-12-11 20:11:38 +00:00
|
|
|
performWeb :: Bool -> URLString -> FilePath -> CommandPerform
|
|
|
|
performWeb relaxed url file = ifAnnexed file addurl geturl
|
|
|
|
where
|
|
|
|
geturl = next $ isJust <$> addUrlFile relaxed url file
|
|
|
|
addurl = addUrlChecked relaxed url webUUID checkexistssize
|
|
|
|
checkexistssize = Url.withUrlOptions . Url.check url . keySize
|
|
|
|
|
2013-09-09 06:16:22 +00:00
|
|
|
#ifdef WITH_QUVI
|
2013-08-22 22:25:21 +00:00
|
|
|
performQuvi :: Bool -> URLString -> URLString -> FilePath -> CommandPerform
|
|
|
|
performQuvi relaxed pageurl videourl file = ifAnnexed file addurl geturl
|
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
quviurl = setDownloader pageurl QuviDownloader
|
2014-12-08 23:14:24 +00:00
|
|
|
addurl key = next $ do
|
|
|
|
cleanup webUUID quviurl file key Nothing
|
|
|
|
return True
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
geturl = next $ isJust <$> addUrlFileQuvi relaxed quviurl videourl file
|
2013-12-29 19:52:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_QUVI
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
addUrlFileQuvi :: Bool -> URLString -> URLString -> FilePath -> Annex (Maybe Key)
|
2013-12-29 19:52:20 +00:00
|
|
|
addUrlFileQuvi relaxed quviurl videourl file = do
|
|
|
|
key <- Backend.URL.fromUrl quviurl Nothing
|
|
|
|
ifM (pure relaxed <||> Annex.getState Annex.fast)
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
( do
|
2014-12-08 23:14:24 +00:00
|
|
|
cleanup webUUID quviurl file key Nothing
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
return (Just key)
|
2013-12-29 19:52:20 +00:00
|
|
|
, do
|
2014-01-04 19:38:59 +00:00
|
|
|
{- Get the size, and use that to check
|
|
|
|
- disk space. However, the size info is not
|
|
|
|
- retained, because the size of a video stream
|
|
|
|
- might change and we want to be able to download
|
|
|
|
- it later. -}
|
|
|
|
sizedkey <- addSizeUrlKey videourl key
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
prepGetViaTmpChecked sizedkey Nothing $ do
|
2014-02-26 20:52:56 +00:00
|
|
|
tmp <- fromRepo $ gitAnnexTmpObjectLocation key
|
2014-01-04 19:38:59 +00:00
|
|
|
showOutput
|
2014-03-22 14:42:38 +00:00
|
|
|
ok <- Transfer.notifyTransfer Transfer.Download (Just file) $
|
|
|
|
Transfer.download webUUID key (Just file) Transfer.forwardRetry $ const $ do
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir tmp)
|
|
|
|
downloadUrl [videourl] tmp
|
2014-01-04 19:38:59 +00:00
|
|
|
if ok
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
then do
|
2014-12-08 23:14:24 +00:00
|
|
|
cleanup webUUID quviurl file key (Just tmp)
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
return (Just key)
|
|
|
|
else return Nothing
|
2013-12-29 19:52:20 +00:00
|
|
|
)
|
2013-09-09 06:16:22 +00:00
|
|
|
#endif
|
2011-10-31 20:46:51 +00:00
|
|
|
|
2014-12-08 23:14:24 +00:00
|
|
|
addUrlChecked :: Bool -> URLString -> UUID -> (Key -> Annex (Bool, Bool)) -> Key -> CommandPerform
|
|
|
|
addUrlChecked relaxed url u checkexistssize key
|
|
|
|
| relaxed = do
|
|
|
|
setUrlPresent u key url
|
|
|
|
next $ return True
|
|
|
|
| otherwise = ifM (elem url <$> getUrls key)
|
2014-12-11 19:49:40 +00:00
|
|
|
( next $ return True -- nothing to do
|
2014-12-08 23:14:24 +00:00
|
|
|
, do
|
|
|
|
(exists, samesize) <- checkexistssize key
|
|
|
|
if exists && samesize
|
|
|
|
then do
|
|
|
|
setUrlPresent u key url
|
|
|
|
next $ return True
|
|
|
|
else do
|
|
|
|
warning $ "while adding a new url to an already annexed file, " ++ if exists
|
|
|
|
then "url does not have expected file size (use --relaxed to bypass this check) " ++ url
|
|
|
|
else "failed to verify url exists: " ++ url
|
|
|
|
stop
|
|
|
|
)
|
2011-08-06 18:57:22 +00:00
|
|
|
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
addUrlFile :: Bool -> URLString -> FilePath -> Annex (Maybe Key)
|
2013-07-28 19:27:36 +00:00
|
|
|
addUrlFile relaxed url file = do
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir file)
|
|
|
|
ifM (Annex.getState Annex.fast <||> pure relaxed)
|
|
|
|
( nodownload relaxed url file
|
2014-12-08 23:14:24 +00:00
|
|
|
, downloadWeb url file
|
2013-07-28 19:27:36 +00:00
|
|
|
)
|
|
|
|
|
2014-12-08 23:14:24 +00:00
|
|
|
downloadWeb :: URLString -> FilePath -> Annex (Maybe Key)
|
|
|
|
downloadWeb url file = do
|
2014-01-04 19:38:59 +00:00
|
|
|
dummykey <- addSizeUrlKey url =<< Backend.URL.fromUrl url Nothing
|
2014-12-08 23:14:24 +00:00
|
|
|
let downloader f _ = do
|
|
|
|
showOutput
|
|
|
|
downloadUrl [url] f
|
|
|
|
showAction $ "downloading " ++ url ++ " "
|
|
|
|
downloadWith downloader dummykey webUUID url file
|
|
|
|
|
|
|
|
{- The Key should be a dummy key, based on the URL, which is used
|
|
|
|
- for this download, before we can examine the file and find its real key.
|
|
|
|
- For resuming downloads to work, the dummy key for a given url should be
|
|
|
|
- stable. -}
|
|
|
|
downloadWith :: (FilePath -> MeterUpdate -> Annex Bool) -> Key -> UUID -> URLString -> FilePath -> Annex (Maybe Key)
|
|
|
|
downloadWith downloader dummykey u url file =
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
prepGetViaTmpChecked dummykey Nothing $ do
|
2014-02-26 20:52:56 +00:00
|
|
|
tmp <- fromRepo $ gitAnnexTmpObjectLocation dummykey
|
2014-12-08 23:14:24 +00:00
|
|
|
ifM (runtransfer tmp)
|
2014-01-04 19:08:06 +00:00
|
|
|
( do
|
|
|
|
backend <- chooseBackend file
|
|
|
|
let source = KeySource
|
|
|
|
{ keyFilename = file
|
|
|
|
, contentLocation = tmp
|
|
|
|
, inodeCache = Nothing
|
|
|
|
}
|
|
|
|
k <- genKey source backend
|
|
|
|
case k of
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
Nothing -> return Nothing
|
|
|
|
Just (key, _) -> do
|
2014-12-08 23:14:24 +00:00
|
|
|
cleanup u url file key (Just tmp)
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
return (Just key)
|
|
|
|
, return Nothing
|
2014-01-04 19:08:06 +00:00
|
|
|
)
|
2013-04-11 20:14:17 +00:00
|
|
|
where
|
2014-12-08 23:14:24 +00:00
|
|
|
runtransfer tmp = Transfer.notifyTransfer Transfer.Download (Just file) $
|
|
|
|
Transfer.download webUUID dummykey (Just file) Transfer.forwardRetry $ \p -> do
|
2013-04-11 20:14:17 +00:00
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir tmp)
|
2014-12-08 23:14:24 +00:00
|
|
|
downloader tmp p
|
2013-04-11 17:35:52 +00:00
|
|
|
|
2014-01-04 19:38:59 +00:00
|
|
|
{- 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
|
2014-02-25 02:00:25 +00:00
|
|
|
size <- snd <$> Url.withUrlOptions (Url.exists url)
|
2014-01-04 19:38:59 +00:00
|
|
|
return $ key { keySize = size }
|
|
|
|
|
2014-12-08 23:14:24 +00:00
|
|
|
cleanup :: UUID -> URLString -> FilePath -> Key -> Maybe FilePath -> Annex ()
|
|
|
|
cleanup u url file key mtmp = do
|
2013-04-11 17:35:52 +00:00
|
|
|
when (isJust mtmp) $
|
|
|
|
logStatus key InfoPresent
|
2014-12-08 23:14:24 +00:00
|
|
|
setUrlPresent u key url
|
2013-09-25 20:07:11 +00:00
|
|
|
Command.Add.addLink file key Nothing
|
2013-04-11 17:35:52 +00:00
|
|
|
whenM isDirect $ do
|
|
|
|
void $ addAssociatedFile key file
|
|
|
|
{- For moveAnnex to work in direct mode, the symlink
|
|
|
|
- must already exist, so flush the queue. -}
|
|
|
|
Annex.Queue.flush
|
|
|
|
maybe noop (moveAnnex key) mtmp
|
2011-07-01 21:15:46 +00:00
|
|
|
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
nodownload :: Bool -> URLString -> FilePath -> Annex (Maybe Key)
|
2013-03-11 23:55:01 +00:00
|
|
|
nodownload relaxed url file = do
|
|
|
|
(exists, size) <- if relaxed
|
|
|
|
then pure (True, Nothing)
|
2014-02-25 02:00:25 +00:00
|
|
|
else Url.withUrlOptions (Url.exists url)
|
2012-02-18 15:44:21 +00:00
|
|
|
if exists
|
|
|
|
then do
|
Fix a few bugs involving filenames that are at or near the filesystem's maximum filename length limit.
Started with a problem when running addurl on a really long url,
because the whole url is munged into the filename. Ended up doing
a fairly extensive review for places where filenames could get too large,
although it's hard to say I'm not missed any..
Backend.Url had a 128 character limit, which is fine when the limit is 255,
but not if it's a lot shorter on some systems. So check the pathconf()
limit. Note that this could result in fromUrl creating different keys
for the same url, if run on systems with different limits. I don't see
this is likely to cause any problems. That can already happen when using
addurl --fast, or if the content of an url changes.
Both Command.AddUrl and Backend.Url assumed that urls don't contain a
lot of multi-byte unicode, and would fail to truncate an url that did
properly.
A few places use a filename as the template to make a temp file.
While that's nice in that the temp file name can be easily related back to
the original filename, it could lead to `git annex add` failing to add a
filename that was at or close to the maximum length.
Note that in Command.Add.lockdown, the template is still derived from the
filename, just with enough space left to turn it into a temp file.
This is an important optimisation, because the assistant may lock down
a bunch of files all at once, and using the same template for all of them
would cause openTempFile to iterate through the same set of names,
looking for an unused temp file. I'm not very happy with the relatedTemplate
hack, but it avoids that slowdown.
Backend.WORM does not limit the filename stored in the key.
I have not tried to change that; so git annex add will fail on really long
filenames when using the WORM backend. It seems better to preserve the
invariant that a WORM key always contains the complete filename, since
the filename is the only unique material in the key, other than mtime and
size. Since nobody has complained about add failing (I think I saw it
once?) on WORM, probably it's ok, or nobody but me uses it.
There may be compatability problems if using git annex addurl --fast
or the WORM backend on a system with the 255 limit and then trying to use
that repo in a system with a smaller limit. I have not tried to deal with
those.
This commit was sponsored by Alexander Brem. Thanks!
2013-07-30 21:49:11 +00:00
|
|
|
key <- Backend.URL.fromUrl url size
|
2014-12-08 23:14:24 +00:00
|
|
|
cleanup webUUID url file key Nothing
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
return (Just key)
|
2012-02-18 15:44:21 +00:00
|
|
|
else do
|
|
|
|
warning $ "unable to access url: " ++ url
|
import metadata from feeds
When annex.genmetadata is set, metadata from the feed is added to files
that are imported from it.
Reused the same feedtitle and itemtitle, feedauthor, itemauthor, etc names
that are used in --template.
Also added title and author, which are the item title/author if available,
falling back to the feed title/author. These are more likely to be common
metadata fields.
(There is a small bit of dupication here, but once git gets
around to packing the object, it will compress it away.)
The itempubdate field is not included in the metadata as a string; instead
it is used to generate year and month fields, same as is done when adding
files with annex.genmetadata set.
This commit was sponsored by Amitai Schlair, who cooincidentially
is responsible for ikiwiki generating nice feed metadata!
2014-07-03 17:46:09 +00:00
|
|
|
return Nothing
|
2011-08-06 18:57:22 +00:00
|
|
|
|
Fix a few bugs involving filenames that are at or near the filesystem's maximum filename length limit.
Started with a problem when running addurl on a really long url,
because the whole url is munged into the filename. Ended up doing
a fairly extensive review for places where filenames could get too large,
although it's hard to say I'm not missed any..
Backend.Url had a 128 character limit, which is fine when the limit is 255,
but not if it's a lot shorter on some systems. So check the pathconf()
limit. Note that this could result in fromUrl creating different keys
for the same url, if run on systems with different limits. I don't see
this is likely to cause any problems. That can already happen when using
addurl --fast, or if the content of an url changes.
Both Command.AddUrl and Backend.Url assumed that urls don't contain a
lot of multi-byte unicode, and would fail to truncate an url that did
properly.
A few places use a filename as the template to make a temp file.
While that's nice in that the temp file name can be easily related back to
the original filename, it could lead to `git annex add` failing to add a
filename that was at or close to the maximum length.
Note that in Command.Add.lockdown, the template is still derived from the
filename, just with enough space left to turn it into a temp file.
This is an important optimisation, because the assistant may lock down
a bunch of files all at once, and using the same template for all of them
would cause openTempFile to iterate through the same set of names,
looking for an unused temp file. I'm not very happy with the relatedTemplate
hack, but it avoids that slowdown.
Backend.WORM does not limit the filename stored in the key.
I have not tried to change that; so git annex add will fail on really long
filenames when using the WORM backend. It seems better to preserve the
invariant that a WORM key always contains the complete filename, since
the filename is the only unique material in the key, other than mtime and
size. Since nobody has complained about add failing (I think I saw it
once?) on WORM, probably it's ok, or nobody but me uses it.
There may be compatability problems if using git annex addurl --fast
or the WORM backend on a system with the 255 limit and then trying to use
that repo in a system with a smaller limit. I have not tried to deal with
those.
This commit was sponsored by Alexander Brem. Thanks!
2013-07-30 21:49:11 +00:00
|
|
|
url2file :: URI -> Maybe Int -> Int -> FilePath
|
|
|
|
url2file url pathdepth pathmax = case pathdepth of
|
2013-10-05 17:32:42 +00:00
|
|
|
Nothing -> truncateFilePath pathmax $ sanitizeFilePath fullurl
|
2012-02-16 16:25:19 +00:00
|
|
|
Just depth
|
2013-07-05 16:46:38 +00:00
|
|
|
| depth >= length urlbits -> frombits id
|
2012-02-16 18:26:53 +00:00
|
|
|
| depth > 0 -> frombits $ drop depth
|
2012-02-16 18:28:17 +00:00
|
|
|
| depth < 0 -> frombits $ reverse . take (negate depth) . reverse
|
|
|
|
| otherwise -> error "bad --pathdepth"
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2014-12-08 23:14:24 +00:00
|
|
|
fullurl = concat
|
|
|
|
[ maybe "" uriRegName (uriAuthority url)
|
|
|
|
, uriPath url
|
|
|
|
, uriQuery url
|
|
|
|
]
|
2013-04-23 00:24:53 +00:00
|
|
|
frombits a = intercalate "/" $ a urlbits
|
2013-10-05 17:30:13 +00:00
|
|
|
urlbits = map (truncateFilePath pathmax . sanitizeFilePath) $
|
|
|
|
filter (not . null) $ split "/" fullurl
|
2014-12-11 20:09:56 +00:00
|
|
|
|
|
|
|
urlString2file :: URLString -> Maybe Int -> Int -> FilePath
|
|
|
|
urlString2file s pathdepth pathmax = case Url.parseURIRelaxed s of
|
|
|
|
Nothing -> error $ "bad uri " ++ s
|
|
|
|
Just u -> url2file u pathdepth pathmax
|