mirror of
https://git.proxmox.com/git/vma-to-pbs
synced 2025-08-06 17:40:42 +00:00
improve error message for unexpected end of VMA file
When a VMA file ends unexpectedly while reading the header, change the error message from "failed to fill whole buffer" to "Unexpected end of VMA file" for more clarity. Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
This commit is contained in:
parent
e70313bd4c
commit
65cca800bf
13
src/vma.rs
13
src/vma.rs
@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::io;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::str;
|
use std::str;
|
||||||
@ -126,7 +127,13 @@ impl<T: Read> VmaReader<T> {
|
|||||||
|
|
||||||
fn read_header(vma_file: &mut T) -> Result<VmaHeader, Error> {
|
fn read_header(vma_file: &mut T) -> Result<VmaHeader, Error> {
|
||||||
let mut buffer = vec![0; VMA_HEADER_SIZE_NO_BLOB_BUFFER];
|
let mut buffer = vec![0; VMA_HEADER_SIZE_NO_BLOB_BUFFER];
|
||||||
vma_file.read_exact(&mut buffer)?;
|
vma_file.read_exact(&mut buffer).map_err(|e| {
|
||||||
|
if e.kind() == io::ErrorKind::UnexpectedEof {
|
||||||
|
io::Error::new(io::ErrorKind::UnexpectedEof, "Unexpected end of VMA file")
|
||||||
|
} else {
|
||||||
|
e
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
let bincode_options = bincode::DefaultOptions::new()
|
let bincode_options = bincode::DefaultOptions::new()
|
||||||
.with_fixint_encoding()
|
.with_fixint_encoding()
|
||||||
@ -298,9 +305,9 @@ impl<T: Read> VmaReader<T> {
|
|||||||
loop {
|
loop {
|
||||||
match self.restore_extent(&callback) {
|
match self.restore_extent(&callback) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(e) => match e.downcast_ref::<std::io::Error>() {
|
Err(e) => match e.downcast_ref::<io::Error>() {
|
||||||
Some(ioerr) => {
|
Some(ioerr) => {
|
||||||
if ioerr.kind() == std::io::ErrorKind::UnexpectedEof {
|
if ioerr.kind() == io::ErrorKind::UnexpectedEof {
|
||||||
break; // Break out of the loop since the end of the file was reached.
|
break; // Break out of the loop since the end of the file was reached.
|
||||||
} else {
|
} else {
|
||||||
return Err(format_err!(e)).context("Failed to read VMA file");
|
return Err(format_err!(e)).context("Failed to read VMA file");
|
||||||
|
Loading…
Reference in New Issue
Block a user