web indexing prefs: display the current cache size

This commit is contained in:
Jean-Francois Dockes 2021-03-23 10:51:14 +01:00
parent ce6c0edc91
commit 5e82af9798
3 changed files with 34 additions and 3 deletions

View File

@ -32,6 +32,7 @@
#include <set>
#include <string>
#include <functional>
#include <memory>
using std::vector;
using std::set;
using std::string;
@ -43,6 +44,8 @@ using std::string;
#include "rcldb.h"
#include "execmd.h"
#include "rclconfig.h"
#include "webstore.h"
#include "circache.h"
static const int spacing = 3;
static const int margin = 3;
@ -353,8 +356,12 @@ bool ConfIndexW::setupWebHistoryPanel(int idx)
"file (only waste space at the end)."
), -1, 1000*1000); // Max 1TB...
m_w->enableLink(bparam, cparam);
int64_t sz = -1;
auto ws = std::unique_ptr<WebStore>(new WebStore(m_rclconf));
sz = ws->cc()->size();
m_w->addBlurb(idx, tr("Note: old pages will be erased to make space for "
"new ones when the maximum size is reached"));
"new ones when the maximum size is reached. "
"Current size: %1").arg(u8s2qs(displayableBytes(sz))));
m_w->endOfList(idx);
return true;
}

View File

@ -787,6 +787,29 @@ bool CirCache::open(OpMode mode)
return m_d->readfirstblock();
}
int64_t CirCache::size()
{
if (m_d == 0) {
LOGERR("CirCache::open: null data\n");
return -1;
}
struct stat st;
if (m_d->m_fd < 0) {
if (stat(m_d->datafn(m_dir).c_str(), &st) < 0) {
m_d->m_reason << "CirCache::size: stat(" << m_d->datafn(m_dir) <<
") failed " << "errno " << errno;
return -1;
}
} else {
if (fstat(m_d->m_fd, &st) < 0) {
m_d->m_reason << "CirCache::open: fstat(" << m_d->datafn(m_dir) <<
") failed " << "errno " << errno;
return -1;
}
}
return st.st_size;
}
class CCScanHookDump : public CCScanHook {
public:
virtual status takeone(int64_t offs, const string& udi,

View File

@ -37,8 +37,7 @@
*/
#include <sys/types.h>
#include <stdint.h>
#include <cstdint>
#include <string>
class ConfSimple;
@ -63,6 +62,8 @@ public:
enum OpMode {CC_OPREAD, CC_OPWRITE};
virtual bool open(OpMode mode);
virtual int64_t size();
virtual std::string getpath();
// Set data to 0 if you just want the header