Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#853 closed request (wontfix)

compare if two file paths refers to the same file

Reported by: Peter Owned by: Jari Häkkinen
Priority: major Milestone:
Component: utility Version:
Keywords: Cc:


I have two paths and wanna compare if the refer to the same file. A simple string comparison doesn't do it for two reasons:

  1. The paths may contain dir/../A which is equivalent to A.
  2. The paths may refer to symbolic links which I wanna follow here.

[posix sysstat], which we use in utility::FileUtil, says that

File serial number and device ID taken together uniquely identify the file within the system

so we could use them to answer the question, and in case the paths don't exist just return false, which clearly is the intuitive if one path exists, but less clear when both paths are non-existing. However, as long as the behaviour is documented, it shouldn't be too confusing.

I suggest a free function taking two FileUtil objects and probably make it friend of FileUtil so it can look into the private parts. Well actually, FileUtil does not have much of privacy; it only stores std::string path_ (why not a stat struct?).

Change History (2)

comment:1 Changed 6 years ago by Peter

Resolution: wontfix
Status: newclosed

This is exactly what boost::filesystem::equivalent does

comment:2 Changed 6 years ago by Peter

Milestone: yat 0.x+
Note: See TracTickets for help on using tickets.