Skip to content

Commit 91decc2

Browse files
committed
FileSystemPath : Work around Windows exFAT bug
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.
1 parent 07c01c5 commit 91decc2

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Gaffer/FileSystemPath.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,28 @@ bool FileSystemPath::isValid( const IECore::Canceller *canceller ) const
258258

259259
std::error_code e;
260260

261-
const std::filesystem::file_type t = std::filesystem::symlink_status( std::filesystem::path( this->string() ), e ).type();
261+
std::filesystem::file_type t = std::filesystem::symlink_status( std::filesystem::path( this->string() ), e ).type();
262+
263+
#if _MSC_VER < 1932
264+
265+
// Fix MSVC bug preventing `symlink_status()` working with exFAT partitions, and possibly FAT.
266+
// Filtering to error 87 is based on experimentation and backed up by
267+
// https://github.com/microsoft/STL/issues/233. Using `status()` instead of `symlink_status()`
268+
// allows exFAT partitions to be used, and because exFAT does not support symlinks, this
269+
// should be a valid workaround provided filtering to error value `87` doesn't include
270+
// partitions that do support symlinks.
271+
if(
272+
(
273+
t == std::filesystem::file_type::none || t == std::filesystem::file_type::not_found
274+
) && e.value() == 87 // "The parameter is incorrect."
275+
)
276+
{
277+
std::cerr << e.value() << " ( " << e.category().name() << " ) : " << e.message() << "\n";
278+
t = std::filesystem::status( std::filesystem::path( this->string() ), e ).type();
279+
}
280+
281+
#endif
282+
262283
return t != std::filesystem::file_type::none && t != std::filesystem::file_type::not_found;
263284
}
264285

0 commit comments

Comments
 (0)