Skip to content

Commit eede4b4

Browse files
committed
Fix all buffer sent bug
1 parent 99daf7a commit eede4b4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/api/processor.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Processor {
9696
fn list_files(&self, path: &str) -> anyhow::Result<Response> {
9797
let dir_path = Path::new(&self.root_dir).join(path);
9898
log::info!(
99-
"Listing files at {}",
99+
"Listing files at {:?}",
100100
dir_path.to_str().unwrap_or("<Unknown>")
101101
);
102102
// Ideally we should find a way to learn the size of all files, but we need to
@@ -141,18 +141,19 @@ impl Processor {
141141
where
142142
F: FnMut(CommandResponse),
143143
{
144+
log::info!("Fetch file at {:?}, chunk_size={}", path, chunk_size);
144145
let mut file = std::fs::File::open(path)?;
145146
let file_size = file.metadata()?.len();
146147
let mut buf = vec![0; chunk_size as usize];
147148
for offset in (0..file_size).step_by(chunk_size as usize) {
148-
file.read(&mut buf)?;
149+
let read_size = file.read(&mut buf)?;
149150
// TODO: somehow stream_position doesn't work correctly?
150151
// assert_eq!(file.stream_position().unwrap(), offset);
151152
send(CommandResponse {
152153
id: req_id.to_string(),
153154
response: FetchFileChunk {
154155
offset,
155-
data: &buf,
156+
data: &buf[..read_size],
156157
is_final: offset + chunk_size >= file_size,
157158
},
158159
});
@@ -216,6 +217,7 @@ pub async fn process_events(
216217
}
217218
SessionEvent::ReceiveText { text } => {
218219
let request: serde_json::Result<CommandRequest> = serde_json::from_str(&text);
220+
log::info!("Processing request {:?}", request);
219221
match request {
220222
Ok(request) => processor.as_mut().unwrap().process(
221223
&request,

0 commit comments

Comments
 (0)