Expand '~/' to $HOME in session path.

This commit is contained in:
Jari Sundell
2026-01-06 12:44:40 +01:00
committed by GitHub
parent a8b6a47054
commit 289ab046bf
4 changed files with 29 additions and 3 deletions
+22
View File
@@ -2,6 +2,28 @@
#include "globals.h"
#include <torrent/exceptions.h>
rpc::ip_table_list ip_tables;
Control* control{};
std::string
expand_path(const std::string& path) {
if (path.empty())
return std::string();
if (path[0] == '~') {
if (path.size() < 2 || path[1] != '/')
throw torrent::input_error("Could not expand ~ in session path, only ~/<path> is supported.");
const char* home = std::getenv("HOME");
if (home == nullptr || *home == '\0')
throw torrent::input_error("Could not expand ~ in session path, HOME environment variable not set.");
return home + path.substr(1);
}
return path;
}