Skip to content

Commit

Permalink
Merge pull request #2192 from DasMarx/cacheFixes
Browse files Browse the repository at this point in the history
Cache fixes, e.g. after pathsubstituion
  • Loading branch information
Arne Morten Kvarving committed Apr 6, 2013
2 parents 1358020 + d7e209a commit 65fcfa6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions xbmc/filesystem/Directory.cpp
Expand Up @@ -133,14 +133,14 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, c
return false;

// check our cache for this path
if (g_directoryCache.GetDirectory(strPath, items, (hints.flags & DIR_FLAG_READ_CACHE) == DIR_FLAG_READ_CACHE))
if (g_directoryCache.GetDirectory(realPath, items, (hints.flags & DIR_FLAG_READ_CACHE) == DIR_FLAG_READ_CACHE))
items.SetPath(strPath);
else
{
// need to clear the cache (in case the directory fetch fails)
// and (re)fetch the folder
if (!(hints.flags & DIR_FLAG_BYPASS_CACHE))
g_directoryCache.ClearDirectory(strPath);
g_directoryCache.ClearDirectory(realPath);

pDirectory->SetFlags(hints.flags);

Expand Down Expand Up @@ -198,7 +198,7 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, c

// cache the directory, if necessary
if (!(hints.flags & DIR_FLAG_BYPASS_CACHE))
g_directoryCache.SetDirectory(strPath, items, pDirectory->GetCacheType(strPath));
g_directoryCache.SetDirectory(realPath, items, pDirectory->GetCacheType(strPath));
}

// now filter for allowed files
Expand Down
16 changes: 8 additions & 8 deletions xbmc/filesystem/DirectoryCache.cpp
Expand Up @@ -63,7 +63,7 @@ bool CDirectoryCache::GetDirectory(const CStdString& strPath, CFileItemList &ite
{
CSingleLock lock (m_cs);

CStdString storedPath = URIUtils::SubstitutePath(strPath);
CStdString storedPath = strPath;
URIUtils::RemoveSlashAtEnd(storedPath);

ciCache i = m_cache.find(storedPath);
Expand Down Expand Up @@ -102,7 +102,7 @@ void CDirectoryCache::SetDirectory(const CStdString& strPath, const CFileItemLis
// this is the best solution for now.
CSingleLock lock (m_cs);

CStdString storedPath = URIUtils::SubstitutePath(strPath);
CStdString storedPath = strPath;
URIUtils::RemoveSlashAtEnd(storedPath);

ClearDirectory(storedPath);
Expand All @@ -126,7 +126,7 @@ void CDirectoryCache::ClearDirectory(const CStdString& strPath)
{
CSingleLock lock (m_cs);

CStdString storedPath = URIUtils::SubstitutePath(strPath);
CStdString storedPath = strPath;
URIUtils::RemoveSlashAtEnd(storedPath);

iCache i = m_cache.find(storedPath);
Expand All @@ -138,7 +138,7 @@ void CDirectoryCache::ClearSubPaths(const CStdString& strPath)
{
CSingleLock lock (m_cs);

CStdString storedPath = URIUtils::SubstitutePath(strPath);
CStdString storedPath = strPath;
URIUtils::RemoveSlashAtEnd(storedPath);

iCache i = m_cache.begin();
Expand Down Expand Up @@ -175,11 +175,11 @@ bool CDirectoryCache::FileExists(const CStdString& strFile, bool& bInCache)
CSingleLock lock (m_cs);
bInCache = false;

CStdString strPath;
URIUtils::GetDirectory(strFile, strPath);
URIUtils::RemoveSlashAtEnd(strPath);
CStdString storedPath;
URIUtils::GetDirectory(strFile, storedPath);
URIUtils::RemoveSlashAtEnd(storedPath);

ciCache i = m_cache.find(strPath);
ciCache i = m_cache.find(storedPath);
if (i != m_cache.end())
{
bInCache = true;
Expand Down
18 changes: 9 additions & 9 deletions xbmc/filesystem/File.cpp
Expand Up @@ -215,7 +215,7 @@ bool CFile::Open(const CStdString& strFileName, unsigned int flags)
try
{
bool bPathInCache;
CURL url2(strFileName);
CURL url2(URIUtils::SubstitutePath(strFileName));
if (url2.GetProtocol() == "apk")
url2.SetOptions("");
if (url2.GetProtocol() == "zip")
Expand Down Expand Up @@ -312,13 +312,14 @@ bool CFile::OpenForWrite(const CStdString& strFileName, bool bOverWrite)
{
try
{
CURL url(URIUtils::SubstitutePath(strFileName));
CStdString storedFileName = URIUtils::SubstitutePath(strFileName);
CURL url(storedFileName);

m_pFile = CFileFactory::CreateLoader(url);
if (m_pFile && m_pFile->OpenForWrite(url, bOverWrite))
{
// add this file to our directory cache (if it's stored)
g_directoryCache.AddFile(strFileName);
g_directoryCache.AddFile(storedFileName);
return true;
}
return false;
Expand All @@ -334,7 +335,7 @@ bool CFile::OpenForWrite(const CStdString& strFileName, bool bOverWrite)

bool CFile::Exists(const CStdString& strFileName, bool bUseCache /* = true */)
{
CURL url;
CURL url = URIUtils::SubstitutePath(strFileName);;

try
{
Expand All @@ -344,13 +345,12 @@ bool CFile::Exists(const CStdString& strFileName, bool bUseCache /* = true */)
if (bUseCache)
{
bool bPathInCache;
if (g_directoryCache.FileExists(strFileName, bPathInCache) )
if (g_directoryCache.FileExists(url.Get(), bPathInCache) )
return true;
if (bPathInCache)
return false;
}

url = URIUtils::SubstitutePath(strFileName);
auto_ptr<IFile> pFile(CFileFactory::CreateLoader(url));
if (!pFile.get())
return false;
Expand Down Expand Up @@ -718,7 +718,7 @@ bool CFile::Delete(const CStdString& strFileName)

if(pFile->Delete(url))
{
g_directoryCache.ClearFile(strFileName);
g_directoryCache.ClearFile(url.Get());
return true;
}
}
Expand All @@ -745,8 +745,8 @@ bool CFile::Rename(const CStdString& strFileName, const CStdString& strNewFileNa

if(pFile->Rename(url, urlnew))
{
g_directoryCache.ClearFile(strFileName);
g_directoryCache.ClearFile(strNewFileName);
g_directoryCache.ClearFile(url.Get());
g_directoryCache.AddFile(urlnew.Get());
return true;
}
}
Expand Down

0 comments on commit 65fcfa6

Please sign in to comment.