2014-08-07 19:45:56 +00:00
|
|
|
{- WebDAV locations.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-08-07 19:45:56 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
|
|
|
|
module Remote.WebDAV.DavLocation where
|
|
|
|
|
|
|
|
import Types
|
2017-09-15 20:34:45 +00:00
|
|
|
import Types.Export
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Locations
|
2014-08-07 19:45:56 +00:00
|
|
|
import Utility.Url (URLString)
|
2017-05-16 03:32:17 +00:00
|
|
|
#ifdef mingw32_HOST_OS
|
|
|
|
import Utility.Split
|
|
|
|
#endif
|
2014-08-07 19:45:56 +00:00
|
|
|
|
|
|
|
import System.FilePath.Posix -- for manipulating url paths
|
|
|
|
import Network.Protocol.HTTP.DAV (inDAVLocation, DAVT)
|
|
|
|
import Control.Monad.IO.Class (MonadIO)
|
2017-09-12 19:45:03 +00:00
|
|
|
import Network.URI
|
2015-01-28 19:55:17 +00:00
|
|
|
import Data.Default
|
2014-08-07 19:45:56 +00:00
|
|
|
|
|
|
|
-- Relative to the top of the DAV url.
|
|
|
|
type DavLocation = String
|
|
|
|
|
2017-09-12 19:45:03 +00:00
|
|
|
{- Runs action with a new location relative to the current location. -}
|
2014-08-07 19:45:56 +00:00
|
|
|
inLocation :: (MonadIO m) => DavLocation -> DAVT m a -> DAVT m a
|
2017-09-12 19:45:03 +00:00
|
|
|
inLocation d = inDAVLocation (</> d')
|
|
|
|
where
|
|
|
|
d' = escapeURIString isUnescapedInURI d
|
2014-08-07 19:45:56 +00:00
|
|
|
|
|
|
|
{- The directory where files(s) for a key are stored. -}
|
2014-08-08 17:40:55 +00:00
|
|
|
keyDir :: Key -> DavLocation
|
|
|
|
keyDir k = addTrailingPathSeparator $ hashdir </> keyFile k
|
2014-08-07 19:45:56 +00:00
|
|
|
where
|
|
|
|
#ifndef mingw32_HOST_OS
|
2015-01-28 19:55:17 +00:00
|
|
|
hashdir = hashDirLower def k
|
2014-08-07 19:45:56 +00:00
|
|
|
#else
|
2015-01-28 19:55:17 +00:00
|
|
|
hashdir = replace "\\" "/" (hashDirLower def k)
|
2014-08-07 19:45:56 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-08 17:40:55 +00:00
|
|
|
keyLocation :: Key -> DavLocation
|
|
|
|
keyLocation k = keyDir k ++ keyFile k
|
|
|
|
|
2017-09-15 19:52:31 +00:00
|
|
|
exportLocation :: ExportLocation -> DavLocation
|
2017-09-18 17:57:25 +00:00
|
|
|
exportLocation = fromExportLocation
|
2017-09-15 19:52:31 +00:00
|
|
|
|
2014-08-07 19:45:56 +00:00
|
|
|
{- Where we store temporary data for a key as it's being uploaded. -}
|
|
|
|
keyTmpLocation :: Key -> DavLocation
|
2016-02-09 15:50:40 +00:00
|
|
|
keyTmpLocation = tmpLocation . keyFile
|
2014-08-07 19:45:56 +00:00
|
|
|
|
|
|
|
tmpLocation :: FilePath -> DavLocation
|
2017-09-15 19:52:31 +00:00
|
|
|
tmpLocation f = "git-annex-webdav-tmp-" ++ f
|
2014-08-07 19:45:56 +00:00
|
|
|
|
|
|
|
locationParent :: String -> Maybe String
|
|
|
|
locationParent loc
|
2017-10-11 15:09:27 +00:00
|
|
|
| loc `elem` tops || parent `elem` tops = Nothing
|
|
|
|
| otherwise = Just parent
|
2014-08-07 19:45:56 +00:00
|
|
|
where
|
|
|
|
tops = ["/", "", "."]
|
2017-10-11 15:09:27 +00:00
|
|
|
parent = takeDirectory loc
|
2014-08-07 19:45:56 +00:00
|
|
|
|
|
|
|
locationUrl :: URLString -> DavLocation -> URLString
|
|
|
|
locationUrl baseurl loc = baseurl </> loc
|