pub fn core_touch(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 1 {
            print_error(chunk, i, "touch requires one argument");
            return 0;
        }

        let path_rr = self.stack.pop().unwrap();
        let path_rrb = path_rr.borrow();
        let path_pre = path_rrb.to_string();
        let path_opt = to_string_2(&path_pre);

        match path_opt {
            Some(path_str) => {
                let path = Path::new(&path_str);
                if !path.exists() {
                    let res = fs::write(&path_str, "");
                    match res {
                        Ok(_) => {},
                        Err(e) => {
                            let err_str = format!(
                                "unable to write file: {}",
                                e.to_string()
                            );
                            print_error(chunk, i, &err_str);
                            return 0;
                        }
                    }
                } else {
                    let times_res = get_file_times(&path_str);
                    match times_res {
                        Ok((accessed, _)) => {
                            let mtime = SystemTime::now()
                                .duration_since(SystemTime::UNIX_EPOCH)
                                .unwrap()
                                .as_secs();
                            let sft_res =
                                set_file_times(&path_str, accessed, mtime as i64);
                            match sft_res {
                                Ok(_) => {}
                                Err(e) => {
                                    let err_str = format!(
                                        "unable to write file: {}",
                                        e.to_string()
                                    );
                                    print_error(chunk, i, &err_str);
                                    return 0;
                                }
                            }
                        }
                        Err(e) => {
                            let err_str = format!(
                                "unable to write file: {}",
                                e.to_string()
                            );
                            print_error(chunk, i, &err_str);
                            return 0;
                        }
                    }
                }
            }
            _ => {
                print_error(chunk, i, "touch argument must be a string");
                return 0;
            }
        }
        return 1;
    }
/// Takes a value that can be stringified as its single argument.
/// Creates the file if it doesn't exist, and updates its
/// modification timestamp to the current time if it does exist,
/// similarly to touch(1).
Takes a value that can be stringified as its single argument.
Creates the file if it doesn't exist, and updates its
modification timestamp to the current time if it does exist,
similarly to touch(1).
Takes a value that can be stringified as its single argument . Creates the file if it doesn ' t exist and updates its modification timestamp to the current time if it does exist similarly to touch ( 1 ) .
pub fn core_touch(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 1 {
            print_error(chunk, i, "touch requires one argument");
            return 0;
        }
        let path_rr = self.stack.pop().unwrap();
        let path_rrb = path_rr.borrow();
        let path_pre = path_rrb.to_string();
        let path_opt = to_string_2(&path_pre);
        match path_opt {
            Some(path_str) => {
                let path = Path::new(&path_str);
                if !path.exists() {
                    let res = fs::write(&path_str, "");
                    match res {
                        Ok(_) => {},
                        Err(e) => {
                            let err_str = format!(
                                "unable to write file: {}",
                                e.to_string()
                            );
                            print_error(chunk, i, &err_str);
                            return 0;
                        }
                    }
                } else {
                    let times_res = get_file_times(&path_str);
                    match times_res {
                        Ok((accessed, _)) => {
                            let mtime = SystemTime::now()
                                .duration_since(SystemTime::UNIX_EPOCH)
                                .unwrap()
                                .as_secs();
                            let sft_res =
                                set_file_times(&path_str, accessed, mtime as i64);
                            match sft_res {
                                Ok(_) => {}
                                Err(e) => {
                                    let err_str = format!(
                                        "unable to write file: {}",
                                        e.to_string()
                                    );
                                    print_error(chunk, i, &err_str);
                                    return 0;
                                }
                            }
                        }
                        Err(e) => {
                            let err_str = format!(
                                "unable to write file: {}",
                                e.to_string()
                            );
                            print_error(chunk, i, &err_str);
                            return 0;
                        }
                    }
                }
            }
            _ => {
                print_error(chunk, i, "touch argument must be a string");
                return 0;
            }
        }
        return 1;
    }
pub fn core_touch ( & mut self , chunk : & Chunk , i : usize ) -> i32 { if self . stack . len ( ) < 1 { print_error ( chunk , i , " " ) ; return 0 ; } let path_rr = self . stack . pop ( ) . unwrap ( ) ; let path_rrb = path_rr . borrow ( ) ; let path_pre = path_rrb . to_string ( ) ; let path_opt = to_string_2 ( & path_pre ) ; match path_opt { Some ( path_str ) => { let path = Path :: new ( & path_str ) ; if ! path . exists ( ) { let res = fs :: write ( & path_str , " " ) ; match res { Ok ( _ ) => { } , Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } else { let times_res = get_file_times ( & path_str ) ; match times_res { Ok ( ( accessed , _ ) ) => { let mtime = SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) . unwrap ( ) . as_secs ( ) ; let sft_res = set_file_times ( & path_str , accessed , mtime as i64 ) ; match sft_res { Ok ( _ ) => { } Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } return 1 ; }
Takes a value that can be stringified as its single argument.
Takes a value that can be stringified as its single argument .
&mut self
chunk
&Chunk
i
usize