MCPcopy Create free account
hub / github.com/beefytech/Beef / GetFileInfo

Function GetFileInfo

BeefySysLib/platform/win/Platform.cpp:435–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

433//////////////////////////////////////////////////
434
435static bool GetFileInfo(const char* path, BfpTimeStamp* lastWriteTime, uint32* fileAttributes)
436{
437 if (lastWriteTime != NULL)
438 *lastWriteTime = 0;
439 if (fileAttributes != NULL)
440 *fileAttributes = 0;
441
442 // Fast Path
443 WIN32_FILE_ATTRIBUTE_DATA data = { 0 };
444 if (::GetFileAttributesExW(UTF8Decode(path).c_str(), GetFileExInfoStandard, &data))
445 {
446 if (lastWriteTime != NULL)
447 *lastWriteTime = *(BfpTimeStamp*)&data.ftLastWriteTime;
448 if (fileAttributes != NULL)
449 *fileAttributes = data.dwFileAttributes;
450
451 return true;
452 }
453
454 int error = ::GetLastError();
455 if ((error == ERROR_FILE_NOT_FOUND) ||
456 (error == ERROR_PATH_NOT_FOUND) ||
457 (error == ERROR_NOT_READY))
458 {
459 return false;
460 }
461
462 // Slow Path- This case is in case someone latched onto the file. In this case, GetFileAttributes will fail but
463 // FindFirstFile will not (though it is slower)
464 WIN32_FIND_DATAW findData = { 0 };
465 HANDLE findHandleFrom = ::FindFirstFileW(UTF8Decode(path).c_str(), &findData);
466
467 if (!IsHandleValid(findHandleFrom))
468 return false;
469
470 if (lastWriteTime != NULL)
471 *lastWriteTime = *(BfpTimeStamp*)&findData.ftLastWriteTime;
472 if (fileAttributes != NULL)
473 *fileAttributes = findData.dwFileAttributes;
474
475 ::FindClose(findHandleFrom);
476 return true;
477}
478
479static BfpFileAttributes FileAttributes_WinToBFP(uint32 fileAttributes)
480{

Callers 3

BfpFile_GetAttributesFunction · 0.85
BfpFile_CopyFunction · 0.85

Calls 2

IsHandleValidFunction · 0.70
c_strMethod · 0.45

Tested by

no test coverage detected