write tool fixes

This commit is contained in:
Luxferre
2026-10-14 12:19:11 +03:00
parent 59c85e9217
commit 05bce7ca9c
4 changed files with 31 additions and 6 deletions
+16 -4
View File
@@ -192,15 +192,27 @@ void mkdir_p(std::string_view dir) {
}
mkdir(path.c_str(), 0755);
}
std::string bantam_tmp_dir() {
std::string bantam_tmp_dir(std::string_view sess_id) {
const char *tmp = std::getenv("TMPDIR");
if (!tmp || !*tmp) tmp = "/tmp";
std::string p = std::string(tmp) + "/bantam";
std::string base(tmp);
/* Drop a single trailing slash so we never build a "//bantam" path (which
* some platforms treat as a special "super-root"); keep "/" itself intact. */
if (base.size() > 1 && base.back() == '/') base.pop_back();
std::string p = base;
if (p != "/") p += "/";
p += "bantam";
/* Segregate temporary artifacts per session so different projects/sessions
* never share or collide on scratch files. */
std::string sid(sess_id);
if (sid.empty()) sid = project_id();
if (!sid.empty()) { p += "/"; p += sid; }
mkdir_p(p);
return p;
}
std::string tool_res_dir() {
std::string base = bantam_tmp_dir();
std::string tool_res_dir(std::string_view sess_id) {
std::string base = bantam_tmp_dir(sess_id);
std::string p = base + "/toolres";
mkdir_p(p);
return p;