Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why path comparison is case-sensitive in latest filesystem draft (C++)?

A quote from Programming Languages — C++ — File System Technical Specification draft N4100:

8.4.8 pathcompare [path.compare]

1 int compare(const path& p) const noexcept;

2 Returns: A value less than 0 if native() for the elements of *this are lexicographically less than native() for the elements of p, otherwise a value greater than 0 if native()for the elements of *this are lexicographically greater than native() for the elements of p, otherwise 0.

Why the file path comparison is defined as case-sensitive if there are file systems that are case-insensitive (NTFS, etc)? Shouldn't comparison be done according to specific file system rules?

like image 769
PowerGamer Avatar asked Jan 18 '15 20:01

PowerGamer


1 Answers

You have additionally equivalent() function specified in 15.13, which checks if two paths resolve to the same file.

bool equivalent(const path& p1, const path& p2)
  1. Returns: true, if s1 == s2 and p1 and p2 resolve to the same file system entity, else false. The signature with argument ec returns false if an error occurs.

compare() function will use iterators and path::operator== to compare elements. In 8.6.13 you have written:

bool operator==(const path& lhs, const path& rhs) noexcept;
  1. Equivalence is determined by the equivalent() non-member function, which determines if two paths resolve to the same file system entity. Thus equivalent("foo", "bar") will be true when both paths resolve to the same file

  2. Programmers wishing to determine if two paths are "the same" must decide if "the same" means "the same representation" or "resolve to the same actual file", and choose the appropriate function accordingly

So, equivalent() comparison is done according to system specific rules, while compare() checks if you have used "the same representation" to describe path.

like image 167
mip Avatar answered Sep 22 '22 15:09

mip