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 10, 2023
1 parent 07c01c5 commit dd06cf5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Improvements
- Popups for string cells and row names are now sized to fit their column.
- Added "Triple" and "Quadruple" width options to the spreadsheet row name popup menu.

Fixes
-----

- FileSystemPath : Fixed bug on Windows where paths on an exFAT partition were not considered valid.

1.3.4.0 (relative to 1.3.3.0)
=======

Expand Down
22 changes: 21 additions & 1 deletion src/Gaffer/FileSystemPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,27 @@ 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 defined(_MSC_VER) && _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."
)
{
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 dd06cf5

Please sign in to comment.