diff options
author | montellese <montellese@xbmc.org> | 2014-01-05 14:57:23 +0100 |
---|---|---|
committer | montellese <montellese@xbmc.org> | 2014-01-05 14:57:23 +0100 |
commit | 5da031f4d89c5ff09365c1d2b3d85608ef951eaa (patch) | |
tree | 2b92a6dffda9453f68ba13e553489930fc8d7eca | |
parent | 2c1e2f6c27da2aac32c90282071f786175c87b9b (diff) |
videodb: fix database cleaning for file-level sources
-rw-r--r-- | xbmc/video/VideoDatabase.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 8fbd9ec8e4..daf3544e59 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -8420,7 +8420,7 @@ std::vector<int> CVideoDatabase::CleanMediaType(const std::string &mediaType, co return cleanedIDs; // now grab them media items - std::string sql = PrepareSQL("SELECT %s.%s, %s.idFile, %s, path.idPath, parentPath.strPath FROM %s " + std::string sql = PrepareSQL("SELECT %s.%s, %s.idFile, %s, path.idPath, parentPath.strPath, parentPath.useFolderNames FROM %s " "JOIN files ON files.idFile = %s.idFile " "JOIN path ON path.idPath = files.idPath ", table.c_str(), idField.c_str(), table.c_str(), parentPathIdField.c_str(), table.c_str(), @@ -8434,16 +8434,21 @@ std::vector<int> CVideoDatabase::CleanMediaType(const std::string &mediaType, co parentPathIdField.c_str(), table.c_str(), cleanableFileIDs.c_str()); + // map of parent path ID to boolean pair (if not exists and user choice) + std::map<int, std::pair<bool, bool> > parentPathsDeleteDecisions; m_pDS->query(sql.c_str()); while (!m_pDS->eof()) { int parentPathID = m_pDS->fv(2).get_asInt(); - std::map<int, bool>::const_iterator pathsDeleteDecision = pathsDeleteDecisions.find(parentPathID); + std::map<int, std::pair<bool, bool> >::const_iterator parentPathsDeleteDecision = parentPathsDeleteDecisions.find(parentPathID); bool del = true; - if (pathsDeleteDecision == pathsDeleteDecisions.end()) + if (parentPathsDeleteDecision == parentPathsDeleteDecisions.end()) { std::string parentPath = m_pDS->fv(4).get_asString(); - if (!CDirectory::Exists(parentPath, false)) + bool parentPathNotExists = !CDirectory::Exists(parentPath, false); + // if the parent path exists, the file will be deleted without asking + // if the parent path doesn't exist, ask the user whether to remove all items it contained + if (parentPathNotExists) { // in silent mode assume that the files are just temporarily missing if (silent) @@ -8468,12 +8473,16 @@ std::vector<int> CVideoDatabase::CleanMediaType(const std::string &mediaType, co } } - pathsDeleteDecisions.insert(make_pair(parentPathID, del)); + parentPathsDeleteDecisions.insert(make_pair(parentPathID, make_pair(parentPathNotExists, del))); } - else - del = pathsDeleteDecision->second; + // the only reason not to delete the file is if the parent path doesn't + // exist and the user decided to delete all the items it contained + else if (parentPathsDeleteDecision->second.first && + !parentPathsDeleteDecision->second.second) + del = false; - pathsDeleteDecisions.insert(make_pair(m_pDS->fv(3).get_asInt(), del)); + if (m_pDS->fv(5).get_asBool()) + pathsDeleteDecisions.insert(make_pair(m_pDS->fv(3).get_asInt(), del)); if (del) { |