Tons of linter fixes (not all yet!)

This commit is contained in:
Bas Wiel, van de 2024-05-12 16:18:29 +02:00
parent b3b4f773c3
commit 5874f36491
10 changed files with 41 additions and 43 deletions

View File

@ -40,7 +40,7 @@ impl Analyzer {
_ => println!("Nothing found"),
}
}
if partitions.len() == 0 {
if partitions.is_empty() {
return None;
}

View File

@ -44,7 +44,7 @@ impl DiskBuilder {
filesystem,
partition: root_partition,
operating_system,
manifest: manifest,
manifest,
})
}
@ -126,7 +126,7 @@ impl DiskBuilder {
DirEntryType::Directory => entry.children_bytes(&self.filesystem.arena)?,
};
if bytes.len() == 0 {
if bytes.is_empty() {
return Ok(());
}
@ -134,10 +134,8 @@ impl DiskBuilder {
let addresses = &entry.allocated_clusters; // Use a reference
// Ensure the number of allocated clusters matches the number of chunks
if entry.entry_type == DirEntryType::Directory {
if entry.directory_name() == "." || entry.directory_name() == ".." {
return Ok(());
}
if entry.entry_type == DirEntryType::Directory && (entry.directory_name() == "." || entry.directory_name() == "..") {
return Ok(());
}
/*if addresses.len() != chunks.len() && entry.entry_type != DirEntryType::Directory {
println!(
@ -193,9 +191,9 @@ impl DiskBuilder {
// Calculate the base offset to figure out where the cluster should live on the disk
let mut sector_address = (cluster_address as usize
* self.filesystem.get_sectors_per_cluster() as usize
* self.filesystem.get_sectors_per_cluster()
+ self.filesystem.get_first_data_sector() as usize)
- 2 * self.filesystem.get_sectors_per_cluster() as usize;
- 2 * self.filesystem.get_sectors_per_cluster();
for chunk in bytes.chunks_exact(512) {
let mut chunk_array = [0u8; 512];
@ -246,7 +244,7 @@ impl DiskBuilder {
)?;
}
counter += 1;
sector_offset = sector_offset + self.filesystem.sectors_per_fat;
sector_offset += self.filesystem.sectors_per_fat;
}
Ok(())

View File

@ -156,7 +156,7 @@ impl Disk {
}
pub fn get_image_type(&self) -> &VhdDisktype {
&self.metadata.get_type()
self.metadata.get_type()
}
/// Read a sector-sized block from the cache

View File

@ -51,7 +51,7 @@ impl ZipDownloader {
// Check if the filename matches the provided name
if file.get_name() == name {
// If found, return a reference to the DownloadedFile
return Some(&file);
return Some(file);
}
}
// If the file is not found, return None

View File

@ -174,7 +174,7 @@ impl Fat {
Ok(Fat {
fat_type,
allocation_table: AllocationTable::new(
sector_count as u32 / sectors_per_cluster as u32,
sector_count / sectors_per_cluster as u32,
),
arena,
root_directory,
@ -387,11 +387,10 @@ impl Fat {
"Parent node not found",
));
}
} else {
self.arena
.get_node_mut(self.root_directory)
.map(|root| root.value.children.push(node_id));
}
} else
if let Some(root) = self.arena
.get_node_mut(self.root_directory) { root.value.children.push(node_id) }
Ok(())
}
@ -525,12 +524,12 @@ impl Fat {
/// Allocate a single free cluster for things like directory entries.
fn allocate_cluster(&mut self) -> Result<u32, std::io::Error> {
if let Some(free_cluster) = self.allocation_table.get_free_cluster() {
return Ok(free_cluster);
Ok(free_cluster)
} else {
return Err(std::io::Error::new(
Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"No free cluster available. File system is full.",
));
))
}
}

View File

@ -69,7 +69,8 @@ impl AllocationTable {
"Attempted to reserve an unavailable cluster.",
));
}
Ok(cluster.set_reserved())
cluster.set_reserved();
Ok(())
}
// Nothing lives at index yet, place a reserved cluster there.
else {
@ -132,10 +133,10 @@ impl AllocationTable {
if let Some(cluster) = self.clusters.get(&cluster_address) {
Ok(*cluster)
} else {
return Err(std::io::Error::new(
Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Fudgies!!",
));
))
}
}

View File

@ -87,6 +87,12 @@ pub struct Arena<T> {
nodes: Vec<Node<T>>,
}
impl Default for Arena<DirEntry> {
fn default() -> Self {
Self::new()
}
}
impl Arena<DirEntry> {
pub fn new() -> Self {
Arena { nodes: Vec::new() }
@ -242,7 +248,7 @@ impl DirEntry {
fn create_directory(
filename: &str,
create_timedate: Option<TimeDate>,
allocated_clusters: &Vec<u32>,
allocated_clusters: &[u32],
) -> Result<Self, std::io::Error> {
// Set of attributes appropriate to a directory
let attributes = Attributes::new(false, false, false, false, false, true, false);
@ -250,7 +256,7 @@ impl DirEntry {
let new_entry = match create_timedate {
None => DirEntry {
filename: FileName::new(filename)?,
attributes: attributes.clone(),
attributes,
create_timedate: TimeDate::now(),
file_size: 0,
entry_type: DirEntryType::Directory,
@ -260,7 +266,7 @@ impl DirEntry {
},
_ => DirEntry {
filename: FileName::new(filename)?,
attributes: attributes.clone(),
attributes,
create_timedate: create_timedate.unwrap(),
file_size: 0,
entry_type: DirEntryType::Directory,
@ -301,7 +307,7 @@ impl DirEntry {
/// when reading a directory from disk. DOES NOT WORK YET!! [TODO]
pub fn from_bytes(bytes: &[u8; 32]) -> Result<DirEntry, std::io::Error> {
let filename_bytes = &bytes[0..11];
let filename = FileName::from_bytes(&filename_bytes)?;
let filename = FileName::from_bytes(filename_bytes)?;
let mut datetime_bytes = [0u8; 4];
datetime_bytes[0..2].copy_from_slice(&bytes[2..4]);
datetime_bytes[2..4].copy_from_slice(&bytes[0..2]);
@ -386,7 +392,7 @@ impl DirEntry {
/// assert_eq!(bytes, [0x32, 0x04]); // Assuming the start cluster number is 1234
/// ```
pub fn start_cluster_as_bytes(&self) -> [u8; 2] {
if self.allocated_clusters.len() == 0 {
if self.allocated_clusters.is_empty() {
// Our parent is the root directory
return [0,0];
}
@ -418,8 +424,8 @@ impl DirEntry {
/// The start cluster is either 0, or the first entry in the allocated clusters vec.
pub fn get_start_cluster(&self) -> u32 {
if self.allocated_clusters.len() == 0 {
return 0;
if self.allocated_clusters.is_empty() {
0
} else {
self.allocated_clusters[0]
}
@ -465,15 +471,12 @@ impl DirEntry {
}
pub fn get_data(&self) -> &[u8] {
&self.data.as_slice()
self.data.as_slice()
}
pub fn is_directory(&self) -> bool {
match self.get_type() {
DirEntryType::Directory => true,
_ => false,
}
matches!(self.get_type(), DirEntryType::Directory)
}
pub fn children_bytes(&self, arena: &Arena<DirEntry>) -> Result<Vec<u8>, std::io::Error> {

View File

@ -202,8 +202,7 @@ impl TimeDate {
let second = if second % 2 == 1 { second - 1 } else { second };
// Validate year, month, day, hour, minute, and second
if year < 1980
|| year > 2107
if !(1980..=2107).contains(&year)
|| day > 31
|| month > 12
|| hour > 23

View File

@ -34,10 +34,10 @@ impl Application {
pub fn get_label(&self) -> String {
if self.label.is_some() {
return self.label.clone().unwrap();
self.label.clone().unwrap()
}
else {
return self.url.to_owned();
self.url.to_owned()
}
}
}

View File

@ -190,9 +190,7 @@ impl OperatingSystem {
/// Return the filename this OS uses for the COMMAND.COM equivalent system file.
pub fn get_commandcom(&self) -> String {
match self {
_ => "COMMAND.COM".to_string(),
}
"COMMAND.COM".to_string()
}
/// Return the default download URL for an operating system zipfile