Skip to content


Make CDirectory::Exists support use directory cache by default. #2496

merged 1 commit into from

4 participants


We check file exists in CFile::Open() and CFile::Exists() for files, but not for dir in CDirectory::Exists() yet, this PR make CDirectory::Exists() also use directory cache to speed up the Exists operation.


Looks OK to me once rebased up.



@MartijnKaijser MartijnKaijser merged commit 33a0d63 into xbmc:master

This causes a problem with changing the GUI language during runtime. CLocalizeStrings::LoadStr2Mem() calls CDirectory::Exists() with the path of the directory of the new language. g_directoryCache.FileExists() returnes false but bPathInCache returns true so the next if-condition fails and returns false.

EDIT: Seems like the problem is using g_directoryCache.FileExists() with a path to a directory as it expects a path to a file. It removes the file and checks the existance of its parent directory in the cache. But when you pass in a directory path, it removes the top-most directory and checks its parent path, which is cached. But the file cache only stores files and not directories so bPathInCache becomes false.
TBH I'm wondering how this works anywhere with directories.

My bet is it's stored slash at end and looked up without (or vice-versa).


the requested dir doesn't ends with slash. but since we are calling CDirectory::Exists here, I will try to add the end slash to the dir to see whether it can be fixed by this.


Fixed in: #2608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
10 xbmc/filesystem/Directory.cpp
@@ -251,10 +251,18 @@ bool CDirectory::Create(const CStdString& strPath)
return false;
-bool CDirectory::Exists(const CStdString& strPath)
+bool CDirectory::Exists(const CStdString& strPath, bool bUseCache /* = true */)
+ if (bUseCache)
+ {
+ bool bPathInCache;
+ if (g_directoryCache.FileExists(strPath, bPathInCache))
+ return true;
+ if (bPathInCache)
+ return false;
+ }
CStdString realPath = URIUtils::SubstitutePath(strPath);
auto_ptr<IDirectory> pDirectory(CDirectoryFactory::Create(realPath));
if (pDirectory.get())
2  xbmc/filesystem/Directory.h
@@ -55,7 +55,7 @@ class CDirectory
, bool allowThreads=false);
static bool Create(const CStdString& strPath);
- static bool Exists(const CStdString& strPath);
+ static bool Exists(const CStdString& strPath, bool bUseCache = true);
static bool Remove(const CStdString& strPath);
/*! \brief Filter files that act like directories from the list, replacing them with their directory counterparts
4 xbmc/filesystem/DirectoryCache.cpp
@@ -175,8 +175,10 @@ bool CDirectoryCache::FileExists(const CStdString& strFile, bool& bInCache)
CSingleLock lock (m_cs);
bInCache = false;
+ CStdString strPath(strFile);
+ URIUtils::RemoveSlashAtEnd(strPath);
CStdString storedPath;
- URIUtils::GetDirectory(strFile, storedPath);
+ URIUtils::GetDirectory(strPath, storedPath);
ciCache i = m_cache.find(storedPath);
Something went wrong with that request. Please try again.