mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-23 01:22:12 +03:00
extract pty writer
This commit is contained in:
parent
de30d69128
commit
6167ee0a31
@ -496,10 +496,7 @@ impl App {
|
||||
)
|
||||
.context("failed to open repository")?;
|
||||
|
||||
let session = gb_repository
|
||||
.get_or_create_current_session()
|
||||
.context("failed to get session")?;
|
||||
let writer = sessions::Writer::open(&gb_repository, &session)?;
|
||||
let pty_writer = pty::Writer::new(&gb_repository)?;
|
||||
|
||||
let timestamp = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
@ -512,7 +509,7 @@ impl App {
|
||||
bytes: bytes.to_vec(),
|
||||
};
|
||||
|
||||
writer.append_pty(&record).context("failed to append pty")?;
|
||||
pty_writer.write(&record).context("failed to append pty")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
mod connection;
|
||||
mod recorder;
|
||||
mod server;
|
||||
mod writer;
|
||||
|
||||
pub use recorder::{Record, Type};
|
||||
pub use server::start_server;
|
||||
pub use writer::PtyWriter as Writer;
|
||||
|
37
src-tauri/src/pty/writer.rs
Normal file
37
src-tauri/src/pty/writer.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use crate::gb_repository;
|
||||
|
||||
use super::Record;
|
||||
|
||||
pub struct PtyWriter<'writer> {
|
||||
repository: &'writer gb_repository::Repository,
|
||||
}
|
||||
|
||||
impl<'writer> PtyWriter<'writer> {
|
||||
pub fn new(repository: &'writer gb_repository::Repository) -> Result<Self> {
|
||||
repository
|
||||
.get_or_create_current_session()
|
||||
.context("failed to create session")?;
|
||||
Ok(Self { repository })
|
||||
}
|
||||
|
||||
pub fn write(&self, record: &Record) -> Result<()> {
|
||||
self.repository.lock()?;
|
||||
defer! {
|
||||
self.repository.unlock().expect("failed to unlock");
|
||||
}
|
||||
|
||||
serde_jsonlines::append_json_lines(
|
||||
self.repository.session_path().join("pty.jsonl"),
|
||||
[record],
|
||||
)?;
|
||||
|
||||
log::info!(
|
||||
"{}: appended pty record to session",
|
||||
self.repository.project_id
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ use std::time;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use crate::{
|
||||
bookmarks, gb_repository, pty,
|
||||
bookmarks, gb_repository,
|
||||
reader::{self, Reader},
|
||||
writer::{self, Writer},
|
||||
};
|
||||
@ -127,25 +127,6 @@ impl<'writer> SessionWriter<'writer> {
|
||||
Ok(writer)
|
||||
}
|
||||
|
||||
pub fn append_pty(&self, record: &pty::Record) -> Result<()> {
|
||||
self.repository.lock()?;
|
||||
defer! {
|
||||
self.repository.unlock().expect("failed to unlock");
|
||||
}
|
||||
|
||||
serde_jsonlines::append_json_lines(
|
||||
self.repository.session_path().join("pty.jsonl"),
|
||||
[record],
|
||||
)?;
|
||||
|
||||
log::info!(
|
||||
"{}: appended pty record to session",
|
||||
self.repository.project_id
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_session_wd_file<P: AsRef<std::path::Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
|
Loading…
Reference in New Issue
Block a user