From fdfa78a81b07f51d402d396f214c1f3a0521b884 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 1 Dec 2016 21:56:10 -0500 Subject: [PATCH] context: default and relative BEESHOME Allow relative paths with BEESHOME. These paths will be relative to the root of the dedup target filesystem. BEESHOME is now optional. If not specified, '.beeshome' is used. We don't try to create BEESHOME if it doesn't exist. BEESHOME might not be on a btrfs filesystem, so we can't insist it be a subvol. --- src/bees-context.cc | 17 ++++++++++++++--- src/bees.h | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/bees-context.cc b/src/bees-context.cc index 932c01a..10783ca 100644 --- a/src/bees-context.cc +++ b/src/bees-context.cc @@ -229,12 +229,23 @@ BeesContext::show_progress() } } +Fd +BeesContext::home_fd() +{ + const char *base_dir = getenv("BEESHOME"); + if (!base_dir) { + base_dir = ".beeshome"; + } + m_home_fd = openat(root_fd(), base_dir, FLAGS_OPEN_DIR); + if (!m_home_fd) { + THROW_ERRNO("openat: " << name_fd(root_fd()) << " / " << base_dir); + } + return m_home_fd; +} + BeesContext::BeesContext(shared_ptr parent) : m_parent_ctx(parent) { - auto base_dir = getenv_or_die("BEESHOME"); - BEESLOG("BEESHOME = " << base_dir); - m_home_fd = open_or_die(base_dir, FLAGS_OPEN_DIR); if (m_parent_ctx) { m_hash_table = m_parent_ctx->hash_table(); m_hash_table->set_shared(true); diff --git a/src/bees.h b/src/bees.h index 154b695..82cbdae 100644 --- a/src/bees.h +++ b/src/bees.h @@ -719,7 +719,7 @@ public: void set_root_path(string path); Fd root_fd() const { return m_root_fd; } - Fd home_fd() const { return m_home_fd; } + Fd home_fd(); string root_path() const { return m_root_path; } string root_uuid() const { return m_root_uuid; }