Advertisement
Guest User

Untitled

a guest
Jun 16th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.84 KB | None | 0 0
  1. From a2f5d32b1fd8e35a61762cc3db04eabd48b91491 Mon Sep 17 00:00:00 2001
  2. From: montellese <montellese@xbmc.org>
  3. Date: Sat, 16 Jun 2012 12:38:17 +0200
  4. Subject: [PATCH] dateadded: add log output in case of invalid datetime values
  5.  
  6. ---
  7. xbmc/video/VideoDatabase.cpp |   56 +++++++++++++++++++++++++++++++++++------
  8.  1 files changed, 47 insertions(+), 9 deletions(-)
  9.  
  10. diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp
  11. index 26818ec..6ada8ad 100644
  12. --- a/xbmc/video/VideoDatabase.cpp
  13. +++ b/xbmc/video/VideoDatabase.cpp
  14. @@ -712,7 +712,18 @@ void CVideoDatabase::UpdateFileDateAdded(int idFile, const CStdString& strFileNa
  15.            if ((time_t)buffer.st_mtime <= now)
  16.              addedTime = (time_t)buffer.st_mtime;
  17.            else
  18. +          {
  19. +            struct tm *time = localtime((time_t*)&buffer.st_mtime);
  20. +            if (time)
  21. +            {
  22. +              CDateTime mtime = *time;
  23. +              CLog::Log(LOGWARNING, "invalid mtime %s for file %s; falling back to ctime", mtime.GetAsDBDateTime().c_str(), strFileNameAndPath.c_str());
  24. +            }
  25. +            else
  26. +              CLog::Log(LOGWARNING, "invalid mtime %d for file %s; falling back to ctime", (int)buffer.st_mtime, strFileNameAndPath.c_str());
  27. +
  28.              addedTime = (time_t)buffer.st_ctime;
  29. +          }
  30.          }
  31.          // Use the newer of the creation and modification time
  32.          else
  33. @@ -720,21 +731,40 @@ void CVideoDatabase::UpdateFileDateAdded(int idFile, const CStdString& strFileNa
  34.            addedTime = max((time_t)buffer.st_ctime, (time_t)buffer.st_mtime);
  35.            // if the newer of the two dates is in the future, we try it with the older one
  36.            if (addedTime > now)
  37. +          {
  38. +            struct tm *time = localtime(&addedTime);
  39. +            if (time)
  40. +            {
  41. +              CDateTime dateAddedTime = *time;
  42. +              CLog::Log(LOGWARNING, "invalid max(mtime, ctime) %s for file %s; falling back to min(mtime, ctime)", dateAddedTime.GetAsDBDateTime().c_str(), strFileNameAndPath.c_str());
  43. +            }
  44. +            else
  45. +              CLog::Log(LOGWARNING, "invalid max(mtime, ctime) %d for file %s; falling back to min(mtime, ctime)", (int)addedTime, strFileNameAndPath.c_str());
  46. +
  47.              addedTime = min((time_t)buffer.st_ctime, (time_t)buffer.st_mtime);
  48. +          }
  49.          }
  50.  
  51. -        // make sure the datetime does is not in the future
  52. -        if (addedTime <= now)
  53. +        // make sure the retrieved datetime is not in the future
  54. +        struct tm *time = localtime(&addedTime);
  55. +        if (time == NULL)
  56. +          CLog::Log(LOGWARNING, "invalid dateadded value %d for file %s", (int)addedTime);
  57. +        else if (addedTime <= now)
  58. +          dateAdded = *time;
  59. +        else
  60.          {
  61. -          struct tm *time = localtime(&addedTime);
  62. -          if (time)
  63. -            dateAdded = *time;
  64. +          CDateTime dateAddedTime = *time;
  65. +          CLog::Log(LOGWARNING, "invalid dateadded value %s for file %s", dateAddedTime.GetAsDBDateTime().c_str(), strFileNameAndPath.c_str());
  66.          }
  67.        }
  68.      }
  69.  
  70.      if (!dateAdded.IsValid())
  71. +    {
  72. +      if (g_advancedSettings.m_iVideoLibraryDateAdded > 0)
  73. +        CLog::Log(LOGWARNING, "invalid dateadded value for file %s; falling back to current datetime", strFileNameAndPath.c_str());
  74.        dateAdded = CDateTime::GetCurrentDateTime();
  75. +    }
  76.  
  77.      strSQL = PrepareSQL("update files set dateAdded='%s' where idFile=%d", dateAdded.GetAsDBDateTime().c_str(), idFile);
  78.      m_pDS->exec(strSQL.c_str());
  79. @@ -1130,17 +1160,25 @@ int CVideoDatabase::AddTvShow(const CStdString& strPath)
  80.        {
  81.          time_t now = time(NULL);
  82.          // Make sure we have a valid date (i.e. not in the future)
  83. -        if ((time_t)buffer.st_ctime <= now)
  84. +        struct tm *time = localtime((const time_t*)&buffer.st_ctime);
  85. +        if (time == NULL)
  86. +          CLog::Log(LOGWARNING, "invalid ctime %d for path %s", (int)buffer.st_ctime, strPath.c_str());
  87. +        else if ((time_t)buffer.st_ctime <= now)
  88. +          dateAdded = *time;
  89. +        else
  90.          {
  91. -          struct tm *time = localtime((const time_t*)&buffer.st_ctime);
  92. -          if (time)
  93. -            dateAdded = *time;
  94. +          CDateTime dateAddedTime = *time;
  95. +          CLog::Log(LOGWARNING, "invalid ctime %s for path %s", dateAddedTime.GetAsDBDateTime().c_str(), strPath.c_str());
  96.          }
  97.        }
  98.      }
  99.  
  100.      if (!dateAdded.IsValid())
  101. +    {
  102. +      if (g_advancedSettings.m_iVideoLibraryDateAdded > 0)
  103. +        CLog::Log(LOGWARNING, "invalid dateadded value for path %s; falling back to current datetime", strPath.c_str());
  104.        dateAdded = CDateTime::GetCurrentDateTime();
  105. +    }
  106.  
  107.      int idPath = AddPath(strPath, dateAdded.GetAsDBDateTime());
  108.      strSQL=PrepareSQL("insert into tvshowlinkpath values (%i,%i)",idTvShow,idPath);
  109. --
  110. 1.7.7.msysgit.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement