Add server-owned stacked panes with vertical navigation
This commit is contained in:
+61
-11
@@ -86,17 +86,21 @@ pub fn control(socket: &Path, command: ClientMessage) -> Result<ServerMessage> {
|
||||
let stream = UnixStream::connect(socket)
|
||||
.with_context(|| format!("connect to psyTerm server at {}", socket.display()))?;
|
||||
let legacy_shutdown = matches!(command, ClientMessage::Shutdown);
|
||||
let result = control_stream(stream, command, REQUEST_TIMEOUT);
|
||||
if legacy_shutdown
|
||||
&& protocol::VERSION > 1
|
||||
&& result
|
||||
.as_ref()
|
||||
.is_err_and(|error| error.to_string().contains("protocol"))
|
||||
{
|
||||
// Version 1 shares the Hello/Shutdown/Closing wire prefix. Permit only
|
||||
// an explicit shutdown through that prefix, never old grid decoding.
|
||||
let stream = UnixStream::connect(socket)?;
|
||||
return control_stream_version(stream, ClientMessage::Shutdown, REQUEST_TIMEOUT, 1);
|
||||
let mut result = control_stream(stream, command, REQUEST_TIMEOUT);
|
||||
if legacy_shutdown {
|
||||
// Older versions share the Hello/Shutdown/Closing wire prefix. Permit
|
||||
// only explicit shutdown through it, never decoding older grid layouts.
|
||||
for version in (1..protocol::VERSION).rev() {
|
||||
if !result
|
||||
.as_ref()
|
||||
.is_err_and(|error| error.to_string().contains("protocol"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
let stream = UnixStream::connect(socket)?;
|
||||
result =
|
||||
control_stream_version(stream, ClientMessage::Shutdown, REQUEST_TIMEOUT, version);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
@@ -672,6 +676,52 @@ mod tests {
|
||||
path
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_shutdown_negotiates_previous_protocol_prefixes() {
|
||||
for old_version in 1..protocol::VERSION {
|
||||
let root = test_dir();
|
||||
let socket = root.join("server.sock");
|
||||
let listener = UnixListener::bind(&socket).unwrap();
|
||||
let peer = thread::spawn(move || {
|
||||
for expected_attempt in (old_version..=protocol::VERSION).rev() {
|
||||
let (mut stream, _) = listener.accept().unwrap();
|
||||
stream.set_read_timeout(Some(REQUEST_TIMEOUT)).unwrap();
|
||||
let hello = protocol::read_message::<ClientMessage>(&mut stream).unwrap();
|
||||
assert!(
|
||||
matches!(hello, ClientMessage::Hello { version } if version == expected_attempt)
|
||||
);
|
||||
if expected_attempt != old_version {
|
||||
protocol::write_message(
|
||||
&mut stream,
|
||||
&ServerMessage::Error("protocol mismatch".into()),
|
||||
)
|
||||
.unwrap();
|
||||
continue;
|
||||
}
|
||||
protocol::write_message(
|
||||
&mut stream,
|
||||
&ServerMessage::Hello {
|
||||
version: old_version,
|
||||
server_pid: std::process::id(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
assert!(matches!(
|
||||
protocol::read_message::<ClientMessage>(&mut stream).unwrap(),
|
||||
ClientMessage::Shutdown
|
||||
));
|
||||
protocol::write_message(&mut stream, &ServerMessage::Closing).unwrap();
|
||||
}
|
||||
});
|
||||
assert!(matches!(
|
||||
control(&socket, ClientMessage::Shutdown).unwrap(),
|
||||
ServerMessage::Closing
|
||||
));
|
||||
peer.join().unwrap();
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn private_paths_reject_symlinks_and_shared_directories() {
|
||||
let root = test_dir();
|
||||
|
||||
Reference in New Issue
Block a user