-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
newline_style = "Unix" | ||
tab_spaces = 2 | ||
use_field_init_shorthand = true | ||
use_try_shorthand = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,68 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
use std::fs; | ||
|
||
pub fn get_file_metadata(path: &str) -> Result<fs::Metadata, std::io::Error> { | ||
fs::metadata(path) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern fn file_creation_date(path: *const i8) -> u64 { | ||
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; | ||
Check failure on line 9 in src/lib.rs
|
||
let path = std::str::from_utf8(path).expect("Invalid UTF-8 string for path"); | ||
|
||
let metadata = get_file_metadata(path).expect("Failed to get file metadata"); | ||
let creation_time = metadata.created().expect("Failed to get file creation time"); | ||
|
||
creation_time.duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern fn file_modification_date(path: *const i8) -> u64 { | ||
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; | ||
Check failure on line 20 in src/lib.rs
|
||
let path = std::str::from_utf8(path).expect("Invalid UTF-8 string for path"); | ||
|
||
let metadata = get_file_metadata(path).expect("Failed to get file metadata"); | ||
let modification_time = metadata.modified().expect("Failed to get file modification time"); | ||
|
||
modification_time.duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern fn file_access_date(path: *const i8) -> u64 { | ||
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; | ||
Check failure on line 31 in src/lib.rs
|
||
let path = std::str::from_utf8(path).expect("Invalid UTF-8 string for path"); | ||
|
||
let metadata = get_file_metadata(path).expect("Failed to get file metadata"); | ||
let access_time = metadata.accessed().expect("Failed to get file access time"); | ||
|
||
access_time.duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern fn file_size(path: *const i8) -> u64 { | ||
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; | ||
Check failure on line 42 in src/lib.rs
|
||
let path = std::str::from_utf8(path).expect("Invalid UTF-8 string for path"); | ||
|
||
let metadata = get_file_metadata(path).expect("Failed to get file metadata"); | ||
metadata.len() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern fn file_exists(path: *const i8) -> bool { | ||
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; | ||
Check failure on line 51 in src/lib.rs
|
||
let path = std::str::from_utf8(path).expect("Invalid UTF-8 string for path"); | ||
|
||
let metadata = get_file_metadata(path); | ||
match metadata { | ||
Check failure on line 55 in src/lib.rs
|
||
Ok(_) => true, | ||
Err(_) => false | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern fn file_is_directory(path: *const i8) -> bool { | ||
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; | ||
Check failure on line 63 in src/lib.rs
|
||
let path = std::str::from_utf8(path).expect("Invalid UTF-8 string for path"); | ||
|
||
let metadata = get_file_metadata(path).expect("Failed to get file metadata"); | ||
metadata.is_dir() | ||
} |