C++17: Normalization Options for Filesystem Paths

Invariants we (probably) agree on:

  1. An empty path remains empty, a non-empty path remains non-empty.
  2. An absolute path remains absolute, a relative path remains relative.
  3. We never remove a trailing separator (this is important because some operating systems use this to reaize that something is a directory)
  4. No redundant dot, dot-dot, or directory-separators.
  5. directory-separators are in the preferred-separator form.

Invariants we have to discuss:

    Option 0 Option 1 Option 2 Option 3 Option 4 Option 5  
    Beman in d0492.html email option a) a simplification email Option b) email Option c) by Jens  
  • We never end with "." (unless this is the whole path)
  • We add a trailing separator if we concatente at the end
    unless the result is just "."
  • We never end with "." (unless this is the whole path)
  • We add a trailing separator if we concatente at the end
  • We never end with "." (unless this is the whole path)
  • The result has a trailing separator IF AND ONLY IF
    the input had one
  • We never end with "."
  • We ALWAYS add a separator when we
    know that it is a directory
    (even after . and ..)
  • Critical, because trailing / means to follow a sym link (should not be added when surce didn't end with one for the directory)
  • We never end with "." (unless this is the whole path)
  • We add a trailing separator if we concatente at the end
  • "./" is always normalized to "."
1) . . . . . ./ .
2) ./ ./ ./ ./ ./ ./ .
3) /./ /./ / / / / /
4) foo/ foo/ foo/ foo/ foo/ foo/ foo/
5) foo/. foo foo/ foo/ foo foo/ foo/
6) foo/.. . . ./ . ./ .
7) foo/../ ./ ./ ./ ./ ./ .
8) foo/../. . . ./ . ./ .
9) /foo/.. / / / / / /
10) /foo/../. / / / / / /
11) /foo/bar/. /foo/bar /foo/bar/ /foo/bar/ /foo/bar /foo/bar/ /foo/bar/
12) /foo/bar/./ /foo/bar/ /foo/bar/ /foo/bar/ /foo/bar/ /foo/bar/ /foo/bar/
13) /foo/bar/.. /foo /foo/ /foo/ /foo /foo/ /foo/  
14) /foo/bar/../ /foo/ /foo/ /foo/ /foo/ /foo/ /foo/
14) /foo/../bar /bar /bar /bar /bar /bar/ /bar