Skip to content

Commit

Permalink
modified if-else and fmt
Browse files Browse the repository at this point in the history
Signed-off-by: JeevaRamanathan <[email protected]>
  • Loading branch information
JeevaRamanathan committed May 7, 2024
1 parent a6e66ad commit 9d49c1a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions kclvm/runtime/src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{fs, io::ErrorKind};

use crate::*;
use glob::glob;
use std::path::Path;
use std::io::Write;
use std::path::Path;

#[no_mangle]
#[runtime_fn]
Expand Down Expand Up @@ -284,18 +284,19 @@ pub extern "C" fn kclvm_file_write(

if let Some(path) = get_call_arg_str(args, kwargs, 0, Some("filepath")) {
if let Some(content) = get_call_arg_str(args, kwargs, 1, Some("content")) {
if let Ok(mut file) = fs::File::create(&path) {
if let Err(e) = file.write_all(content.as_bytes()) {
panic!("Failed to write to '{}': {}", path, e);
match fs::File::create(&path) {
Ok(mut file) => {
if let Err(e) = file.write_all(content.as_bytes()) {
panic!("Failed to write to '{}': {}", path, e);
}
return ValueRef::none().into_raw(ctx);
}
return ValueRef::none().into_raw(ctx);
} else if let Err(e) = fs::File::create(&path) {
panic!("Failed to create file '{}': {}", path, e);
Err(e) => panic!("Failed to create file '{}': {}", path, e),
}
} else {
panic!("write() missing 'content' argument");
}
} else {
panic!("write() missing 'filepath' argument");
}
}
}

0 comments on commit 9d49c1a

Please sign in to comment.