Windows: Support urls like "file:///c:/path"
That is a legal url, but parseUrl parses it to "/c:/path" which is not a valid path on Windows. So as a workaround, use parseURIPortable everywhere, which removes the leading slash when run on windows. Note that if an url is parsed like this and then serialized back to a string, it will be different from the input. Which could potentially be a problem, but is probably not in practice. An alternative way to do it would be to have an uriPathPortable that fixes up the path after parsing. But it would be harder to make sure that is used everywhere, since uriPath is also used when constructing an URI. It's also worth noting that System.FilePath.normalize "/c:/path" yields "c:/path". The reason I didn't use it is that it also may change "/" to "\" in the path and I wanted to keep the url changes minimal. Also noticed that convertToWindowsNativeNamespace handles "/c:/path" the same as "c:/path". Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
This commit is contained in:
parent
3badde71ae
commit
cd076cd085
11 changed files with 45 additions and 14 deletions
|
@ -23,6 +23,7 @@ import Types.CleanupActions
|
|||
import Messages.Progress
|
||||
import Utility.Metered
|
||||
import Utility.Tmp
|
||||
import Utility.Url (parseURIPortable)
|
||||
import Backend.URL
|
||||
import Annex.Perms
|
||||
import Annex.Tmp
|
||||
|
@ -141,10 +142,10 @@ isSupportedUrl :: URLString -> Bool
|
|||
isSupportedUrl u = isTorrentMagnetUrl u || isTorrentUrl u
|
||||
|
||||
isTorrentUrl :: URLString -> Bool
|
||||
isTorrentUrl = maybe False (\u -> ".torrent" `isSuffixOf` uriPath u) . parseURI
|
||||
isTorrentUrl = maybe False (\u -> ".torrent" `isSuffixOf` uriPath u) . parseURIPortable
|
||||
|
||||
isTorrentMagnetUrl :: URLString -> Bool
|
||||
isTorrentMagnetUrl u = "magnet:" `isPrefixOf` u && checkbt (parseURI u)
|
||||
isTorrentMagnetUrl u = "magnet:" `isPrefixOf` u && checkbt (parseURIPortable u)
|
||||
where
|
||||
checkbt (Just uri) | "xt=urn:btih:" `isInfixOf` uriQuery uri = True
|
||||
checkbt _ = False
|
||||
|
|
4
Remote/External/Types.hs
vendored
4
Remote/External/Types.hs
vendored
|
@ -53,7 +53,7 @@ import Types.Export
|
|||
import Types.Availability (Availability(..))
|
||||
import Types.Key
|
||||
import Git.Types
|
||||
import Utility.Url (URLString)
|
||||
import Utility.Url (URLString, parseURIPortable)
|
||||
import qualified Utility.SimpleProtocol as Proto
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
@ -462,7 +462,7 @@ instance Proto.Serializable [(URLString, Size, FilePath)] where
|
|||
|
||||
instance Proto.Serializable URI where
|
||||
serialize = show
|
||||
deserialize = parseURI
|
||||
deserialize = parseURIPortable
|
||||
|
||||
instance Proto.Serializable ExportLocation where
|
||||
serialize = fromRawFilePath . fromExportLocation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue