Skip to content

canonicalizePath is no longer canonical for directories (trailing slashes) #63

@dcoutts

Description

@dcoutts

It used to be the case that canonicalizePath for directories would return the directory without the trailing slash, irrespective of whether the directory was given with or without the trailing slash. As of some version, but certainly including 1.2.6 and still in 1.2.7.1 the result sometimes includes a trailing slash and sometimes does not. This violates the property that the result be canonical.

$ ghci -package directory-1.2.7.1
> :m System.Directory
> canonicalizePath "./"
"/home/duncan/"
> canonicalizePath "."
"/home/duncan"
> canonicalizePath "./foo/"
"/home/duncan/foo/"
> canonicalizePath "./foo"
"/home/duncan/foo"

This canonical property is important, lots of code relies on it. As an example of the kind of bug it causes:

cabal new-build ./
Unknown build target './'.
The project has no package directory './'.
Perhaps you meant the package directory './'?

This happens because this code relies on the canonical property to match up packages that are known to live at various locations with a directory given by the user. Since one code path happens to call canonicalizePath with a trailing slash and another without then there is no match and the confusing error.

Metadata

Metadata

Assignees

Labels

type: a-bugThe described behavior is not working as intended.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions