Skip to content

Commit

Permalink
FileSystemPath : Work around Windows exFAT bug
Browse files Browse the repository at this point in the history
MSVC's `std::filesystem` has a bug that causes it to fail to retrieve
file information on exFAT partitions in versions prior to (roughly)
17.2. That version is the first release after merging a fix from
microsoft/STL#2373, but I'm not certain that
version has the fix included.

Using `std::filesystem::status` instead of `symlink_status()` seems
justified because exFAT paritions don't support symlinks. If other
partition types are included in the filter for error code 87, this
may need to be revisited.
  • Loading branch information
ericmehl committed Oct 9, 2023
1 parent 07c01c5 commit 91decc2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Gaffer/FileSystemPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,28 @@ bool FileSystemPath::isValid( const IECore::Canceller *canceller ) const

std::error_code e;

const std::filesystem::file_type t = std::filesystem::symlink_status( std::filesystem::path( this->string() ), e ).type();
std::filesystem::file_type t = std::filesystem::symlink_status( std::filesystem::path( this->string() ), e ).type();

#if _MSC_VER < 1932

// Fix MSVC bug preventing `symlink_status()` working with exFAT partitions, and possibly FAT.
// Filtering to error 87 is based on experimentation and backed up by
// https://github.com/microsoft/STL/issues/233. Using `status()` instead of `symlink_status()`
// allows exFAT partitions to be used, and because exFAT does not support symlinks, this
// should be a valid workaround provided filtering to error value `87` doesn't include
// partitions that do support symlinks.
if(
(
t == std::filesystem::file_type::none || t == std::filesystem::file_type::not_found
) && e.value() == 87 // "The parameter is incorrect."
)
{
std::cerr << e.value() << " ( " << e.category().name() << " ) : " << e.message() << "\n";
t = std::filesystem::status( std::filesystem::path( this->string() ), e ).type();
}

#endif

return t != std::filesystem::file_type::none && t != std::filesystem::file_type::not_found;
}

Expand Down

0 comments on commit 91decc2

Please sign in to comment.