aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormontellese <montellese@xbmc.org>2012-05-12 19:53:54 +0200
committermontellese <montellese@xbmc.org>2012-05-12 19:54:14 +0200
commitfccca034d189dd640fd15cd494fef522e1bd21e7 (patch)
treeeba69bd9ee8ca99fc90955a8c31d7310aa3d367e
parent805ab7a3a2b6d48653535e2fc6148d564c5b7c65 (diff)
dateadded: make sure we don't add a datetime located in the future (fixes #12998)
-rw-r--r--xbmc/video/VideoDatabase.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp
index 90c7a04691..e6a39e11c8 100644
--- a/xbmc/video/VideoDatabase.cpp
+++ b/xbmc/video/VideoDatabase.cpp
@@ -701,10 +701,19 @@ void CVideoDatabase::UpdateFileDateAdded(int idFile, const CStdString& strFileNa
struct __stat64 buffer;
if (CFile::Stat(file, &buffer) == 0)
{
- time_t maxTime = max((time_t)buffer.st_ctime, (time_t)buffer.st_mtime);
- struct tm *time = localtime(&maxTime);
- if (time)
- dateAdded = *time;
+ time_t now = time(NULL);
+ time_t 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)
+ 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)
+ {
+ struct tm *time = localtime(&addedTime);
+ if (time)
+ dateAdded = *time;
+ }
}
if (!dateAdded.IsValid())
@@ -1099,9 +1108,14 @@ int CVideoDatabase::AddTvShow(const CStdString& strPath)
struct __stat64 buffer;
if (XFILE::CFile::Stat(strPath, &buffer) == 0)
{
- struct tm *time = localtime((const time_t*)&buffer.st_ctime);
- if (time)
- dateAdded = *time;
+ 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)
+ dateAdded = *time;
+ }
}
if (!dateAdded.IsValid())