mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 21:52:30 +00:00
Expand '~/' to $HOME in session path.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
+2
-1
@@ -8,8 +8,9 @@
|
||||
class Control;
|
||||
|
||||
extern rpc::ip_table_list ip_tables;
|
||||
extern Control* control;
|
||||
|
||||
extern Control* control;
|
||||
std::string expand_path(const std::string& path);
|
||||
|
||||
namespace rpc {
|
||||
class SCgi;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "session/session_manager.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/utils/log.h>
|
||||
|
||||
@@ -23,12 +24,14 @@ SessionManager::SessionManager(torrent::utils::Thread* thread)
|
||||
SessionManager::~SessionManager() = default;
|
||||
|
||||
void
|
||||
SessionManager::set_path(const std::string& path) {
|
||||
SessionManager::set_path(std::string path) {
|
||||
assert(torrent::this_thread::thread() == torrent::main_thread::thread());
|
||||
|
||||
if (m_freeze_info)
|
||||
throw torrent::input_error("Session path cannot be changed after startup.");
|
||||
|
||||
path = expand_path(path);
|
||||
|
||||
if (path.empty() || path.back() == '/')
|
||||
m_path = path;
|
||||
else
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
bool is_used() const;
|
||||
|
||||
std::string path() const;
|
||||
void set_path(const std::string& path);
|
||||
void set_path(std::string path);
|
||||
|
||||
bool use_fsyncdisk() const;
|
||||
void set_use_fsyncdisk(bool use_fsyncdisk);
|
||||
|
||||
Reference in New Issue
Block a user