use subdir for addurl when it creates multiple files
The --file parameter specifies the subdir in this mode.
This commit is contained in:
parent
a941af0fe2
commit
bce7e0dd96
3 changed files with 22 additions and 25 deletions
|
@ -60,14 +60,10 @@ seek us = do
|
||||||
if Remote.uuid r == webUUID
|
if Remote.uuid r == webUUID
|
||||||
then void $ commandAction $ startWeb relaxed optfile pathdepth u
|
then void $ commandAction $ startWeb relaxed optfile pathdepth u
|
||||||
else do
|
else do
|
||||||
let handlecontents url c = case c of
|
pathmax <- liftIO $ fileNameLengthLimit "."
|
||||||
UrlContents sz mkf ->
|
let deffile = fromMaybe (urlString2file u pathdepth pathmax) optfile
|
||||||
void $ commandAction $
|
|
||||||
startRemote r relaxed optfile pathdepth url sz mkf
|
|
||||||
UrlNested l -> forM_ l $
|
|
||||||
uncurry handlecontents
|
|
||||||
res <- tryNonAsync $ maybe
|
res <- tryNonAsync $ maybe
|
||||||
(error "unable to checkUrl")
|
(error $ "unable to checkUrl of " ++ Remote.name r)
|
||||||
(flip id u)
|
(flip id u)
|
||||||
(Remote.checkUrl r)
|
(Remote.checkUrl r)
|
||||||
case res of
|
case res of
|
||||||
|
@ -75,20 +71,19 @@ seek us = do
|
||||||
showStart "addurl" u
|
showStart "addurl" u
|
||||||
warning (show e)
|
warning (show e)
|
||||||
next $ next $ return False
|
next $ next $ return False
|
||||||
Right c -> handlecontents u c
|
Right (UrlContents sz mf) -> do
|
||||||
|
void $ commandAction $
|
||||||
|
startRemote r relaxed (fromMaybe deffile mf) pathdepth u sz
|
||||||
|
Right (UrlMulti l) ->
|
||||||
|
forM_ l $ \(u', sz, f) ->
|
||||||
|
void $ commandAction $
|
||||||
|
startRemote r relaxed (deffile </> f) pathdepth u' sz
|
||||||
|
|
||||||
startRemote :: Remote -> Bool -> Maybe FilePath -> Maybe Int -> String -> Maybe Integer -> (FilePath -> FilePath) -> CommandStart
|
startRemote :: Remote -> Bool -> FilePath -> Maybe Int -> String -> Maybe Integer -> CommandStart
|
||||||
startRemote r relaxed optfile pathdepth s sz mkf = do
|
startRemote r relaxed file pathdepth s sz = do
|
||||||
url <- case Url.parseURIRelaxed s of
|
|
||||||
Nothing -> error $ "bad uri " ++ s
|
|
||||||
Just u -> pure u
|
|
||||||
pathmax <- liftIO $ fileNameLengthLimit "."
|
|
||||||
let file = mkf $ choosefile $ url2file url pathdepth pathmax
|
|
||||||
showStart "addurl" file
|
showStart "addurl" file
|
||||||
showNote $ "using " ++ Remote.name r
|
showNote $ "using " ++ Remote.name r
|
||||||
next $ performRemote r relaxed s file sz
|
next $ performRemote r relaxed s file sz
|
||||||
where
|
|
||||||
choosefile = flip fromMaybe optfile
|
|
||||||
|
|
||||||
performRemote :: Remote -> Bool -> URLString -> FilePath -> Maybe Integer -> CommandPerform
|
performRemote :: Remote -> Bool -> URLString -> FilePath -> Maybe Integer -> CommandPerform
|
||||||
performRemote r relaxed uri file sz = ifAnnexed file adduri geturi
|
performRemote r relaxed uri file sz = ifAnnexed file adduri geturi
|
||||||
|
@ -324,3 +319,8 @@ url2file url pathdepth pathmax = case pathdepth of
|
||||||
frombits a = intercalate "/" $ a urlbits
|
frombits a = intercalate "/" $ a urlbits
|
||||||
urlbits = map (truncateFilePath pathmax . sanitizeFilePath) $
|
urlbits = map (truncateFilePath pathmax . sanitizeFilePath) $
|
||||||
filter (not . null) $ split "/" fullurl
|
filter (not . null) $ split "/" fullurl
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -434,10 +434,8 @@ checkurl :: External -> URLString -> Annex UrlContents
|
||||||
checkurl external url =
|
checkurl external url =
|
||||||
handleRequest external (CHECKURL url) Nothing $ \req -> case req of
|
handleRequest external (CHECKURL url) Nothing $ \req -> case req of
|
||||||
CHECKURL_CONTENTS sz f -> Just $ return $ UrlContents sz
|
CHECKURL_CONTENTS sz f -> Just $ return $ UrlContents sz
|
||||||
(if null f then id else const f)
|
(if null f then Nothing else Just f)
|
||||||
CHECKURL_MULTI l -> Just $ return $ UrlNested $ map mknested l
|
CHECKURL_MULTI l -> Just $ return $ UrlMulti l
|
||||||
CHECKURL_FAILURE errmsg -> Just $ error errmsg
|
CHECKURL_FAILURE errmsg -> Just $ error errmsg
|
||||||
UNSUPPORTED_REQUEST -> error "CHECKURL not implemented by external special remote"
|
UNSUPPORTED_REQUEST -> error "CHECKURL not implemented by external special remote"
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
where
|
|
||||||
mknested (url', sz, f) = (url', UrlContents sz (const f))
|
|
||||||
|
|
|
@ -11,9 +11,8 @@ import Utility.Url
|
||||||
|
|
||||||
data UrlContents
|
data UrlContents
|
||||||
-- An URL contains a file, whose size may be known.
|
-- An URL contains a file, whose size may be known.
|
||||||
-- A default filename will be provided, and can be overridded
|
-- There might be a nicer filename to use.
|
||||||
-- or built on.
|
= UrlContents (Maybe Integer) (Maybe FilePath)
|
||||||
= UrlContents (Maybe Integer) (FilePath -> FilePath)
|
|
||||||
-- Sometimes an URL points to multiple files, each accessible
|
-- Sometimes an URL points to multiple files, each accessible
|
||||||
-- by their own URL.
|
-- by their own URL.
|
||||||
| UrlNested [(URLString, UrlContents)]
|
| UrlMulti [(URLString, Maybe Integer, FilePath)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue