Skip to content

Commit

Permalink
fix: fmt, clippy, and lib upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Nov 22, 2023
1 parent 3acd24c commit 76ba4c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ jobs:
- name: Build
run: cargo build --release

- name: Package
if: matrix.platform != 'windows-latest'
run: chmod +x ./package.sh && ./package.sh
env:
LIB_FILE: ${{ matrix.platform != 'windows-latest' && 'lib' || '' }}file_metadata${{ matrix.platform == 'windows-latest' && '.dll' || matrix.platform == 'macos-latest' && '.dylib' || '.so' }}
# - name: Package
# if: matrix.platform != 'windows-latest'
# run: chmod +x ./package.sh && ./package.sh
# env:
# LIB_FILE: ${{ matrix.platform != 'windows-latest' && 'lib' || '' }}file_metadata${{ matrix.platform == 'windows-latest' && '.dll' || matrix.platform == 'macos-latest' && '.dylib' || '.so' }}

- name: Package
if: matrix.platform == 'windows-latest'
run: ./package.ps1
env:
LIB_FILE: ${{ matrix.platform != 'windows-latest' && 'lib' || '' }}file_metadata${{ matrix.platform == 'windows-latest' && '.dll' || matrix.platform == 'macos-latest' && '.dylib' || '.so' }}
# - name: Package
# if: matrix.platform == 'windows-latest'
# run: ./package.ps1
# env:
# LIB_FILE: ${{ matrix.platform != 'windows-latest' && 'lib' || '' }}file_metadata${{ matrix.platform == 'windows-latest' && '.dll' || matrix.platform == 'macos-latest' && '.dylib' || '.so' }}

- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: lib-${{ matrix.platform }}
# Find exec based on platform
path: FileMetadata.*
path: ${{ matrix.platform != 'windows-latest' && 'lib' || '' }}file_metadata${{ matrix.platform == 'windows-latest' && '.dll' || matrix.platform == 'macos-latest' && '.dylib' || '.so' }}

31 changes: 20 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn log_and_return(e: impl std::fmt::Display) -> f64 {
}

#[no_mangle]
pub extern fn file_creation_date(path: *const i8) -> f64 {
pub unsafe extern "C" fn file_creation_date(path: *const i8) -> f64 {

Check failure on line 13 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 13 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 13 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

unsafe function's docs miss `# Safety` section
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() };
let path = match std::str::from_utf8(path) {
Ok(v) => v,
Expand All @@ -27,11 +27,14 @@ pub extern fn file_creation_date(path: *const i8) -> f64 {
Err(e) => return log_and_return(e),
};

creation_time.duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs() as f64
creation_time
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as f64
}

#[no_mangle]
pub extern fn file_modification_date(path: *const i8) -> f64 {
pub unsafe extern "C" fn file_modification_date(path: *const i8) -> f64 {

Check failure on line 37 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 37 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 37 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

unsafe function's docs miss `# Safety` section
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() };
let path = match std::str::from_utf8(path) {
Ok(v) => v,
Expand All @@ -48,11 +51,14 @@ pub extern fn file_modification_date(path: *const i8) -> f64 {
Err(e) => return log_and_return(e),
};

modification_time.duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs() as f64
modification_time
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as f64
}

#[no_mangle]
pub extern fn file_access_date(path: *const i8) -> f64 {
pub unsafe extern "C" fn file_access_date(path: *const i8) -> f64 {

Check failure on line 61 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 61 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 61 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

unsafe function's docs miss `# Safety` section
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() };
let path = match std::str::from_utf8(path) {
Ok(v) => v,
Expand All @@ -69,11 +75,14 @@ pub extern fn file_access_date(path: *const i8) -> f64 {
Err(e) => return log_and_return(e),
};

access_time.duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs() as f64
access_time
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as f64
}

#[no_mangle]
pub extern fn file_size(path: *const i8) -> f64 {
pub unsafe extern "C" fn file_size(path: *const i8) -> f64 {

Check failure on line 85 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 85 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 85 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

unsafe function's docs miss `# Safety` section
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() };
let path = match std::str::from_utf8(path) {
Ok(v) => v,
Expand All @@ -89,20 +98,20 @@ pub extern fn file_size(path: *const i8) -> f64 {
}

#[no_mangle]
pub extern fn file_exists(path: *const i8) -> bool {
pub unsafe extern "C" fn file_exists(path: *const i8) -> bool {

Check failure on line 101 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 101 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 101 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

unsafe function's docs miss `# Safety` section
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() };
let path = match std::str::from_utf8(path) {
Ok(v) => v,
Err(_) => return false,
};

let metadata = get_file_metadata(path);

metadata.is_ok()
}

#[no_mangle]
pub extern fn file_is_directory(path: *const i8) -> bool {
pub unsafe extern "C" fn file_is_directory(path: *const i8) -> bool {

Check failure on line 114 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (windows-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 114 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

unsafe function's docs miss `# Safety` section

Check failure on line 114 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

unsafe function's docs miss `# Safety` section
let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() };
let path = match std::str::from_utf8(path) {
Ok(v) => v,
Expand All @@ -115,4 +124,4 @@ pub extern fn file_is_directory(path: *const i8) -> bool {
};

metadata.is_dir()
}
}

0 comments on commit 76ba4c9

Please sign in to comment.