Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion xbmc/filesystem/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */)
{
try
{
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())
Expand Down
2 changes: 1 addition & 1 deletion xbmc/filesystem/Directory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion xbmc/filesystem/DirectoryCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
URIUtils::RemoveSlashAtEnd(storedPath);

ciCache i = m_cache.find(storedPath);
Expand Down