aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Kaijser <martijn@xbmc.org>2017-05-20 11:06:48 +0200
committerGitHub <noreply@github.com>2017-05-20 11:06:48 +0200
commit46b6f189efa6b864a360660b670928c3dbef8b0d (patch)
treeb781b6faa0610dd835001a08bbb27a7143f548ff
parent26e5e1fea05d18cbc972b12813889c99367dfc03 (diff)
parentad572c325769ce3182cdc4cf9aafbaf14235cd79 (diff)
Merge pull request #12127 from MilhouseVH/a27_fix_krypton
detect and delete zero-byte database files
-rw-r--r--xbmc/dbwrappers/sqlitedataset.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/xbmc/dbwrappers/sqlitedataset.cpp b/xbmc/dbwrappers/sqlitedataset.cpp
index 7091e9766a..d3764a776f 100644
--- a/xbmc/dbwrappers/sqlitedataset.cpp
+++ b/xbmc/dbwrappers/sqlitedataset.cpp
@@ -33,6 +33,7 @@
#include "utils/log.h"
#include "system.h" // for Sleep(), OutputDebugString() and GetLastError()
#include "utils/URIUtils.h"
+#include "filesystem/File.h"
#ifdef TARGET_WINDOWS
#pragma comment(lib, "sqlite3.lib")
@@ -42,6 +43,8 @@
#include "linux/XTimeUtils.h"
#endif
+using namespace XFILE;
+
namespace dbiplus {
//************* Callback function ***************************
@@ -221,6 +224,21 @@ int SqliteDatabase::connect(bool create) {
int flags = SQLITE_OPEN_READWRITE;
if (create)
flags |= SQLITE_OPEN_CREATE;
+
+ if (CFile::Exists(db_fullpath.c_str()))
+ {
+ CFile file;
+ if (file.Open(db_fullpath.c_str()))
+ {
+ if (file.GetLength() == 0)
+ {
+ CLog::Log(LOGWARNING, "Found zero byte SQLite database, deleting %s", db_fullpath.c_str());
+ CFile::Delete(db_fullpath.c_str());
+ }
+ file.Close();
+ }
+ }
+
if (sqlite3_open_v2(db_fullpath.c_str(), &conn, flags, NULL)==SQLITE_OK)
{
sqlite3_busy_handler(conn, busy_callback, NULL);