Date: Thu, 29 Aug 2024 18:41:37 -0700
On Thursday 29 August 2024 16:10:35 GMT-7 Jeremy Rifkin via Std-Proposals
wrote:
> if by std::filesystem::equivalent, otherwise implementation defined. But
> "filesystem" would need to be defined.
libstdc++:
fs::equiv_files([[maybe_unused]] const char_type* p1, const stat_type& st1,
[[maybe_unused]] const char_type* p2, const stat_type& st2,
[[maybe_unused]] error_code& ec)
{
// For POSIX the device ID and inode number uniquely identify a file.
// This doesn't work on Windows (see equiv_files in src/c++17/fs_ops.cc).
return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino;
}
libc++'s implementation is the same:
inline bool stat_equivalent(const StatT& st1, const StatT& st2) {
return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
}
At least Microsoft's works on Windows. Like Qt, it uses
GetFileInformationByHandleEx. Though Qt's source code has a comment that that
was known to fail on FAT32...
And as Jonathan replied, "uniquely identifies" is an oversimplification, even
for POSIX systems. If we standardise on the standard library's behaviour, then
MSVC's behaviour on Windows will differ from Clang's and GCC's.
Side note:
Qt uses this to determine whether, when renaming a file, you're trying to
overwrite something or change the case of the file's name. So we have a
workaround for that for systems that don't usually expect case-insensitive
filesystems.
wrote:
> if by std::filesystem::equivalent, otherwise implementation defined. But
> "filesystem" would need to be defined.
libstdc++:
fs::equiv_files([[maybe_unused]] const char_type* p1, const stat_type& st1,
[[maybe_unused]] const char_type* p2, const stat_type& st2,
[[maybe_unused]] error_code& ec)
{
// For POSIX the device ID and inode number uniquely identify a file.
// This doesn't work on Windows (see equiv_files in src/c++17/fs_ops.cc).
return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino;
}
libc++'s implementation is the same:
inline bool stat_equivalent(const StatT& st1, const StatT& st2) {
return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
}
At least Microsoft's works on Windows. Like Qt, it uses
GetFileInformationByHandleEx. Though Qt's source code has a comment that that
was known to fail on FAT32...
And as Jonathan replied, "uniquely identifies" is an oversimplification, even
for POSIX systems. If we standardise on the standard library's behaviour, then
MSVC's behaviour on Windows will differ from Clang's and GCC's.
Side note:
Qt uses this to determine whether, when renaming a file, you're trying to
overwrite something or change the case of the file's name. So we have a
workaround for that for systems that don't usually expect case-insensitive
filesystems.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel DCAI Platform & System Engineering
Received on 2024-08-30 01:41:40