From 615b4d6cbbe19e3d9da271a549089da85a4444ea Mon Sep 17 00:00:00 2001 From: Felix Marx Date: Fri, 8 Feb 2013 16:23:31 +0100 Subject: [PATCH 1/2] DirectoryCache: access and save calls on DirectoryCache after substituting those calls as needed since it does not substitute them anymore --- xbmc/filesystem/Directory.cpp | 6 +++--- xbmc/filesystem/File.cpp | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/xbmc/filesystem/Directory.cpp b/xbmc/filesystem/Directory.cpp index 5b8c6de5d0991..8f4232e7bb2c5 100644 --- a/xbmc/filesystem/Directory.cpp +++ b/xbmc/filesystem/Directory.cpp @@ -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); @@ -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 diff --git a/xbmc/filesystem/File.cpp b/xbmc/filesystem/File.cpp index 1dbbd2296063f..3281a3d0b0273 100644 --- a/xbmc/filesystem/File.cpp +++ b/xbmc/filesystem/File.cpp @@ -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") @@ -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; @@ -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 { @@ -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 pFile(CFileFactory::CreateLoader(url)); if (!pFile.get()) return false; @@ -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; } } @@ -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; } } From d7e209a76beb2fc2971503953bab99f43a26cd61 Mon Sep 17 00:00:00 2001 From: Felix Marx Date: Fri, 8 Feb 2013 16:38:12 +0100 Subject: [PATCH 2/2] DirectoryCache: The cache keeps track of files and directories and should therefor not be the one to do any substituting. --- xbmc/filesystem/DirectoryCache.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xbmc/filesystem/DirectoryCache.cpp b/xbmc/filesystem/DirectoryCache.cpp index 844954352d51b..369d0a7d1fb80 100644 --- a/xbmc/filesystem/DirectoryCache.cpp +++ b/xbmc/filesystem/DirectoryCache.cpp @@ -64,7 +64,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); @@ -103,7 +103,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); @@ -127,7 +127,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); @@ -139,7 +139,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(); @@ -176,11 +176,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;