Tweak session renaming code

This commit is contained in:
Maxime Coste 2016-07-28 00:16:41 +01:00
parent 62fa133efd
commit 2425f4a781
3 changed files with 8 additions and 14 deletions

View File

@ -1902,10 +1902,10 @@ const CommandDesc change_working_directory_cmd = {
}
};
const CommandDesc change_session_name = {
"session",
const CommandDesc set_session_name = {
"namesession",
nullptr,
"session <name>: change remote session name",
"namesession <name>: change remote session name",
ParameterDesc{{}, ParameterDesc::Flags::None, 1, 1},
CommandFlags::None,
CommandHelper{},
@ -1914,10 +1914,6 @@ const CommandDesc change_session_name = {
{
if (not Server::instance().rename_session(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(select_cmd);
register_command(change_working_directory_cmd);
register_command(change_session_name);
register_command(set_session_name);
}
}

View File

@ -651,17 +651,15 @@ Server::Server(String session_name)
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 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;
unlink(old_socket_file.c_str());
m_session = name;
m_session = name.str();
return true;
}

View File

@ -48,7 +48,7 @@ struct Server : public Singleton<Server>
~Server();
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);
private: