remove SafeFilePath

Move sanitizeFilePath call to where fromSafeFilePath had been.
This commit is contained in:
Joey Hess 2020-05-11 14:04:56 -04:00
parent cabbc91b18
commit 5f5170b22b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 16 additions and 32 deletions

View file

@ -7,35 +7,14 @@
module Types.UrlContents (
UrlContents(..),
SafeFilePath,
mkSafeFilePath,
fromSafeFilePath
) where
import Utility.Url
import Annex.UntrustedFilePath
import System.FilePath
data UrlContents
-- An URL contains a file, whose size may be known.
-- There might be a nicer filename to use.
= UrlContents (Maybe Integer) (Maybe SafeFilePath)
= UrlContents (Maybe Integer) (Maybe FilePath)
-- Sometimes an URL points to multiple files, each accessible
-- by their own URL.
| UrlMulti [(URLString, Maybe Integer, SafeFilePath)]
-- This is a FilePath, from an untrusted source,
-- sanitized so it doesn't contain any directory traversal tricks
-- and is always relative. It can still contain subdirectories.
-- Any unusual characters are also filtered out.
newtype SafeFilePath = SafeFilePath FilePath
deriving (Show)
mkSafeFilePath :: FilePath -> SafeFilePath
mkSafeFilePath p = SafeFilePath $ if null p' then "file" else p'
where
p' = joinPath $ map sanitizeFilePath $ splitDirectories p
fromSafeFilePath :: SafeFilePath -> FilePath
fromSafeFilePath (SafeFilePath p) = p
| UrlMulti [(URLString, Maybe Integer, FilePath)]