Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

videodb: fix database cleaning for file-level sources

  • Loading branch information...
commit 5da031f4d89c5ff09365c1d2b3d85608ef951eaa 1 parent 2c1e2f6
@Montellese Montellese authored
Showing with 17 additions and 8 deletions.
  1. +17 −8 xbmc/video/VideoDatabase.cpp
View
25 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)
{
Please sign in to comment.
Something went wrong with that request. Please try again.