Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From a2f5d32b1fd8e35a61762cc3db04eabd48b91491 Mon Sep 17 00:00:00 2001
- From: montellese <montellese@xbmc.org>
- Date: Sat, 16 Jun 2012 12:38:17 +0200
- Subject: [PATCH] dateadded: add log output in case of invalid datetime values
- ---
- xbmc/video/VideoDatabase.cpp | 56 +++++++++++++++++++++++++++++++++++------
- 1 files changed, 47 insertions(+), 9 deletions(-)
- diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp
- index 26818ec..6ada8ad 100644
- --- a/xbmc/video/VideoDatabase.cpp
- +++ b/xbmc/video/VideoDatabase.cpp
- @@ -712,7 +712,18 @@ void CVideoDatabase::UpdateFileDateAdded(int idFile, const CStdString& strFileNa
- if ((time_t)buffer.st_mtime <= now)
- addedTime = (time_t)buffer.st_mtime;
- else
- + {
- + struct tm *time = localtime((time_t*)&buffer.st_mtime);
- + if (time)
- + {
- + CDateTime mtime = *time;
- + CLog::Log(LOGWARNING, "invalid mtime %s for file %s; falling back to ctime", mtime.GetAsDBDateTime().c_str(), strFileNameAndPath.c_str());
- + }
- + else
- + CLog::Log(LOGWARNING, "invalid mtime %d for file %s; falling back to ctime", (int)buffer.st_mtime, strFileNameAndPath.c_str());
- +
- addedTime = (time_t)buffer.st_ctime;
- + }
- }
- // Use the newer of the creation and modification time
- else
- @@ -720,21 +731,40 @@ void CVideoDatabase::UpdateFileDateAdded(int idFile, const CStdString& strFileNa
- addedTime = max((time_t)buffer.st_ctime, (time_t)buffer.st_mtime);
- // if the newer of the two dates is in the future, we try it with the older one
- if (addedTime > now)
- + {
- + struct tm *time = localtime(&addedTime);
- + if (time)
- + {
- + CDateTime dateAddedTime = *time;
- + CLog::Log(LOGWARNING, "invalid max(mtime, ctime) %s for file %s; falling back to min(mtime, ctime)", dateAddedTime.GetAsDBDateTime().c_str(), strFileNameAndPath.c_str());
- + }
- + else
- + CLog::Log(LOGWARNING, "invalid max(mtime, ctime) %d for file %s; falling back to min(mtime, ctime)", (int)addedTime, strFileNameAndPath.c_str());
- +
- addedTime = min((time_t)buffer.st_ctime, (time_t)buffer.st_mtime);
- + }
- }
- - // make sure the datetime does is not in the future
- - if (addedTime <= now)
- + // make sure the retrieved datetime is not in the future
- + struct tm *time = localtime(&addedTime);
- + if (time == NULL)
- + CLog::Log(LOGWARNING, "invalid dateadded value %d for file %s", (int)addedTime);
- + else if (addedTime <= now)
- + dateAdded = *time;
- + else
- {
- - struct tm *time = localtime(&addedTime);
- - if (time)
- - dateAdded = *time;
- + CDateTime dateAddedTime = *time;
- + CLog::Log(LOGWARNING, "invalid dateadded value %s for file %s", dateAddedTime.GetAsDBDateTime().c_str(), strFileNameAndPath.c_str());
- }
- }
- }
- if (!dateAdded.IsValid())
- + {
- + if (g_advancedSettings.m_iVideoLibraryDateAdded > 0)
- + CLog::Log(LOGWARNING, "invalid dateadded value for file %s; falling back to current datetime", strFileNameAndPath.c_str());
- dateAdded = CDateTime::GetCurrentDateTime();
- + }
- strSQL = PrepareSQL("update files set dateAdded='%s' where idFile=%d", dateAdded.GetAsDBDateTime().c_str(), idFile);
- m_pDS->exec(strSQL.c_str());
- @@ -1130,17 +1160,25 @@ int CVideoDatabase::AddTvShow(const CStdString& strPath)
- {
- time_t now = time(NULL);
- // Make sure we have a valid date (i.e. not in the future)
- - if ((time_t)buffer.st_ctime <= now)
- + struct tm *time = localtime((const time_t*)&buffer.st_ctime);
- + if (time == NULL)
- + CLog::Log(LOGWARNING, "invalid ctime %d for path %s", (int)buffer.st_ctime, strPath.c_str());
- + else if ((time_t)buffer.st_ctime <= now)
- + dateAdded = *time;
- + else
- {
- - struct tm *time = localtime((const time_t*)&buffer.st_ctime);
- - if (time)
- - dateAdded = *time;
- + CDateTime dateAddedTime = *time;
- + CLog::Log(LOGWARNING, "invalid ctime %s for path %s", dateAddedTime.GetAsDBDateTime().c_str(), strPath.c_str());
- }
- }
- }
- if (!dateAdded.IsValid())
- + {
- + if (g_advancedSettings.m_iVideoLibraryDateAdded > 0)
- + CLog::Log(LOGWARNING, "invalid dateadded value for path %s; falling back to current datetime", strPath.c_str());
- dateAdded = CDateTime::GetCurrentDateTime();
- + }
- int idPath = AddPath(strPath, dateAdded.GetAsDBDateTime());
- strSQL=PrepareSQL("insert into tvshowlinkpath values (%i,%i)",idTvShow,idPath);
- --
- 1.7.7.msysgit.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement