Tweak session renaming code
This commit is contained in:
parent
62fa133efd
commit
2425f4a781
|
@ -1902,10 +1902,10 @@ const CommandDesc change_working_directory_cmd = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const CommandDesc change_session_name = {
|
const CommandDesc set_session_name = {
|
||||||
"session",
|
"namesession",
|
||||||
nullptr,
|
nullptr,
|
||||||
"session <name>: change remote session name",
|
"namesession <name>: change remote session name",
|
||||||
ParameterDesc{{}, ParameterDesc::Flags::None, 1, 1},
|
ParameterDesc{{}, ParameterDesc::Flags::None, 1, 1},
|
||||||
CommandFlags::None,
|
CommandFlags::None,
|
||||||
CommandHelper{},
|
CommandHelper{},
|
||||||
|
@ -1914,10 +1914,6 @@ const CommandDesc change_session_name = {
|
||||||
{
|
{
|
||||||
if (not Server::instance().rename_session(parser[0]))
|
if (not Server::instance().rename_session(parser[0]))
|
||||||
throw runtime_error(format("Cannot rename current session: '{}' may be already in use", parser[0]));
|
throw runtime_error(format("Cannot rename current session: '{}' may be already in use", parser[0]));
|
||||||
|
|
||||||
// update modeline
|
|
||||||
for (auto& client : ClientManager::instance())
|
|
||||||
client->redraw_ifn();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1978,7 +1974,7 @@ void register_commands()
|
||||||
register_command(set_register_cmd);
|
register_command(set_register_cmd);
|
||||||
register_command(select_cmd);
|
register_command(select_cmd);
|
||||||
register_command(change_working_directory_cmd);
|
register_command(change_working_directory_cmd);
|
||||||
register_command(change_session_name);
|
register_command(set_session_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -651,17 +651,15 @@ Server::Server(String session_name)
|
||||||
m_listener.reset(new FDWatcher{listen_sock, accepter});
|
m_listener.reset(new FDWatcher{listen_sock, accepter});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::rename_session(const String& name)
|
bool Server::rename_session(StringView name)
|
||||||
{
|
{
|
||||||
String old_socket_file = format("/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, m_session);
|
String old_socket_file = format("/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, m_session);
|
||||||
String new_socket_file = format("/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, name);
|
String new_socket_file = format("/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, name);
|
||||||
|
|
||||||
if (link(old_socket_file.c_str(), new_socket_file.c_str()) != 0)
|
if (rename(old_socket_file.c_str(), new_socket_file.c_str()) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unlink(old_socket_file.c_str());
|
m_session = name.str();
|
||||||
|
|
||||||
m_session = name;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ struct Server : public Singleton<Server>
|
||||||
~Server();
|
~Server();
|
||||||
const String& session() const { return m_session; }
|
const String& session() const { return m_session; }
|
||||||
|
|
||||||
bool rename_session(const String& name);
|
bool rename_session(StringView name);
|
||||||
void close_session(bool do_unlink = true);
|
void close_session(bool do_unlink = true);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user