From be1d3841802d80ed4a1fdcaa01ce9110984ef2c0 Mon Sep 17 00:00:00 2001 From: Osei Fortune Date: Mon, 7 Mar 2022 13:01:20 -0400 Subject: [PATCH] chore: clean up --- .../src/android/fs/a_sync.rs | 30 ++++++++----------- .../src/android/fs/async_callback.rs | 2 +- .../src/android/fs/file_dir.rs | 10 +++---- .../src/android/fs/file_dirent.rs | 10 +++---- .../src/android/fs/file_stat.rs | 6 ++-- .../src/android/fs/fs_watch.rs | 6 ++-- .../src/android/fs/sync.rs | 10 +++---- .../nativescript_common/src/android/mod.rs | 8 ++--- .../src/android/prelude.rs | 10 +++---- .../src/common/fs/copy_file.rs | 8 ++--- .../nativescript_common/src/common/fs/sync.rs | 4 +-- 11 files changed, 48 insertions(+), 56 deletions(-) diff --git a/packages/ui-mobile-base/nativescript_common/src/android/fs/a_sync.rs b/packages/ui-mobile-base/nativescript_common/src/android/fs/a_sync.rs index 53d4ff211..854a0f872 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/fs/a_sync.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/fs/a_sync.rs @@ -1,23 +1,17 @@ -use std::ffi::{c_void, CString}; use std::path::PathBuf; -use std::ptr::NonNull; use std::sync::Arc; -use jni::objects::{ - AutoPrimitiveArray, JByteBuffer, JClass, JObject, JString, JValue, ReleaseMode, -}; -use jni::sys::{jboolean, jbyteArray, jint, jlong, jobject, jobjectArray, JNI_TRUE}; +use jni::objects::{JByteBuffer, JClass, JObject, JString, JValue, ReleaseMode}; +use jni::sys::{jboolean, jbyteArray, jint, jlong, jobjectArray, JNI_TRUE}; use jni::JNIEnv; -use libc::{c_char, c_int, c_long, c_uint, c_ushort}; -use log::log; -use parking_lot::Mutex; +use libc::{c_int, c_uint, c_ushort}; use crate::android::prelude::*; -use crate::android::{FILE_SYSTEM_CLASS, JVM, JVM_CLASS_CACHE}; +use crate::android::{FILE_SYSTEM_CLASS, JVM}; use crate::common::fs; pub use crate::common::fs::a_sync::FileWatchEvent; pub use crate::common::fs::a_sync::WatchEvent; -use crate::common::fs::a_sync::{runtime, AsyncClosure, OnErrorCallback, OnSuccessCallback}; +use crate::common::fs::a_sync::{runtime, AsyncClosure}; use crate::common::fs::file_dir::FileDir; use crate::common::fs::file_stat::FileStat; use crate::common::{ByteBuf, ByteBufMut}; @@ -915,7 +909,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileSystem_nativ _: JNIEnv, _: JClass, path: JString, - encoding: JString, + _encoding: JString, callback: jlong, ) { let callback = callback as *const AsyncCallback; @@ -943,7 +937,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileSystem_nativ _: JNIEnv, _: JClass, path: JString, - encoding: JString, + _encoding: JString, callback: jlong, ) { let callback = callback as *const AsyncCallback; @@ -1529,7 +1523,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileSystem_nativ let encoding = get_str(encoding, ""); let on_success = AsyncCallback::clone_from_ptr(callback); - let callback = AsyncClosure::<(), std::io::Error>::new(Box::new(move |success, error| { + let callback = AsyncClosure::<(), std::io::Error>::new(Box::new(move |_success, error| { if error.is_some() { on_success.on_error(jni::objects::JValue::Object( error_to_jstring(error.unwrap()).as_obj(), @@ -1566,7 +1560,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileSystem_nativ ) }; match fs::sync::write_file_with_bytes(fd, bytes) { - Ok(wrote) => { + Ok(_) => { // force drop of array to enable jni usage drop(data); callback.on_success(jni::objects::JValue::Object(jni::objects::JObject::null())) @@ -1600,7 +1594,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileSystem_nativ .get_direct_buffer_address(JByteBuffer::from(data.as_obj())) .unwrap(); match fs::sync::write_file_with_bytes(fd, bytes) { - Ok(wrote) => { + Ok(_) => { callback.on_success(jni::objects::JValue::Object(jni::objects::JObject::null())) } Err(error) => callback.on_error(jni::objects::JValue::Object( @@ -1627,8 +1621,8 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileSystem_nativ let encoding = get_str(encoding, ""); let on_success = AsyncCallback::clone_from_ptr(callback); - let callback = AsyncClosure::<(), std::io::Error>::new(Box::new(move |success, error| { - if error.is_some() { + let callback = AsyncClosure::<(), std::io::Error>::new(Box::new(move |_, error| { + if let Some(error) = error { on_success.on_error(jni::objects::JValue::Object( error_to_jstring(error.unwrap()).as_obj(), )) diff --git a/packages/ui-mobile-base/nativescript_common/src/android/fs/async_callback.rs b/packages/ui-mobile-base/nativescript_common/src/android/fs/async_callback.rs index da78520e4..7703f5561 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/fs/async_callback.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/fs/async_callback.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use jni::objects::{JClass, JObject, JValue}; +use jni::objects::{JClass, JObject}; use jni::sys::jlong; use jni::JNIEnv; diff --git a/packages/ui-mobile-base/nativescript_common/src/android/fs/file_dir.rs b/packages/ui-mobile-base/nativescript_common/src/android/fs/file_dir.rs index fded8872d..e686f14f6 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/fs/file_dir.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/fs/file_dir.rs @@ -25,7 +25,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeCl ) { let dir: *mut FileDir = file_dir as _; if !dir.is_null() { - let mut dir = unsafe { Box::from_raw(dir) }; + let dir = unsafe { Box::from_raw(dir) }; let result = dir.close(); if let Err(error) = result { let _ = env.throw(error.to_string()); @@ -44,7 +44,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeCl let on_success = AsyncCallback::clone_from_ptr(callback); let dir: *mut FileDir = file_dir as _; if !dir.is_null() { - let mut dir = unsafe { Box::from_raw(dir) }; + let dir = unsafe { Box::from_raw(dir) }; dir.close_async(Box::new(move |error| { if let Some(error) = error { on_success.on_error(jni::objects::JValue::Object( @@ -65,7 +65,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativePa ) -> jobject { let dir: *mut FileDir = file_dir as _; if !dir.is_null() { - let mut dir = unsafe { Box::from_raw(dir) }; + let dir = unsafe { Box::from_raw(dir) }; return env.new_string(dir.path()).unwrap().into_inner(); } JObject::null().into_inner() @@ -91,7 +91,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeRe ) -> jobject { let dir: *mut FileDir = file_dir as _; if !dir.is_null() { - let mut dir = unsafe { Box::from_raw(dir) }; + let dir = unsafe { Box::from_raw(dir) }; match dir.read() { Ok(dirent) => { return build_dirent(&env, dirent).into_inner(); @@ -115,7 +115,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileDir_nativeRe let on_success = AsyncCallback::clone_from_ptr(callback); let dir: *mut FileDir = file_dir as _; if !dir.is_null() { - let mut dir = unsafe { Box::from_raw(dir) }; + let dir = unsafe { Box::from_raw(dir) }; dir.read_async(Box::new(move |dirent, error| { if error.is_some() { on_success.on_error(jni::objects::JValue::Object( diff --git a/packages/ui-mobile-base/nativescript_common/src/android/fs/file_dirent.rs b/packages/ui-mobile-base/nativescript_common/src/android/fs/file_dirent.rs index 18d781585..7879677df 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/fs/file_dirent.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/fs/file_dirent.rs @@ -1,15 +1,15 @@ use std::ffi::OsString; use std::sync::Arc; -use jni::objects::{JClass, JObject, JValue}; +use jni::objects::{JClass, JObject}; use jni::sys::{jboolean, jlong, jobjectArray, JNI_FALSE}; use jni::{sys::jobject, JNIEnv}; use crate::android::prelude::*; -use crate::android::{FILE_DIRENT_CLASS, OBJECT_CLASS, STRING_CLASS}; +use crate::android::{FILE_DIRENT_CLASS, OBJECT_CLASS}; use crate::common::fs::file_dirent::FileDirent; -use super::a_sync::AsyncCallback; + pub(crate) fn build_dirent<'a>(env: &JNIEnv<'a>, dirent: FileDirent) -> JObject<'a> { let clazz = find_class(FILE_DIRENT_CLASS).unwrap(); @@ -22,7 +22,7 @@ pub(crate) fn build_dirents(env: &JNIEnv, dirent: Vec) -> jobjectArr let mut dirent = dirent; let object_clazz = find_class(OBJECT_CLASS).unwrap(); let clazz = find_class(FILE_DIRENT_CLASS).unwrap(); - let mut object_array = env + let object_array = env .new_object_array( dirent.len().try_into().unwrap(), object_clazz, @@ -45,7 +45,7 @@ pub(crate) fn build_dirents(env: &JNIEnv, dirent: Vec) -> jobjectArr pub(crate) fn build_dirents_paths(env: &JNIEnv, dirent: Vec) -> jobjectArray { let mut dirent = dirent; let clazz = find_class(OBJECT_CLASS).unwrap(); - let mut object_array = env + let object_array = env .new_object_array(dirent.len().try_into().unwrap(), clazz, JObject::null()) .unwrap(); diff --git a/packages/ui-mobile-base/nativescript_common/src/android/fs/file_stat.rs b/packages/ui-mobile-base/nativescript_common/src/android/fs/file_stat.rs index 8264d13db..197d4c88a 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/fs/file_stat.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/fs/file_stat.rs @@ -1,9 +1,9 @@ use std::ptr::NonNull; -use jni::objects::{JObject, JValue}; -use jni::sys::jobject; +use jni::objects::{JObject}; + use jni::JNIEnv; -use libc::stat; + use crate::android::prelude::*; use crate::android::FILE_STAT_CLASS; diff --git a/packages/ui-mobile-base/nativescript_common/src/android/fs/fs_watch.rs b/packages/ui-mobile-base/nativescript_common/src/android/fs/fs_watch.rs index 183636a18..a914ae3db 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/fs/fs_watch.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/fs/fs_watch.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::ffi::{CStr, CString}; +use std::ffi::{CStr}; use std::os::raw::c_char; use std::ptr::NonNull; use std::sync::Arc; @@ -148,7 +148,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FsWatcher_native #[no_mangle] pub extern "system" fn Java_org_nativescript_widgets_filesystem_FsWatcher_nativeRef( - env: JNIEnv, + _env: JNIEnv, _: JClass, filename: JString, callback: jlong, @@ -198,7 +198,7 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_WatcherEvent_nat let callback = AsyncCallback::clone_from_ptr(callback); let on_close = AsyncCallback::clone_from_ptr(on_close); - let mut map = watcher_callback_map().lock(); + let map = watcher_callback_map().lock(); if let Some(item) = map.get(&callback).map(|c| Arc::clone(&c.inner)) { let close_callback = AsyncClosure::<(), std::io::Error>::new(Box::new(move |_, error| { if let Some(error) = error { diff --git a/packages/ui-mobile-base/nativescript_common/src/android/fs/sync.rs b/packages/ui-mobile-base/nativescript_common/src/android/fs/sync.rs index a7f322058..4d4895ca3 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/fs/sync.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/fs/sync.rs @@ -6,12 +6,12 @@ use libc::{c_int, c_uint, c_ushort}; use crate::android::prelude::*; use crate::android::FILE_SYSTEM_CLASS; use crate::common::fs; -use crate::common::fs::file_stat::FileStat; + use crate::common::fs::prelude::handle_meta; use crate::common::{ByteBuf, ByteBufMut}; use super::file_dir::build_dir; -use super::file_dirent::{build_dirent, build_dirents, build_dirents_paths}; +use super::file_dirent::{build_dirents, build_dirents_paths}; use super::file_stat::build_stat; #[no_mangle] @@ -172,10 +172,10 @@ pub extern "system" fn Java_org_nativescript_widgets_filesystem_FileSystem_nativ _: JClass, src: JString, dest: JString, - flags: jint, + _flags: jint, ) { - let src = get_str(src, ""); - let dest = get_str(dest, ""); + let _src = get_str(src, ""); + let _dest = get_str(dest, ""); todo!() } diff --git a/packages/ui-mobile-base/nativescript_common/src/android/mod.rs b/packages/ui-mobile-base/nativescript_common/src/android/mod.rs index 77050b261..fdd5da32d 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/mod.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/mod.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use std::ffi::c_void; -use std::os::unix::fs::MetadataExt; -use jni::objects::{GlobalRef, JByteBuffer, JClass, JObject, JString, JValue, ReleaseMode}; -use jni::sys::{jbyteArray, jint, jlong, jobject}; -use jni::JNIEnv; + +use jni::objects::{GlobalRef, JValue}; +use jni::sys::{jint}; + use jni::JavaVM; use once_cell::sync::OnceCell; diff --git a/packages/ui-mobile-base/nativescript_common/src/android/prelude.rs b/packages/ui-mobile-base/nativescript_common/src/android/prelude.rs index 75c338f74..49df5ebc2 100644 --- a/packages/ui-mobile-base/nativescript_common/src/android/prelude.rs +++ b/packages/ui-mobile-base/nativescript_common/src/android/prelude.rs @@ -1,11 +1,11 @@ -use std::ffi::{c_void, CString}; -use std::ptr::NonNull; + + use jni::objects::{GlobalRef, JClass, JObject, JString}; -use jni::sys::{jboolean, jobject}; +use jni::sys::{jboolean}; use jni::JNIEnv; -use libc::{c_char, c_double, c_float, c_int}; -use log::log; +use libc::{c_double, c_float, c_int}; + use crate::android::{ BOOLEAN_CLASS, DOUBLE_CLASS, FLOAT_CLASS, INTEGER_CLASS, JVM, JVM_CLASS_CACHE, LONG_CLASS, diff --git a/packages/ui-mobile-base/nativescript_common/src/common/fs/copy_file.rs b/packages/ui-mobile-base/nativescript_common/src/common/fs/copy_file.rs index e6149b553..c9938e9aa 100644 --- a/packages/ui-mobile-base/nativescript_common/src/common/fs/copy_file.rs +++ b/packages/ui-mobile-base/nativescript_common/src/common/fs/copy_file.rs @@ -3,13 +3,9 @@ use std::path::Path; use libc::c_uint; -use crate::common::{ - FILE_COPY_OPTIONS_COPYFILE_EXCL, FILE_COPY_OPTIONS_COPYFILE_FICLONE, - FILE_COPY_OPTIONS_COPYFILE_FICLONE_FORCE, -}; - #[cfg(any(target_os = "android"))] pub fn copy_file(from: &Path, to: &Path, mode: c_uint) -> io::Result<()> { + use crate::common::{FILE_COPY_OPTIONS_COPYFILE_EXCL, FILE_COPY_OPTIONS_COPYFILE_FICLONE}; use std::fs; use std::os::unix::io::AsRawFd; @@ -50,6 +46,8 @@ pub fn copy_file(from: &Path, to: &Path, mode: c_uint) -> io::Result<()> { #[cfg(any(target_os = "macos", target_os = "ios"))] pub fn copy_file(from: &Path, to: &Path, flags: c_uint) -> io::Result<()> { + use crate::common::FILE_COPY_OPTIONS_COPYFILE_FICLONE_FORCE; + use crate::common::{FILE_COPY_OPTIONS_COPYFILE_EXCL, FILE_COPY_OPTIONS_COPYFILE_FICLONE}; use std::ffi::c_void; use std::ffi::CString; use std::os::unix::ffi::OsStrExt; diff --git a/packages/ui-mobile-base/nativescript_common/src/common/fs/sync.rs b/packages/ui-mobile-base/nativescript_common/src/common/fs/sync.rs index effc41c75..c2b8db4a4 100644 --- a/packages/ui-mobile-base/nativescript_common/src/common/fs/sync.rs +++ b/packages/ui-mobile-base/nativescript_common/src/common/fs/sync.rs @@ -301,8 +301,8 @@ pub fn futimes(fd: c_int, atime: c_long, mtime: c_long) -> std::io::Result<()> { pub fn lchmod(path: &str, mode: c_ushort) -> std::io::Result<()> { let mut options = OpenOptions::new(); options.write(true); - let mut file = options.open(path)?; - let mut permissions = std::fs::Permissions::from_mode(mode.into()); + let file = options.open(path)?; + let permissions = std::fs::Permissions::from_mode(mode.into()); file.set_permissions(permissions) }