graph_blob << m_ctx->get_progress();
BEESLOGINFO(graph_blob.str());
- catch_all([&]() {
- m_stats_file.write(graph_blob.str());
- });
+ // Skip the on-disk stats file when paths.home is unavailable
+ // (state.persistent=no with no home directory). The log copy
+ // above still fires so operators see the same content; only
+ // the file write is suppressed to avoid throwing from the
+ // inert BeesStringFile handle.
+ if (m_ctx->home_fd()) {
+ catch_all([&]() {
+ m_stats_file.write(graph_blob.str());
+ });
+ }
if (not_locked && !m_stop_requested) {
// Always do the mlock, whether shared or not
void
BeesRoots::import_legacy()
{
+ // No on-disk home means no legacy beescrawl.dat to migrate. Bail
+ // before opening BeesStringFile against an empty home_fd(), which
+ // would throw on the inert read() below.
+ if (!m_ctx->home_fd()) {
+ return;
+ }
+
BEESNOTE("importing beescrawl.dat into beespoint.ini");
BEESLOGINFO("Importing beescrawl.dat into beespoint.ini");
{
// Must already be holding m_mutex.
+ // No on-disk home means no beespoint.ini to write. Bail before
+ // iterating crawlers and serialising the INI string — the work is
+ // wasted and m_point_file.write() would throw on its inert handle.
+ if (!m_ctx->home_fd()) {
+ return;
+ }
+
if (m_crawl_clean == m_crawl_dirty) {
BEESLOGINFO("Nothing to save");
return;
void
BeesRoots::flush_pending_checkpoints(bool force)
{
+ // Defence in depth: snapshot_point() already bails when home_fd()
+ // is empty so the queue stays empty, but bail here too so the
+ // queue-drain loop never attempts an inert write.
+ if (!m_ctx->home_fd()) {
+ return;
+ }
+
while (true) {
string write_ini;
uint64_t write_seq = 0;
string
BeesStringFile::read()
{
+ // Inert handle: relative name with no dir fd is a programming error.
+ // Callers that bind a BeesStringFile to home_fd() must check
+ // !home_fd() upfront and skip read() before getting here. The
+ // absolute-path branch (m_name starts with '/') stays supported below
+ // via AT_FDCWD; only the relative-name + empty-dir-fd combination
+ // throws.
+ if (!m_dir_fd && !m_name.empty() && m_name.at(0) != '/') {
+ THROW_ERROR(runtime_error, "BeesStringFile read on inert handle: m_dir_fd unset and relative name '" << m_name << "'");
+ }
+
BEESNOTE("opening " << m_name << " in " << name_fd(m_dir_fd));
Fd fd;
const auto fdcwd = (!m_dir_fd) ? AT_FDCWD : m_dir_fd.operator int();
void
BeesStringFile::write(string contents)
{
+ // Inert handle: symmetric to read(). A relative name with no dir fd
+ // means the caller built content destined for an unbound BeesStringFile
+ // without checking home_fd() first. Throw rather than silently dropping
+ // the write so the bug is operator-visible.
+ if (!m_dir_fd && !m_name.empty() && m_name.at(0) != '/') {
+ THROW_ERROR(runtime_error, "BeesStringFile write on inert handle: m_dir_fd unset and relative name '" << m_name << "'");
+ }
+
// Path components not allowed - this code can't implement m_allow_symlink with them
THROW_CHECK1(invalid_argument, m_name, m_name.find_first_of("/") == string::npos);