+ do_keep_all = keep;
+}
+
+temp_dir::temp_dir(const std::string & base_name)
+{
+ std::string tmp_dir_name(Glib::get_tmp_dir());
+ std::vector<char> template_name;
+ template_name.reserve(tmp_dir_name.size() + 1 + base_name.size() + 6 + 1);
+ name_.reserve(tmp_dir_name.size() + 1 + base_name.size() + 6);
+ template_name.assign(tmp_dir_name.begin(), tmp_dir_name.end());
+ template_name.insert(template_name.end(), '/');
+ template_name.insert(template_name.end(),
+ base_name.begin(), base_name.end());
+ template_name.insert(template_name.end(), 6, 'X');
+ template_name.insert(template_name.end(), '\0');
+ if (mkdtemp(&template_name[0]))
+ name_.assign(template_name.begin(), template_name.end() - 1);
+ else
+ throw std::runtime_error(
+ std::string("mkdtemp: ").append(std::strerror(errno)));
+}
+
+temp_dir::~temp_dir()
+{
+ if (!do_keep_all && !try_rmdir_recursive(name_))
+ std::cerr << "Warning: failed to remove temporary directory "
+ << name_ << "\n";