Skip to content

canonicalizePath "\\\\localhost\\C$\.." incorrectly produces "\\\\localhost\\" #206

Description

@andreasabel

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: (1) bugThe described behavior is not working as intended.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions