Opened 7 years ago

Closed 2 years ago

Last modified 2 years ago

#4215 closed bug (fixed)

canonicalizePath behaves strangely with paths that do not exist

Reported by: creswick Owned by: ekmett
Priority: low Milestone: 8.0.1
Component: Core Libraries Version: 6.12.3
Keywords: Cc: pho@…, the.dead.shall.rise@…, core-libraries-committee@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The behavior of System.Directory.canonicalizePath is not documented (and perhaps not defined) for paths that do not exist on the file system. The documentation should, minimally, indicate that this is the case. Ideally, the behavior would be well-defined.

This is complicated by differing behaviors of the underlying realpath(char*, char*) function in Linux and OS X. On Linux, realpath changes its behavior if the last existing portion of the input path is a file vs. a directory, while OS X does not alter behavior in these two cases. Specifically, assume the following:

  • $HOME/tmp/foo is a file.
  • $HOME/tmp/bar is a directory.
  • $HOME/tmp/baz does not exist.

Linux:

Prelude System.Directory> canonicalizePath "/home/creswick/tmp/foo/subdir"
"/home/creswick/tmp/foo"
Prelude System.Directory> canonicalizePath "/home/creswick/tmp/bar/subdir"
"/home/creswick/tmp/bar/subdir"
Prelude System.Directory> canonicalizePath "/home/creswick/tmp/baz/subdir"
"/home/creswick/tmp/baz"

OS-X:

Prelude System.Directory> canonicalizePath "/Users/hudson/tmp/foo/subdir"                                                           
"/Users/hudson/tmp/foo/subdir"
Prelude System.Directory> canonicalizePath "/Users/hudson/tmp/bar/subdir"
"/Users/hudson/tmp/bar/subdir"
Prelude System.Directory> canonicalizePath "/Users/hudson/tmp/baz/subdir"
"/Users/hudson/tmp/baz"

Change History (17)

comment:1 Changed 7 years ago by igloo

Milestone: 6.14.1

comment:2 Changed 7 years ago by PHO

Cc: pho@… added

comment:3 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:4 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:5 Changed 7 years ago by batterseapower

Another complication is that according to T4113 on Windows:

canonicalizePath "/no/such/file" == "C:\\no\\such\\file"

This function should probably be fixed so that it never fails just because the file is missing. Current behaviour is causing T4113 to fail on OS X because on OS X:

canonicalizePath "" == getCurrentDirectory

But on other platforms it throws an exception.

comment:6 Changed 7 years ago by maeder

With ghc-7.0.2 (directory-1.1.0.0) I get (under linux)

canonicalizePath: does not exist (No such file or directory)

whereas I do not get this exception with ghc-6.12.3 (directory-1.0.1.1)

comment:7 Changed 6 years ago by igloo

See also #4480, #5014.

comment:8 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:9 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:10 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:11 Changed 5 years ago by refold

Cc: the.dead.shall.rise@… added

comment:12 Changed 3 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:13 Changed 3 years ago by thoughtpolice

Component: libraries/directoryCore Libraries
Owner: set to ekmett

Moving over to new owning component 'Core Libraries'.

comment:14 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:15 Changed 3 years ago by ekmett

Cc: core-libraries-committee@… added
Status: newupstream

comment:16 Changed 2 years ago by Rufflewind

Resolution: fixed
Status: upstreamclosed

Fixed upstream.

comment:17 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

Note: See TracTickets for help on using tickets.