Skip to content

Commit

Permalink
fix: layout and rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Nov 22, 2023
1 parent 9082bc2 commit 5e51147
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
4 changes: 4 additions & 0 deletions rustfmt.toml
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
69 changes: 67 additions & 2 deletions src/lib.rs
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

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 9 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 9 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

this public function might dereference a raw pointer but is not marked `unsafe`
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

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 20 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 20 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

this public function might dereference a raw pointer but is not marked `unsafe`
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

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 31 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 31 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

this public function might dereference a raw pointer but is not marked `unsafe`
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

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 42 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 42 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

this public function might dereference a raw pointer but is not marked `unsafe`
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

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 51 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 51 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

this public function might dereference a raw pointer but is not marked `unsafe`
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

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

redundant pattern matching, consider using `is_ok()`

Check failure on line 55 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

redundant pattern matching, consider using `is_ok()`

Check failure on line 55 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

redundant pattern matching, consider using `is_ok()`
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

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 63 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

this public function might dereference a raw pointer but is not marked `unsafe`

Check failure on line 63 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

this public function might dereference a raw pointer but is not marked `unsafe`
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()
}

0 comments on commit 5e51147

Please sign in to comment.