summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-11 19:55:01 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-11 19:55:01 -0400
commit8cdbe8fe29ccd7f1d2bc0daeaacd3a88427d40c2 (patch)
tree9f53c20d153c2f1e1d7ae2b4699102ede5142b7b /Command
parentdfc7b3351c4b10681f48dfa347a2308a2eb63489 (diff)
addurl: Add --relaxed option.
Diffstat (limited to 'Command')
-rw-r--r--Command/AddUrl.hs30
1 files changed, 18 insertions, 12 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs
index 41a947db8..cf8aae17c 100644
--- a/Command/AddUrl.hs
+++ b/Command/AddUrl.hs
@@ -25,7 +25,7 @@ import Config
import Annex.Content.Direct
def :: [Command]
-def = [notBareRepo $ withOptions [fileOption, pathdepthOption] $
+def = [notBareRepo $ withOptions [fileOption, pathdepthOption, relaxedOption] $
command "addurl" (paramRepeating paramUrl) seek "add urls to annex"]
fileOption :: Option
@@ -34,28 +34,32 @@ fileOption = Option.field [] "file" paramFile "specify what file the url is adde
pathdepthOption :: Option
pathdepthOption = Option.field [] "pathdepth" paramNumber "path components to use in filename"
+relaxedOption :: Option
+relaxedOption = Option.flag [] "relaxed" "skip size check"
+
seek :: [CommandSeek]
seek = [withField fileOption return $ \f ->
+ withFlag relaxedOption $ \relaxed ->
withField pathdepthOption (return . maybe Nothing readish) $ \d ->
- withStrings $ start f d]
+ withStrings $ start relaxed f d]
-start :: Maybe FilePath -> Maybe Int -> String -> CommandStart
-start optfile pathdepth s = go $ fromMaybe bad $ parseURI s
+start :: Bool -> Maybe FilePath -> Maybe Int -> String -> CommandStart
+start relaxed optfile pathdepth s = go $ fromMaybe bad $ parseURI s
where
bad = fromMaybe (error $ "bad url " ++ s) $
parseURI $ escapeURIString isUnescapedInURI s
go url = do
let file = fromMaybe (url2file url pathdepth) optfile
showStart "addurl" file
- next $ perform s file
+ next $ perform relaxed s file
-perform :: String -> FilePath -> CommandPerform
-perform url file = ifAnnexed file addurl geturl
+perform :: Bool -> String -> FilePath -> CommandPerform
+perform relaxed url file = ifAnnexed file addurl geturl
where
geturl = do
liftIO $ createDirectoryIfMissing True (parentDir file)
- ifM (Annex.getState Annex.fast)
- ( nodownload url file , download url file )
+ ifM (Annex.getState Annex.fast <||> pure relaxed)
+ ( nodownload relaxed url file , download url file )
addurl (key, _backend) = do
headers <- getHttpHeaders
ifM (liftIO $ Url.check url headers $ keySize key)
@@ -90,10 +94,12 @@ download url file = do
setUrlPresent key url
next $ Command.Add.cleanup file key True
-nodownload :: String -> FilePath -> CommandPerform
-nodownload url file = do
+nodownload :: Bool -> String -> FilePath -> CommandPerform
+nodownload relaxed url file = do
headers <- getHttpHeaders
- (exists, size) <- liftIO $ Url.exists url headers
+ (exists, size) <- if relaxed
+ then pure (True, Nothing)
+ else liftIO $ Url.exists url headers
if exists
then do
let key = Backend.URL.fromUrl url size