Lifted from agda/agda#8116 (comment):
import System.Directory
import System.FilePath
list :: FilePath -> IO ()
list dir = do
putStrLn $ replicate 66 '-'
putStrLn dir
putStrLn $ replicate 66 '-'
mapM_ (putStrLn . ("- " ++)) . take 2 =<< listDirectory dir
up :: FilePath -> IO FilePath
up dir = canonicalizePath (dir </> "..")
upIO :: IO FilePath -> IO FilePath
upIO = (up =<<)
-- https://stackoverflow.com/questions/2787203/unc-path-to-a-folder-on-my-local-computer
main :: IO ()
main = do
-- let dir = "\\\\?\\C:\\Users\\admin"
let dir = "\\\\localhost\\C$\\Users\\admin"
let ups = take 4 $ iterate upIO (pure dir)
mapM_ (list =<<) ups
This produces:
------------------------------------------------------------------
\\localhost\C$\Users\admin
------------------------------------------------------------------
- VirtualBox VMs
- Videos
------------------------------------------------------------------
\\localhost\C$\Users
------------------------------------------------------------------
- Public
- desktop.ini
------------------------------------------------------------------
\\localhost\C$
------------------------------------------------------------------
- Windows
- Users
------------------------------------------------------------------
\\localhost\
------------------------------------------------------------------
test-directory: Uncaught exception ghc-internal:GHC.Internal.IO.Exception.IOExce
ption:
\\localhost\: getDirectoryContents:findFirstFile: does not exist (The specified
path is invalid.)
While handling findFirstFile: does not exist (The specified path is invalid.)
In contrast, "\\\\?\\C:\\Users\\admin" is treated correctly. Canonicalization turns this into C:\Users\admin.
There is a suspicion that canonicalizePath does not work correctly on UNC pathes.
The unitests for canonicalizePath seem to steer clear of UNC paths, except for this one:
|
when isWindows $ do |
|
-- https://github.com/haskell/directory/issues/170 |
|
T(expectEq) () "\\\\localhost" =<< canonicalizePath "\\\\localhost" |
Lifted from agda/agda#8116 (comment):
This produces:
In contrast,
"\\\\?\\C:\\Users\\admin"is treated correctly. Canonicalization turns this intoC:\Users\admin.There is a suspicion that
canonicalizePathdoes not work correctly on UNC pathes.The unitests for
canonicalizePathseem to steer clear of UNC paths, except for this one:directory/tests/CanonicalizePath.hs
Lines 164 to 166 in 6442a3c