Skip to content
Snippets Groups Projects
Commit 77d25204 authored by Oz Linden's avatar Oz Linden
Browse files

clarity and logging cleanup

parent ab30a44d
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,8 @@ class LLLiveFile::Impl ...@@ -51,6 +51,8 @@ class LLLiveFile::Impl
bool mLastExists; bool mLastExists;
LLEventTimer* mEventTimer; LLEventTimer* mEventTimer;
private:
LOG_CLASS(LLLiveFile);
}; };
LLLiveFile::Impl::Impl(const std::string& filename, const F32 refresh_period) LLLiveFile::Impl::Impl(const std::string& filename, const F32 refresh_period)
...@@ -83,46 +85,51 @@ LLLiveFile::~LLLiveFile() ...@@ -83,46 +85,51 @@ LLLiveFile::~LLLiveFile()
bool LLLiveFile::Impl::check() bool LLLiveFile::Impl::check()
{ {
if (!mForceCheck && mRefreshTimer.getElapsedTimeF32() < mRefreshPeriod) bool detected_change = false;
// Skip the check if not enough time has elapsed and we're not
// forcing a check of the file
if (mForceCheck || mRefreshTimer.getElapsedTimeF32() >= mRefreshPeriod)
{ {
// Skip the check if not enough time has elapsed and we're not mForceCheck = false; // force only forces one check
// forcing a check of the file mRefreshTimer.reset(); // don't check again until mRefreshPeriod has passed
return false;
} // Stat the file to see if it exists and when it was last modified.
mForceCheck = false; llstat stat_data;
mRefreshTimer.reset(); if (LLFile::stat(mFilename, &stat_data))
{
// Stat the file to see if it exists and when it was last modified. // Couldn't stat the file, that means it doesn't exist or is
llstat stat_data; // broken somehow.
int res = LLFile::stat(mFilename, &stat_data); if (mLastExists)
{
if (res) mLastExists = false;
{ detected_change = true; // no longer existing is a change!
// Couldn't stat the file, that means it doesn't exist or is LL_DEBUGS() << "detected deleted file '" << mFilename << "'" << LL_ENDL;
// broken somehow. Clear flags and return. }
if (mLastExists) }
{ else
mLastExists = false; {
return true; // no longer existing is a change! // The file exists
} if ( ! mLastExists )
return false; {
} // last check, it did not exist - that counts as a change
LL_DEBUGS() << "detected created file '" << mFilename << "'" << LL_ENDL;
// The file exists, decide if we want to load it. detected_change = true;
if (mLastExists) }
{ else if ( stat_data.st_mtime > mLastModTime )
// The file existed last time, don't read it if it hasn't changed since {
// last time. // file modification time is newer than last check
if (stat_data.st_mtime <= mLastModTime) LL_DEBUGS() << "detected updated file '" << mFilename << "'" << LL_ENDL;
{ detected_change = true;
return false; }
} mLastExists = true;
} mLastStatTime = stat_data.st_mtime;
}
// We want to read the file. Update status info for the file. }
mLastExists = true; if (detected_change)
mLastStatTime = stat_data.st_mtime; {
return true; LL_INFOS() << "detected file change '" << mFilename << "'" << LL_ENDL;
}
return detected_change;
} }
void LLLiveFile::Impl::changed() void LLLiveFile::Impl::changed()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment