MacOSX: set FUSE-T workaround max delay to 5 seconds. Make logic specific to FUSE-T volumes.

This commit is contained in:
Mounir IDRASSI 2024-06-23 16:57:18 +02:00
parent a23da988d2
commit 01361e300f
No known key found for this signature in database
GPG Key ID: C2FF2438CD26E3B7

View File

@ -304,8 +304,13 @@ namespace VeraCrypt
shared_ptr <VolumeInfo> mountedVol; shared_ptr <VolumeInfo> mountedVol;
// Introduce a retry mechanism with a timeout for control file access // Introduce a retry mechanism with a timeout for control file access
int controlFileRetries = 5; // This workaround is limited to FUSE-T mounted volume under macOS for
while (controlFileRetries-- > 0) // which md.Device starts with "fuse-t:"
#ifdef VC_MACOSX_FUSET
bool isFuseT = wstring(mf.Device).find(L"fuse-t:") == 0;
int controlFileRetries = 10; // 10 retries with 500ms sleep each, total 5 seconds
while (!mountedVol && (controlFileRetries-- > 0))
#endif
{ {
try try
{ {
@ -314,22 +319,23 @@ namespace VeraCrypt
shared_ptr <Stream> controlFileStream (new FileStream (controlFile)); shared_ptr <Stream> controlFileStream (new FileStream (controlFile));
mountedVol = Serializable::DeserializeNew <VolumeInfo> (controlFileStream); mountedVol = Serializable::DeserializeNew <VolumeInfo> (controlFileStream);
break; // Control file opened successfully
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
#ifdef VC_MACOSX_FUSET
// if exception starts with "VeraCrypt::Serializer::ValidateName", then // if exception starts with "VeraCrypt::Serializer::ValidateName", then
// serialization is not ready yet and we need to wait before retrying // serialization is not ready yet and we need to wait before retrying
// this happens when FUSE-T is used under macOS and if it is the first time // this happens when FUSE-T is used under macOS and if it is the first time
// the volume is mounted // the volume is mounted
if (string (e.what()).find ("VeraCrypt::Serializer::ValidateName") != string::npos) if (isFuseT && string (e.what()).find ("VeraCrypt::Serializer::ValidateName") != string::npos)
{ {
Thread::Sleep(250); // Wait before retrying Thread::Sleep(500); // Wait before retrying
} }
else else
{ {
break; // Control file not found break; // Control file not found or other error
} }
#endif
} }
} }