gui: resolve session/agent names from IDs before building 9P paths

killSession, renameSession, readLogForSession, getAgents, and
renameAgent were using immutable IDs directly in paths like
session/{id}/ctl. The 9P namespace uses the mutable display name
as the directory key, not the ID. Use sessionNameForId() and
agentNameForId() consistently (matching agentPath()).
This commit is contained in:
Levi Neely 2026-08-03 09:09:49 +02:00
parent 34d4a97b3d
commit 042f287796
1 changed files with 25 additions and 5 deletions

View File

@ -363,7 +363,11 @@ QString Ollie9pClient::readLog()
QString Ollie9pClient::readLogForSession(const QString &sessionId, const QString &agentId)
{
if (sessionId.isEmpty() || agentId.isEmpty()) return {};
QByteArray out = run9p({"read", "session/" + sessionId + "/agent/" + agentId + "/log"});
QString sessName = sessionNameForId(sessionId);
if (sessName.isEmpty()) sessName = sessionId;
QString agentName = agentNameForId(sessionId, agentId);
if (agentName.isEmpty()) agentName = agentId;
QByteArray out = run9p({"read", "session/" + sessName + "/agent/" + agentName + "/log"});
return QString::fromUtf8(out);
}
@ -412,7 +416,11 @@ bool Ollie9pClient::killSession(const QString &sessionId)
stopStreams();
}
QString path = "session/" + sessionId + "/ctl";
// Resolve the directory name from the immutable session ID
QString sessName = sessionNameForId(sessionId);
if (sessName.isEmpty()) sessName = sessionId;
QString path = "session/" + sessName + "/ctl";
QProcess proc;
proc.start(ninepBin(), {"-a", serverAddr(), "write", path});
proc.waitForStarted(3000);
@ -432,7 +440,9 @@ QString Ollie9pClient::getConfig()
QStringList Ollie9pClient::getAgents(const QString &sessionId)
{
if (sessionId.isEmpty()) return {};
QByteArray out = run9p({"ls", "session/" + sessionId + "/agent"});
QString sessName = sessionNameForId(sessionId);
if (sessName.isEmpty()) sessName = sessionId;
QByteArray out = run9p({"ls", "session/" + sessName + "/agent"});
QString raw = QString::fromUtf8(out).trimmed();
if (raw.isEmpty()) return {};
QStringList all = raw.split('\n', Qt::SkipEmptyParts);
@ -596,9 +606,13 @@ bool Ollie9pClient::renameSession(const QString &sessionId, const QString &newNa
// Session names are mutable display names, not directory IDs. Writing the
// name file also avoids relying on Twstat, which is not implemented by all
// 9P frontends.
// Resolve the directory name from the immutable session ID
QString sessName = sessionNameForId(sessionId);
if (sessName.isEmpty()) sessName = sessionId;
QProcess proc;
proc.setProgram(bin);
proc.setArguments({"-a", serverAddr(), "write", "session/" + sessionId + "/name"});
proc.setArguments({"-a", serverAddr(), "write", "session/" + sessName + "/name"});
proc.start();
if (!proc.waitForStarted(3000)) {
qDebug() << "renameSession failed to start:" << proc.errorString();
@ -649,10 +663,16 @@ bool Ollie9pClient::renameAgent(const QString &sessionId, const QString &agentId
if (active)
stopAgentStreams();
// Resolve directory names from immutable IDs
QString sessName = sessionNameForId(sessionId);
if (sessName.isEmpty()) sessName = sessionId;
QString agentName = agentNameForId(sessionId, agentId);
if (agentName.isEmpty()) agentName = agentId;
QProcess proc;
proc.setProgram(bin);
proc.setArguments({"-a", serverAddr(), "write",
"session/" + sessionId + "/agent/" + agentId + "/name"});
"session/" + sessName + "/agent/" + agentName + "/name"});
proc.start();
if (!proc.waitForStarted(3000)) {
qDebug() << "renameAgent failed to start:" << proc.errorString();