aboutsummaryrefslogtreecommitdiff
path: root/Command/AddUrl.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-02-16 14:26:53 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-02-16 14:26:53 -0400
commit346c9344094635edbcf85ac6ddb27b8235038d8a (patch)
treebfb4c8d7ea6441b3c20d8c490436dd96102c50f0 /Command/AddUrl.hs
parentc2245260b1e6e3bd9a8827449fea2c0eafe7e0f2 (diff)
allow pathdepth to drop from the front or take from the end (negative)
Diffstat (limited to 'Command/AddUrl.hs')
-rw-r--r--Command/AddUrl.hs9
1 files changed, 4 insertions, 5 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs
index 986736943..0b4131067 100644
--- a/Command/AddUrl.hs
+++ b/Command/AddUrl.hs
@@ -90,13 +90,12 @@ url2file :: URI -> Maybe Int -> FilePath
url2file url pathdepth = case pathdepth of
Nothing -> filesize $ escape fullurl
Just depth
- | depth > 0 -> filesize $ join "/" $
- fromend depth $ map escape $
- filter (not . null) $ split "/" fullurl
- | otherwise -> error "bad --pathdepth value"
+ | depth > 0 -> frombits $ drop depth
+ | otherwise -> frombits $ reverse . take (negate depth) . reverse
where
fullurl = uriRegName auth ++ uriPath url ++ uriQuery url
+ frombits a = filesize $ join "/" $ a urlbits
+ urlbits = map escape $ filter (not . null) $ split "/" fullurl
auth = fromMaybe (error $ "bad url " ++ show url) $ uriAuthority url
filesize = take 255
escape = replace "/" "_" . replace "?" "_"
- fromend n = reverse . take n . reverse