From c98db302baedde5e03b17ece264c34bfa1e276e4 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Fri, 25 Dec 2015 15:18:05 +0100 Subject: [PATCH] LIB: normalize instead of canonicalizePath' We shouldn't follow symlinks in our internal paths, because that makes us lose information. However, we normalize where we could have passed user input, so we don't end up with ill-formed anchors/names. --- src/Data/DirTree.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Data/DirTree.hs b/src/Data/DirTree.hs index c7d8e27..afdb2d3 100644 --- a/src/Data/DirTree.hs +++ b/src/Data/DirTree.hs @@ -390,7 +390,7 @@ readFileWith ff p = do readFile :: FilePath -> IO (AnchoredFile FileInfo) -readFile fp = readFileWith getFileInfo =<< canonicalizePath' fp +readFile fp = readFileWith getFileInfo $ normalize fp -- |Build a list of AnchoredFile, given the path to a directory, filling @@ -398,7 +398,7 @@ readFile fp = readFileWith getFileInfo =<< canonicalizePath' fp -- directories. readDirectory :: FilePath -> IO [AnchoredFile FileInfo] readDirectory fp = readDirectoryWith getAllDirsFiles getFileInfo - =<< canonicalizePath' fp + $ normalize fp -- |Build a list of AnchoredFile, given the path to a directory, filling @@ -406,7 +406,7 @@ readDirectory fp = readDirectoryWith getAllDirsFiles getFileInfo -- directories. readDirectory' :: FilePath -> IO [AnchoredFile FileInfo] readDirectory' fp = readDirectoryWith getDirsFiles getFileInfo - =<< canonicalizePath' fp + $ normalize fp -- | same as readDirectory but allows us to, for example, use @@ -416,7 +416,7 @@ readDirectoryWith :: (FilePath -> IO [FilePath]) -> FilePath -> IO [AnchoredFile a] readDirectoryWith getfiles ff p = do - contents <- getfiles =<< canonicalizePath' p + contents <- getfiles $ normalize p cs <- mapM (\x -> readFileWith ff $ p x) contents return $ removeNonexistent cs @@ -576,7 +576,7 @@ goUp (bp :/ _) = Data.DirTree.readFile bp -- |Go up one directory in the filesystem hierarchy. goUp' :: FilePath -> IO (AnchoredFile FileInfo) goUp' fp = do - cfp <- canonicalizePath' fp + let cfp = normalize fp Data.DirTree.readFile $ baseDir cfp