Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 38 additions & 27 deletions console_backend/src/bin/fileio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (|| {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of awkward, but is nice for convenience. I guess we could change each of these closures to be actual functions, or maybe we could use try_block for these? Happy to go with whatever people think is most readable.

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()
}
Expand All @@ -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<dyn Write + Send> = 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<dyn Write + Send> = 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()
}
Expand All @@ -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)?;
files.iter().for_each(|f| println!("{}", f));
Ok(())
})();
done_tx.send(true).unwrap();
Result::Ok(())
res
})
.unwrap()
}
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion console_backend/src/fileio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions console_backend/src/log_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fn write_packet(packet: ConsoleLogPacket, f: &mut File) {
timestamp = packet.timestamp,
level = packet.level,
msg = packet.msg,
spaces = spaces,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing issues for me (I guess I need to update to 1.58.0?) but figured the rest of the arguments are specified, so this one should probably be too, so I fixed it for consistency. 🤷‍♂️

);
}

Expand Down