From 0a94691685433b64c2a7acc2d11094a783297b00 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Tue, 28 Mar 2023 20:41:03 -0400 Subject: [PATCH] Small tweak in message passing --- src/creator/mod.rs | 7 ++----- tar/src/header.rs | 32 +++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/creator/mod.rs b/src/creator/mod.rs index 1595cb9..513dda8 100644 --- a/src/creator/mod.rs +++ b/src/creator/mod.rs @@ -5,7 +5,7 @@ use { borrow::BorrowMut, env, error::Error, - fs::{File, self}, + fs::{self, File}, io::{self, Write}, path::{Path, PathBuf}, sync::{ @@ -97,10 +97,7 @@ impl Creator { plist.lock().unwrap().borrow_mut().entries.push(item.entry); match writer.lock().unwrap().borrow_mut().write_all(&item.data) { Ok(_) => sender - .send(Message::MemberAdded(format!( - "{} added to archive", - path.display() - ))) + .send(Message::MemberAdded(format!("{}", path.display()))) .expect("couldn't send message"), Err(e) => sender .send(Message::Failure(format!("{e}"))) diff --git a/tar/src/header.rs b/tar/src/header.rs index fe37291..337cda4 100644 --- a/tar/src/header.rs +++ b/tar/src/header.rs @@ -5,8 +5,10 @@ use std::{ ffi::CStr, fmt::{self, Write}, fs::{self, Metadata}, + io, ops::Deref, - os::{linux::fs::MetadataExt, unix::fs::FileTypeExt}, path::PathBuf, io, + os::{linux::fs::MetadataExt, unix::fs::FileTypeExt}, + path::PathBuf, }; #[repr(u8)] @@ -225,11 +227,21 @@ impl Header { let path = PathBuf::from(&filename); let name = match path.file_name().and_then(|n| n.to_str()) { Some(n) => n.to_string(), - None => return Err(Error::Io(io::Error::new(io::ErrorKind::Other, "Cannot get file name"))), + None => { + return Err(Error::Io(io::Error::new( + io::ErrorKind::Other, + "Cannot get file name", + ))) + } }; let dir = match path.parent() { Some(d) => d, - None => return Err(Error::Io(io::Error::new(io::ErrorKind::Other, "Cannot get path prefix"))), + None => { + return Err(Error::Io(io::Error::new( + io::ErrorKind::Other, + "Cannot get path prefix", + ))) + } }; (name, Some(format!("{}", dir.display()))) }; @@ -288,11 +300,21 @@ impl Header { let path = PathBuf::from(&filename); let name = match path.file_name().and_then(|n| n.to_str()) { Some(n) => n.to_string(), - None => return Err(Error::Io(io::Error::new(io::ErrorKind::Other, "Cannot get file name"))), + None => { + return Err(Error::Io(io::Error::new( + io::ErrorKind::Other, + "Cannot get file name", + ))) + } }; let dir = match path.parent() { Some(d) => d, - None => return Err(Error::Io(io::Error::new(io::ErrorKind::Other, "Cannot get path prefix"))), + None => { + return Err(Error::Io(io::Error::new( + io::ErrorKind::Other, + "Cannot get path prefix", + ))) + } }; (name, Some(format!("{}", dir.display()))) };