circache: handle the case where the cache dir exists but not the file
This commit is contained in:
parent
713a98de30
commit
ff1bf58ae0
@ -621,21 +621,33 @@ bool CirCache::create(off_t m_maxsize, int flags)
|
||||
LOGERR(("CirCache::create: null data\n"));
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(m_dir.c_str(), &st) < 0) {
|
||||
// Directory does not exist, create it
|
||||
if (mkdir(m_dir.c_str(), 0777) < 0) {
|
||||
m_d->m_reason << "CirCache::create: mkdir(" << m_dir <<
|
||||
") failed" << " errno " << errno;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!(flags & CC_CRTRUNCATE))
|
||||
// Directory exists but file might still not exist:
|
||||
// e.g. the user is using a non default directory and
|
||||
// created it for us.
|
||||
if (access(m_d->datafn(m_dir).c_str(), 0) >= 0) {
|
||||
// File exists, switch to "open" mode, except if we're told to
|
||||
// truncate.
|
||||
if (!(flags & CC_CRTRUNCATE)) {
|
||||
return open(CC_OPWRITE);
|
||||
}
|
||||
}
|
||||
// Else fall through to create file
|
||||
}
|
||||
}
|
||||
|
||||
if ((m_d->m_fd = ::open(m_d->datafn(m_dir).c_str(),
|
||||
O_CREAT | O_RDWR | O_TRUNC,
|
||||
0666)) < 0) {
|
||||
O_CREAT | O_RDWR | O_TRUNC, 0666)) < 0) {
|
||||
m_d->m_reason << "CirCache::create: open/creat(" <<
|
||||
m_d->datafn(m_dir) << ") failed " << "errno " << errno;
|
||||
return false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user