Fix is_regular_file again (#1218)

This commit is contained in:
Pavel Krymets 2018-08-13 10:32:39 -07:00 committed by GitHub
parent b857a83dd8
commit f1c1f82e8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 14 deletions

View File

@ -57,5 +57,5 @@ HRESULT AppOfflineApplication::OnAppOfflineFound()
bool AppOfflineApplication::ShouldBeStarted(IHttpApplication& pApplication)
{
return is_regular_file(GetAppOfflineLocation(pApplication));
return FileExists(GetAppOfflineLocation(pApplication));
}

View File

@ -28,20 +28,12 @@ PollingAppOfflineApplication::CheckAppOffline()
SRWExclusiveLock lock(m_statusLock);
if (ulCurrentTime - m_ulLastCheckTime > c_appOfflineRefreshIntervalMS)
{
try
m_fAppOfflineFound = FileExists(m_appOfflineLocation);
if(m_fAppOfflineFound)
{
m_fAppOfflineFound = is_regular_file(m_appOfflineLocation);
if(m_fAppOfflineFound)
{
LOG_IF_FAILED(OnAppOfflineFound());
}
m_ulLastCheckTime = ulCurrentTime;
}
catch (...)
{
// is_regular_file might throw in very rare cases
OBSERVE_CAUGHT_EXCEPTION();
LOG_IF_FAILED(OnAppOfflineFound());
}
m_ulLastCheckTime = ulCurrentTime;
}
}
@ -56,3 +48,9 @@ std::filesystem::path PollingAppOfflineApplication::GetAppOfflineLocation(IHttpA
{
return std::filesystem::path(pApplication.GetApplicationPhysicalPath()) / "app_offline.htm";
}
bool PollingAppOfflineApplication::FileExists(const std::filesystem::path& path)
{
std::error_code ec;
return is_regular_file(path, ec) || ec.value() == ERROR_SHARING_VIOLATION;
}

View File

@ -32,7 +32,7 @@ public:
protected:
std::filesystem::path m_appOfflineLocation;
static std::filesystem::path GetAppOfflineLocation(IHttpApplication& pApplication);
static bool FileExists(const std::filesystem::path& path);
private:
static const int c_appOfflineRefreshIntervalMS = 200;
std::string m_strAppOfflineContent;