mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: clean up
This commit is contained in:
@@ -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(),
|
||||
))
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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<FileDirent>) -> 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<FileDirent>) -> jobjectArr
|
||||
pub(crate) fn build_dirents_paths(env: &JNIEnv, dirent: Vec<OsString>) -> 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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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!()
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user