diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index be65b31..e7cb43a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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' }} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 09a2665..2ea66bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; let path = match std::str::from_utf8(path) { Ok(v) => v, @@ -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 { let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; let path = match std::str::from_utf8(path) { Ok(v) => v, @@ -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 { let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; let path = match std::str::from_utf8(path) { Ok(v) => v, @@ -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 { let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; let path = match std::str::from_utf8(path) { Ok(v) => v, @@ -89,7 +98,7 @@ 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 { let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; let path = match std::str::from_utf8(path) { Ok(v) => v, @@ -97,12 +106,12 @@ pub extern fn file_exists(path: *const i8) -> bool { }; 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 { let path = unsafe { std::ffi::CStr::from_ptr(path).to_bytes() }; let path = match std::str::from_utf8(path) { Ok(v) => v, @@ -115,4 +124,4 @@ pub extern fn file_is_directory(path: *const i8) -> bool { }; metadata.is_dir() -} \ No newline at end of file +}