Skip to content

Commit 687a4ca

Browse files
fix error two
1 parent ef33ae0 commit 687a4ca

File tree

5 files changed

+31
-60
lines changed

5 files changed

+31
-60
lines changed

command/src/commands/command.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -302,25 +302,18 @@ pub fn cat(file: &str) -> Result<(usize,String),Error>{
302302
return Ok(empty_file());
303303
}
304304
let mut buffer = String::new();
305-
let file_size = max_size_file(file);
306-
match file_size{
307-
Ok(_) =>{
308-
let f = fs::File::open(Path::new(file));
309-
let _ = f.unwrap().read_to_string(&mut buffer);
310-
},
311-
Err(err) =>{
312-
return Ok((ERR_CODE,err.to_string()));
313-
}
314-
}
305+
let f = fs::File::open(Path::new(file));
306+
let _ = f.unwrap().read_to_string(&mut buffer);
307+
315308
Ok((STATUE_CODE,buffer))
316309
}
317310

318311

319312
use crate::commands::download::{download_package, find_package};
320313
use crate::priority::get_priority;
321-
use crate::set::set::{file_create_time, max_size_file};
314+
use crate::set::set::file_create_time;
322315
use crate::run::run;
323-
use crate::state_code::{empty_dir, empty_file, missing_pattern, ERR_CODE, STATUE_CODE};
316+
use crate::state_code::{empty_dir, empty_file, missing_pattern, STATUE_CODE};
324317
use super::download::update;
325318
use crate::root::SessionContext;
326319

@@ -551,7 +544,6 @@ pub fn priority_run(command:Vec<String>,session_context: &mut SessionContext){
551544
}
552545

553546
save_command.sort_by_key(|c| -(get_priority(&c[0]).as_number() as i32));
554-
println!("{:?}",save_command);
555547

556548
for c in save_command{
557549
run(c, session_context)

command/src/priority/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ pub enum CommandPriority {
44
Low,
55
Medium,
66
High,
7+
Unknow,
78
}
89

910
impl CommandPriority{
1011
pub fn as_number(&self) -> u8 {
1112
match *self {
12-
CommandPriority::Low => 0,
13-
CommandPriority::Medium => 1,
14-
CommandPriority::High => 2,
13+
CommandPriority::Unknow => 0,
14+
CommandPriority::Low => 1,
15+
CommandPriority::Medium => 2,
16+
CommandPriority::High => 3,
1517
}
1618
}
1719
}
@@ -28,6 +30,6 @@ pub fn get_priority(command: &str) -> CommandPriority{
2830
"pwd"|"ls"|"mkdir"|"touch"|"whoami"|"exit" => CommandPriority::Low,
2931
"cd"|"rm"|"cat"|"python"|"html"|"web"|"rn"|"mv"|"tar"|"grep"|"pd"|"root"|"apt"|"history" => CommandPriority::Medium,
3032
"sleep"|"kill"|"ps"=> CommandPriority::High,
31-
_ => CommandPriority::Low
33+
_ => CommandPriority::Unknow
3234
}
3335
}

command/src/process/process.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ pub struct ProcessManager {
5353
pub processes: Vec<Process>,
5454
}
5555

56+
#[allow(dropping_references)]
57+
impl Drop for ProcessManager{
58+
fn drop(&mut self) {
59+
for i in self.processes.iter_mut(){
60+
drop(&i);
61+
i.stop()
62+
}
63+
}
64+
}
65+
5666
impl ProcessManager {
5767
pub fn new() -> Self {
5868
ProcessManager {

command/src/process/thread.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ pub struct ThreadControlBlock {
5656
}
5757

5858

59+
#[allow(dropping_references)]
60+
impl Drop for ThreadControlBlock{
61+
fn drop(&mut self) {
62+
for i in self.threads.iter_mut(){
63+
drop(&i);
64+
i.stop()
65+
}
66+
}
67+
}
68+
5969
impl ThreadControlBlock {
6070
pub fn new() -> ThreadControlBlock {
6171
ThreadControlBlock {

command/src/set/set.rs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -134,47 +134,4 @@ pub fn error_log(err: String){
134134
return;
135135
}
136136
// error.log -> $HOME/.Tiks/error.log -> [time]: [Error]
137-
}
138-
139-
140-
pub const MB:f64 = 1024.0*1024.0;
141-
142-
use std::fs::metadata;
143-
use std::io;
144-
145-
fn get_file_size(file:&str) -> f64{
146-
let mut size = 0;
147-
if let Ok(s) = metadata(file){
148-
size = s.len();
149-
}
150-
151-
size as f64
152-
}
153-
154-
type MB = f64;
155-
156-
fn byte_to_mb(size: f64) -> MB{
157-
let new_size = size/MB;
158-
new_size
159-
}
160-
161-
pub fn max_size_file(path: &str) -> Result<(),&'static str>{
162-
let size = get_file_size(path);
163-
let mb = byte_to_mb(size); // MB
164-
165-
if mb > 128_f64{
166-
loop {
167-
let mut choice = String::new();
168-
println!("This file is more than 256MB, Do you want to read? [y/n]");
169-
io::stdout().flush().unwrap();
170-
io::stdin().read_line(&mut choice).unwrap();
171-
if choice.as_str() == "y"{
172-
break;
173-
}else{
174-
return Err("Canel read");
175-
}
176-
}
177-
}
178-
179-
Ok(())
180137
}

0 commit comments

Comments
 (0)