Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
zanderlewis committed Jan 28, 2025
1 parent 7d8bc56 commit 6ec62fc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/api/time.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::api::clock;
use crate::sys;

use alloc::{string::{String, ToString}, vec::Vec};
use alloc::{
string::{String, ToString},
vec::Vec,
};
use time::{Duration, OffsetDateTime, UtcOffset};

pub fn now() -> OffsetDateTime {
Expand Down
7 changes: 5 additions & 2 deletions src/sys/clk/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use core::convert::TryFrom;
use super::cmos::CMOS;

use crate::api::clock::DATE_TIME_LEN;
use crate::api::time::{format_primitive_time, parse_primitive_date_time};
use crate::api::fs::{FileIO, IO};
use crate::api::time::{format_primitive_time, parse_primitive_date_time};

use alloc::string::String;
use time::{Date, PrimitiveDateTime};
Expand Down Expand Up @@ -60,7 +60,10 @@ impl FileIO for RTC {
self.sync();
let month = time::Month::try_from(self.month).map_err(|_| ())?;
let date = Date::from_calendar_date(self.year.into(), month, self.day).map_err(|_| ())?;
let date_time = PrimitiveDateTime::new(date, time::Time::from_hms(self.hour, self.minute, self.second).map_err(|_| ())?);
let date_time = PrimitiveDateTime::new(
date,
time::Time::from_hms(self.hour, self.minute, self.second).map_err(|_| ())?,
);
let out = format_primitive_time(date_time);
buf.copy_from_slice(out.as_bytes());
Ok(out.len())
Expand Down
24 changes: 19 additions & 5 deletions src/sys/fs/hfs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use alloc::{
string::{String, ToString},
vec::Vec,
};
use spin::Mutex;
use alloc::{string::{String, ToString}, vec::Vec};

pub struct HiddenFile {
filename: String,
Expand Down Expand Up @@ -35,7 +38,10 @@ impl HiddenFS {

pub fn retrieve_file(&self, filename: &str) -> Option<Vec<u8>> {
let files = self.files.lock();
files.iter().find(|f| f.filename == filename).map(|f| f.data.clone())
files
.iter()
.find(|f| f.filename == filename)
.map(|f| f.data.clone())
}

pub fn delete_file(&self, filename: &str) -> bool {
Expand Down Expand Up @@ -85,7 +91,12 @@ impl HiddenFS {
if data.len() < 4 {
return; // Not enough data
}
let file_count = u32::from_le_bytes([data[cursor], data[cursor + 1], data[cursor + 2], data[cursor + 3]]) as usize;
let file_count = u32::from_le_bytes([
data[cursor],
data[cursor + 1],
data[cursor + 2],
data[cursor + 3],
]) as usize;
cursor += 4;

let mut files = self.files.lock();
Expand Down Expand Up @@ -151,7 +162,10 @@ mod tests {
fn test_store_retrieve() {
let fs = HiddenFS::new();
fs.store_file("test.txt", b"Hello, world!");
assert_eq!(fs.retrieve_file("test.txt"), Some(b"Hello, world!".to_vec()));
assert_eq!(
fs.retrieve_file("test.txt"),
Some(b"Hello, world!".to_vec())
);
}

#[test_case]
Expand Down Expand Up @@ -180,4 +194,4 @@ mod tests {
assert!(fs.file_exists("test.txt"));
assert!(!fs.file_exists("test2.txt"));
}
}
}
14 changes: 4 additions & 10 deletions src/usr/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ fn help_summary() -> Result<(), ExitCode> {

println!("{}Commands:{}", csi_color, csi_reset);

print_usage(
"copy <file> <file>",
"Copy file from source to destination",
);
print_usage("copy <file> <file>", "Copy file from source to destination");
print_usage(" - cp <file>", "Alias for copy");

print_usage("delete <file>", "Delete file or empty directory");
Expand All @@ -69,21 +66,18 @@ fn help_summary() -> Result<(), ExitCode> {
print_usage("list <dir>", "List entries in directory");
print_usage(" - ls <dir>", "Alias for list");

print_usage(
"move <file> <file>",
"Move file from source to destination",
);
print_usage("move <file> <file>", "Move file from source to destination");
print_usage(" - mv <file>", "Alias for move");

print_usage("print <str>", "Print string to screen");
print_usage(" - echo <str>", "Alias for print");

print_usage("quit", "Quit the console");

print_usage( "read <file>", "Read file to screen");
print_usage("read <file>", "Read file to screen");
print_usage(" - cat <file>", "Alias for read");

print_usage( "write <file>", "Write file or directory");
print_usage("write <file>", "Write file or directory");

println!();

Expand Down

0 comments on commit 6ec62fc

Please sign in to comment.