forked from Rativel/BurritOS
filesys.rs : decompname & find_dir
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
use std::{fs::File, io::{Seek, SeekFrom, Read}};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Read, Seek, SeekFrom},
|
||||
};
|
||||
|
||||
use super::filesys;
|
||||
|
||||
pub const TRANSFER_SIZE: usize = 10;
|
||||
|
||||
/// copy the contents of the UNIX file "from" to the Nachos file "to"
|
||||
///
|
||||
///
|
||||
/// `panic!` when the file from doesn't exist
|
||||
///
|
||||
///
|
||||
/// ### parameters
|
||||
///
|
||||
/// - **from** file UNIX
|
||||
/// - **to** BurritOS file
|
||||
pub fn copy(from : &str, to : &str) {
|
||||
|
||||
pub fn copy(from: &str, to: &str) {
|
||||
let file_from_opt = File::options().read(true).open(from);
|
||||
let mut file_from : File;
|
||||
let mut file_from: File;
|
||||
match file_from_opt {
|
||||
Err(e) => {
|
||||
panic!("Copy: couldn't open Unix file {}", from);
|
||||
@@ -35,7 +39,9 @@ pub fn copy(from : &str, to : &str) {
|
||||
|
||||
let mut buffer = [0; TRANSFER_SIZE];
|
||||
loop {
|
||||
let amount_read = file_from.read(&mut buffer).expect("copy : couldn't read the UNIX file");
|
||||
let amount_read = file_from
|
||||
.read(&mut buffer)
|
||||
.expect("copy : couldn't read the UNIX file");
|
||||
open_file.write(&buffer[..amount_read]);
|
||||
|
||||
if amount_read != TRANSFER_SIZE {
|
||||
@@ -45,11 +51,13 @@ pub fn copy(from : &str, to : &str) {
|
||||
}
|
||||
|
||||
/// Print the contents of the Nachos file "name".
|
||||
///
|
||||
///
|
||||
/// `panic!` when the file name doewn't exist
|
||||
///
|
||||
///
|
||||
/// ### parameters
|
||||
///
|
||||
/// - **name** of the BurritOS file
|
||||
pub fn print(name : &str) {
|
||||
pub fn print(name: &str) {
|
||||
let open_file = filesys::open(name);
|
||||
|
||||
let mut buffer = [0; TRANSFER_SIZE];
|
||||
@@ -63,4 +71,4 @@ pub fn print(name : &str) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user