I need help about this code
async fn bajar_imagen(
url_imagen: Url,
nombre_fichero: &Path,
directorio_capitulo: &Path,
cliente: &reqwest::Client,
) -> Result<(), &'static str> {
dbg!(&url_imagen);
const MIN_SIZE_FILE: u64 = 1141;
match cliente.get(url_imagen).send().await {
Ok(mut doc1) => {
dbg!(&nombre_fichero);
match tokio::fs::File::create(&nombre_fichero).await {
Ok(mut file) => {
while let Some(chunk) = match doc1.chunk().await {
Ok(x) => x,
Err(e) => {
imprimir_rojo(
" Fallo al obtener datos de la imagen, borrar directorio",
);
println!("Error: {}", e);
borrar_directorio_y_panic(&directorio_capitulo).await;
panic!();
}
} {
match file.write_all(&chunk).await {
Ok(_) => (),
Err(e) => {
imprimir_rojo(
" Fallo al escribir en el fichero, borrar directorio",
);
println!("Error: {}", e);
borrar_directorio_y_panic(&directorio_capitulo).await;
panic!();
}
}
}
}
Err(e) => {
imprimir_rojo(" Error al crear fichero, borrar directorio");
println!("Error: {}", e);
borrar_directorio_y_panic(&directorio_capitulo).await;
panic!();
}
}
println!("Tamaño fichero creado: {}",Path::new(nombre_fichero).metadata().unwrap().len());
println!("Tamaño fichero creado segunda lectura: {}",Path::new(nombre_fichero).metadata().unwrap().len());
if Path::new(nombre_fichero).metadata().unwrap().len() <= MIN_SIZE_FILE {
Err("fichero_pequeño")
} else {
Ok(())
}
}
Err(e) => {
imprimir_rojo(" Error al bajar imagen mirar status, borrar directorio");
println!("Error: {}", e);
borrar_directorio_y_panic(&directorio_capitulo).await;
panic!();
}
}
}
I'm trying to get a image, the problem is that i check if the image is correct looking with the size of the write image
if it's very little i suposse that there is an error (<1141 bytes)
But the nfs is still writing the image (or i think that this is the problem) because sometimes
when i check two or three time the size of the file, the size is increasing
./scrape
http://www.mangatown.com/manga/danberu_nan_kiro_moteru/ Apr 22,2022
https://www.mangatown.com/manga/danberu_nan_kiro_moteru/c144/
Tamaño fichero creado: 0
Tamaño fichero creado segunda lectura: 16
Fichero muy pequeño, borrar directorio
Se ha borrado el directorio
i mount the nfs share with this mount:
sudo mount -o sync -t nfs 192.168.1.2:/Cyberdojo /mnt/Cyberdojo
(in the server options are subtree_check,insecure,crossmnt,sync)
I don't know why perhaps because i have and zfs, after the share of the nfs,
the file is created but i don't know how to solve and see if the write or the image is ok, or how to wait to the sync of the write that the filesystem is doing while i check the size of the file that i have writed