aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Kaijser <martijn@xbmc.org>2016-01-10 00:33:14 -0800
committerMartijn Kaijser <martijn@xbmc.org>2016-01-10 00:33:14 -0800
commitc0541b52d6652f95dc966681ea72cfa0f8fddb77 (patch)
tree2611aacfa66c8b65b470da2f7110a82b0d23189f
parent10597e3b22e8207a133e25d74651fa7a53bbce13 (diff)
parent7643d82b4cdeb0676618e19f392fcde0b32908a6 (diff)
Merge pull request #8756 from arnova/dircache_url_options_fix_jarvis
fixed: Dir cache should ignore url (protocol) options (fixes #16469)
-rw-r--r--xbmc/FileItem.cpp8
-rw-r--r--xbmc/FileItem.h4
-rw-r--r--xbmc/URL.cpp18
-rw-r--r--xbmc/URL.h1
-rw-r--r--xbmc/filesystem/DirectoryCache.cpp28
-rw-r--r--xbmc/utils/URIUtils.cpp16
-rw-r--r--xbmc/utils/URIUtils.h2
7 files changed, 53 insertions, 24 deletions
diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp
index c5f07acfa3..49c7eec423 100644
--- a/xbmc/FileItem.cpp
+++ b/xbmc/FileItem.cpp
@@ -1537,9 +1537,9 @@ bool CFileItem::IsURL(const CURL& url) const
return IsPath(url.Get());
}
-bool CFileItem::IsPath(const std::string& path) const
+bool CFileItem::IsPath(const std::string& path, bool ignoreURLOptions /* = false */) const
{
- return URIUtils::PathEquals(m_strPath, path);
+ return URIUtils::PathEquals(m_strPath, path, false, ignoreURLOptions);
}
void CFileItem::SetCueDocument(const CCueDocumentPtr& cuePtr)
@@ -1705,7 +1705,7 @@ void CFileItemList::SetFastLookup(bool fastLookup)
m_fastLookup = fastLookup;
}
-bool CFileItemList::Contains(const std::string& fileName) const
+bool CFileItemList::Contains(const std::string& fileName, bool ignoreURLOptions /* = false */) const
{
CSingleLock lock(m_lock);
@@ -1716,7 +1716,7 @@ bool CFileItemList::Contains(const std::string& fileName) const
for (unsigned int i = 0; i < m_items.size(); i++)
{
const CFileItemPtr pItem = m_items[i];
- if (pItem->IsPath(fileName))
+ if (pItem->IsPath(fileName, ignoreURLOptions))
return true;
}
return false;
diff --git a/xbmc/FileItem.h b/xbmc/FileItem.h
index 293f979d64..2cf3dcfd50 100644
--- a/xbmc/FileItem.h
+++ b/xbmc/FileItem.h
@@ -126,7 +126,7 @@ public:
bool IsURL(const CURL& url) const;
const std::string &GetPath() const { return m_strPath; };
void SetPath(const std::string &path) { m_strPath = path; };
- bool IsPath(const std::string& path) const;
+ bool IsPath(const std::string& path, bool ignoreURLOptions = false) const;
/*! \brief reset class to it's default values as per construction.
Free's all allocated memory.
@@ -626,7 +626,7 @@ public:
void FilterCueItems();
void RemoveExtensions();
void SetFastLookup(bool fastLookup);
- bool Contains(const std::string& fileName) const;
+ bool Contains(const std::string& fileName, bool ignoreURLOptions = false) const;
bool GetFastLookup() const { return m_fastLookup; };
/*! \brief stack a CFileItemList
diff --git a/xbmc/URL.cpp b/xbmc/URL.cpp
index 2ecf050718..b23080d545 100644
--- a/xbmc/URL.cpp
+++ b/xbmc/URL.cpp
@@ -531,6 +531,9 @@ char CURL::GetDirectorySeparator() const
std::string CURL::Get() const
{
+ if (m_strProtocol.empty())
+ return m_strFileName;
+
unsigned int sizeneed = m_strProtocol.length()
+ m_strDomain.length()
+ m_strUserName.length()
@@ -541,23 +544,28 @@ std::string CURL::Get() const
+ m_strProtocolOptions.length()
+ 10;
- if (m_strProtocol.empty())
- return m_strFileName;
-
std::string strURL;
strURL.reserve(sizeneed);
- strURL = GetWithoutFilename();
- strURL += m_strFileName;
+ strURL = GetWithoutOptions();
if( !m_strOptions.empty() )
strURL += m_strOptions;
+
if (!m_strProtocolOptions.empty())
strURL += "|"+m_strProtocolOptions;
return strURL;
}
+std::string CURL::GetWithoutOptions() const
+{
+ if (m_strProtocol.empty())
+ return m_strFileName;
+
+ return GetWithoutFilename() + m_strFileName;
+}
+
std::string CURL::GetWithoutUserDetails(bool redact) const
{
std::string strURL;
diff --git a/xbmc/URL.h b/xbmc/URL.h
index d1018cf667..debe942bb5 100644
--- a/xbmc/URL.h
+++ b/xbmc/URL.h
@@ -67,6 +67,7 @@ public:
char GetDirectorySeparator() const;
std::string Get() const;
+ std::string GetWithoutOptions() const;
std::string GetWithoutUserDetails(bool redact = false) const;
std::string GetWithoutFilename() const;
std::string GetRedacted() const;
diff --git a/xbmc/filesystem/DirectoryCache.cpp b/xbmc/filesystem/DirectoryCache.cpp
index fe0fe898c9..d23c7fa819 100644
--- a/xbmc/filesystem/DirectoryCache.cpp
+++ b/xbmc/filesystem/DirectoryCache.cpp
@@ -24,6 +24,7 @@
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "utils/StringUtils.h"
+#include "URL.h"
#include "climits"
#include <algorithm>
@@ -38,7 +39,7 @@ CDirectoryCache::CDir::CDir(DIR_CACHE_TYPE cacheType)
m_cacheType = cacheType;
m_lastAccess = 0;
m_Items = new CFileItemList;
- m_Items->SetFastLookup(true);
+ m_Items->SetFastLookup(false);
}
CDirectoryCache::CDir::~CDir()
@@ -68,7 +69,8 @@ bool CDirectoryCache::GetDirectory(const std::string& strPath, CFileItemList &it
{
CSingleLock lock (m_cs);
- std::string storedPath = strPath;
+ // Get rid of any URL options, else the compare may be wrong
+ std::string storedPath = CURL(strPath).GetWithoutOptions();
URIUtils::RemoveSlashAtEnd(storedPath);
ciCache i = m_cache.find(storedPath);
@@ -107,7 +109,8 @@ void CDirectoryCache::SetDirectory(const std::string& strPath, const CFileItemLi
// this is the best solution for now.
CSingleLock lock (m_cs);
- std::string storedPath = strPath;
+ // Get rid of any URL options, else the compare may be wrong
+ std::string storedPath = CURL(strPath).GetWithoutOptions();
URIUtils::RemoveSlashAtEnd(storedPath);
ClearDirectory(storedPath);
@@ -122,14 +125,18 @@ void CDirectoryCache::SetDirectory(const std::string& strPath, const CFileItemLi
void CDirectoryCache::ClearFile(const std::string& strFile)
{
- ClearDirectory(URIUtils::GetDirectory(strFile));
+ // Get rid of any URL options, else the compare may be wrong
+ std::string strFile2 = CURL(strFile).GetWithoutOptions();
+
+ ClearDirectory(URIUtils::GetDirectory(strFile2));
}
void CDirectoryCache::ClearDirectory(const std::string& strPath)
{
CSingleLock lock (m_cs);
- std::string storedPath = strPath;
+ // Get rid of any URL options, else the compare may be wrong
+ std::string storedPath = CURL(strPath).GetWithoutOptions();
URIUtils::RemoveSlashAtEnd(storedPath);
iCache i = m_cache.find(storedPath);
@@ -141,7 +148,8 @@ void CDirectoryCache::ClearSubPaths(const std::string& strPath)
{
CSingleLock lock (m_cs);
- std::string storedPath = strPath;
+ // Get rid of any URL options, else the compare may be wrong
+ std::string storedPath = CURL(strPath).GetWithoutOptions();
URIUtils::RemoveSlashAtEnd(storedPath);
iCache i = m_cache.begin();
@@ -158,7 +166,8 @@ void CDirectoryCache::AddFile(const std::string& strFile)
{
CSingleLock lock (m_cs);
- std::string strPath = URIUtils::GetDirectory(strFile);
+ // Get rid of any URL options, else the compare may be wrong
+ std::string strPath = URIUtils::GetDirectory(CURL(strFile).GetWithoutOptions());
URIUtils::RemoveSlashAtEnd(strPath);
ciCache i = m_cache.find(strPath);
@@ -176,7 +185,8 @@ bool CDirectoryCache::FileExists(const std::string& strFile, bool& bInCache)
CSingleLock lock (m_cs);
bInCache = false;
- std::string strPath(strFile);
+ // Get rid of any URL options, else the compare may be wrong
+ std::string strPath = CURL(strFile).GetWithoutOptions();
URIUtils::RemoveSlashAtEnd(strPath);
std::string storedPath = URIUtils::GetDirectory(strPath);
URIUtils::RemoveSlashAtEnd(storedPath);
@@ -190,7 +200,7 @@ bool CDirectoryCache::FileExists(const std::string& strFile, bool& bInCache)
#ifdef _DEBUG
m_cacheHits++;
#endif
- return (URIUtils::PathEquals(strPath, storedPath) || dir->m_Items->Contains(strFile));
+ return (URIUtils::PathEquals(strPath, storedPath) || dir->m_Items->Contains(strFile, true));
}
#ifdef _DEBUG
m_cacheMisses++;
diff --git a/xbmc/utils/URIUtils.cpp b/xbmc/utils/URIUtils.cpp
index 8c76a82bfc..4a9903c6b0 100644
--- a/xbmc/utils/URIUtils.cpp
+++ b/xbmc/utils/URIUtils.cpp
@@ -522,10 +522,20 @@ bool URIUtils::PathStarts(const std::string& url, const char *start)
return StringUtils::StartsWith(url, start);
}
-bool URIUtils::PathEquals(const std::string& url, const std::string &start, bool ignoreTrailingSlash /* = false */)
+bool URIUtils::PathEquals(const std::string& url, const std::string &start, bool ignoreTrailingSlash /* = false */, bool ignoreURLOptions /* = false */)
{
- std::string path1 = url;
- std::string path2 = start;
+ std::string path1, path2;
+ if (ignoreURLOptions)
+ {
+ path1 = CURL(url).GetWithoutOptions();
+ path2 = CURL(start).GetWithoutOptions();
+ }
+ else
+ {
+ path1 = url;
+ path2 = start;
+ }
+
if (ignoreTrailingSlash)
{
RemoveSlashAtEnd(path1);
diff --git a/xbmc/utils/URIUtils.h b/xbmc/utils/URIUtils.h
index 483af5f38d..874d5ec81d 100644
--- a/xbmc/utils/URIUtils.h
+++ b/xbmc/utils/URIUtils.h
@@ -117,7 +117,7 @@ public:
\return true if the paths are equal, false otherwise.
\sa IsProtocol, PathStarts
*/
- static bool PathEquals(const std::string& path1, const std::string &path2, bool ignoreTrailingSlash = false);
+ static bool PathEquals(const std::string& path1, const std::string &path2, bool ignoreTrailingSlash = false, bool ignoreURLOptions = false);
static bool IsAddonsPath(const std::string& strFile);
static bool IsSourcesPath(const std::string& strFile);