more OsPath conversion
Sponsored-by: mycroft
This commit is contained in:
parent
917c43f31f
commit
22c2451e26
11 changed files with 46 additions and 44 deletions
|
@ -17,9 +17,9 @@ import Utility.Url (URLString)
|
|||
#ifdef mingw32_HOST_OS
|
||||
import Utility.Split
|
||||
#endif
|
||||
import Utility.FileSystemEncoding
|
||||
import Utility.OsPath
|
||||
|
||||
import System.FilePath.Posix -- for manipulating url paths
|
||||
import qualified System.FilePath.Posix as UrlPath
|
||||
import Network.Protocol.HTTP.DAV (inDAVLocation, DAVT)
|
||||
import Control.Monad.IO.Class (MonadIO)
|
||||
import Network.URI
|
||||
|
@ -30,28 +30,29 @@ type DavLocation = String
|
|||
|
||||
{- Runs action with a new location relative to the current location. -}
|
||||
inLocation :: (MonadIO m) => DavLocation -> DAVT m a -> DAVT m a
|
||||
inLocation d = inDAVLocation (</> d')
|
||||
inLocation d = inDAVLocation (UrlPath.</> d')
|
||||
where
|
||||
d' = escapeURIString isUnescapedInURI d
|
||||
|
||||
{- The directory where files(s) for a key are stored. -}
|
||||
keyDir :: Key -> DavLocation
|
||||
keyDir k = addTrailingPathSeparator $ hashdir </> fromRawFilePath (keyFile k)
|
||||
keyDir k = UrlPath.addTrailingPathSeparator $
|
||||
hashdir UrlPath.</> fromOsPath (keyFile k)
|
||||
where
|
||||
#ifndef mingw32_HOST_OS
|
||||
hashdir = fromRawFilePath $ hashDirLower def k
|
||||
hashdir = fromOsPath $ hashDirLower def k
|
||||
#else
|
||||
hashdir = replace "\\" "/" (fromRawFilePath $ hashDirLower def k)
|
||||
hashdir = replace "\\" "/" (fromOsPath $ hashDirLower def k)
|
||||
#endif
|
||||
|
||||
keyLocation :: Key -> DavLocation
|
||||
keyLocation k = keyDir k ++ fromRawFilePath (keyFile k)
|
||||
keyLocation k = keyDir k ++ fromOsPath (keyFile k)
|
||||
|
||||
{- Paths containing # or ? cannot be represented in an url, so fails on
|
||||
- those. -}
|
||||
exportLocation :: ExportLocation -> Either String DavLocation
|
||||
exportLocation l =
|
||||
let p = fromRawFilePath $ fromExportLocation l
|
||||
let p = fromOsPath $ fromExportLocation l
|
||||
in if any (`elem` p) illegalinurl
|
||||
then Left ("Cannot store file containing '#' or '?' on webdav: " ++ p)
|
||||
else Right p
|
||||
|
@ -60,7 +61,7 @@ exportLocation l =
|
|||
|
||||
{- Where we store temporary data for a key as it's being uploaded. -}
|
||||
keyTmpLocation :: Key -> DavLocation
|
||||
keyTmpLocation = tmpLocation . fromRawFilePath . keyFile
|
||||
keyTmpLocation = tmpLocation . fromOsPath . keyFile
|
||||
|
||||
{- Where we store temporary data for a file as it's being exported.
|
||||
-
|
||||
|
@ -72,10 +73,11 @@ keyTmpLocation = tmpLocation . fromRawFilePath . keyFile
|
|||
-}
|
||||
exportTmpLocation :: ExportLocation -> Key -> DavLocation
|
||||
exportTmpLocation l k
|
||||
| length (splitDirectories p) > 1 = takeDirectory p </> keyTmpLocation k
|
||||
| length (UrlPath.splitDirectories p) > 1 =
|
||||
UrlPath.takeDirectory p UrlPath.</> keyTmpLocation k
|
||||
| otherwise = keyTmpLocation k
|
||||
where
|
||||
p = fromRawFilePath (fromExportLocation l)
|
||||
p = fromOsPath (fromExportLocation l)
|
||||
|
||||
tmpLocation :: FilePath -> DavLocation
|
||||
tmpLocation f = "git-annex-webdav-tmp-" ++ f
|
||||
|
@ -86,7 +88,7 @@ locationParent loc
|
|||
| otherwise = Just parent
|
||||
where
|
||||
tops = ["/", "", "."]
|
||||
parent = takeDirectory loc
|
||||
parent = UrlPath.takeDirectory loc
|
||||
|
||||
locationUrl :: URLString -> DavLocation -> URLString
|
||||
locationUrl baseurl loc = baseurl </> loc
|
||||
locationUrl baseurl loc = baseurl UrlPath.</> loc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue