From 8b3bc7d50d3ad832019bc5a03e09791965bc3961 Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Fri, 28 Jan 2022 19:52:16 +1100 Subject: [PATCH 1/4] Fix log panel log --- console_backend/src/log_panel.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/console_backend/src/log_panel.rs b/console_backend/src/log_panel.rs index 7ed3f8763..52ed511b5 100644 --- a/console_backend/src/log_panel.rs +++ b/console_backend/src/log_panel.rs @@ -173,6 +173,7 @@ fn write_packet(packet: ConsoleLogPacket, f: &mut File) { timestamp = packet.timestamp, level = packet.level, msg = packet.msg, + spaces = spaces, ); } From e4bf8afc6b5c94e4fc3da234e082573e55805e3b Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Fri, 28 Jan 2022 19:53:12 +1100 Subject: [PATCH 2/4] fileio: Fix hang on error Fixes a hang in fileio that would occur if any command had an error during processing, causing the sbp reading thread to wait forever due to never receiving its exit condition. This moves all the potentially error-producing functions into closures, so that the errors can be handled together. --- console_backend/src/bin/fileio.rs | 65 ++++++++++++++++++------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/console_backend/src/bin/fileio.rs b/console_backend/src/bin/fileio.rs index e79d0fa7c..87f4af2fc 100644 --- a/console_backend/src/bin/fileio.rs +++ b/console_backend/src/bin/fileio.rs @@ -75,19 +75,22 @@ fn main() -> Result<()> { let sender = MsgSender::new(writer); scope(|s| { s.spawn(|_| run(rdr)); - let mut fileio = Fileio::new(link, sender); - let file = fs::File::open(source)?; - let size = file.metadata()?.len() as usize; - let mut bytes_written = 0; - print!("\rWriting 0.0%..."); - fileio.overwrite_with_progress(dest, file, |n| { - bytes_written += n; - let progress = (bytes_written as f64) / (size as f64) * 100.0; - print!("\rWriting {:.2}%...", progress); - })?; - println!("\nFile written successfully ({} bytes).", bytes_written); + let res = (|| { + let mut fileio = Fileio::new(link, sender); + let file = fs::File::open(source)?; + let size = file.metadata()?.len() as usize; + let mut bytes_written = 0; + print!("\rWriting 0.0%..."); + fileio.overwrite_with_progress(dest, file, |n| { + bytes_written += n; + let progress = (bytes_written as f64) / (size as f64) * 100.0; + print!("\rWriting {:.2}%...", progress); + })?; + println!("\nFile written successfully ({} bytes).", bytes_written); + Ok(()) + })(); done_tx.send(true).unwrap(); - Result::Ok(()) + res }) .unwrap() } @@ -100,14 +103,16 @@ fn main() -> Result<()> { let sender = MsgSender::new(writer); scope(|s| { s.spawn(|_| run(rdr)); - let mut fileio = Fileio::new(link, sender); - let dest: Box = match dest { - Some(path) => Box::new(fs::File::create(path)?), - None => Box::new(io::stdout()), - }; - fileio.read(source, dest)?; + let res = (|| { + let mut fileio = Fileio::new(link, sender); + let dest: Box = match dest { + Some(path) => Box::new(fs::File::create(path)?), + None => Box::new(io::stdout()), + }; + fileio.read(source, dest) + })(); done_tx.send(true).unwrap(); - Result::Ok(()) + res }) .unwrap() } @@ -116,11 +121,14 @@ fn main() -> Result<()> { let sender = MsgSender::new(writer); scope(|s| { s.spawn(|_| run(rdr)); - let mut fileio = Fileio::new(link, sender); - let files = fileio.readdir(path)?; - eprintln!("{:#?}", files); + let res = (|| { + let mut fileio = Fileio::new(link, sender); + let files = fileio.readdir(path)?; + eprintln!("{:#?}", files); + Ok(()) + })(); done_tx.send(true).unwrap(); - Result::Ok(()) + res }) .unwrap() } @@ -129,11 +137,14 @@ fn main() -> Result<()> { let sender = MsgSender::new(writer); scope(|s| { s.spawn(|_| run(rdr)); - let fileio = Fileio::new(link, sender); - fileio.remove(path)?; - eprintln!("File deleted."); + let res = (|| { + let fileio = Fileio::new(link, sender); + fileio.remove(path)?; + eprintln!("File deleted."); + Ok(()) + })(); done_tx.send(true).unwrap(); - Result::Ok(()) + res }) .unwrap() } From f0b91aa7bd411bb705c0911dc03d536e4dfce32a Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Fri, 28 Jan 2022 20:11:28 +1100 Subject: [PATCH 3/4] fileio: Add hint to the dir listing timeout error The MSG_FILEIO_READ_DIR_RESP isn't enable to be output by default on Piksis, so it would be useful to provide a hint to users as to why the command may be timing out. --- console_backend/src/fileio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console_backend/src/fileio.rs b/console_backend/src/fileio.rs index e7542e91c..375a77b8f 100644 --- a/console_backend/src/fileio.rs +++ b/console_backend/src/fileio.rs @@ -259,7 +259,7 @@ impl Fileio { }, recv(channel::tick(READDIR_TIMEOUT)) -> _ => { self.link.unregister(key); - bail!("MsgFileioReadDirReq timed out"); + bail!("MsgFileioReadDirReq timed out. Is the device configured to emit MSG_FILEIO_READ_DIR_RESP (170) messages?"); } } } From f22c07e82323e9de59478fc45b056b4866e495b2 Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Fri, 28 Jan 2022 20:40:17 +1100 Subject: [PATCH 4/4] fileio: Print list like the python version Prints to stdout instead of stderror and prints each entry without the list formatting --- console_backend/src/bin/fileio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console_backend/src/bin/fileio.rs b/console_backend/src/bin/fileio.rs index 87f4af2fc..af1680145 100644 --- a/console_backend/src/bin/fileio.rs +++ b/console_backend/src/bin/fileio.rs @@ -124,7 +124,7 @@ fn main() -> Result<()> { let res = (|| { let mut fileio = Fileio::new(link, sender); let files = fileio.readdir(path)?; - eprintln!("{:#?}", files); + files.iter().for_each(|f| println!("{}", f)); Ok(()) })(); done_tx.send(true).unwrap();