Skip to content

Commit 4fdd3e0

Browse files
committedFeb 24, 2025·
ksud: migrate to Rust 2024 edition
1 parent e245e34 commit 4fdd3e0

11 files changed

+30
-27
lines changed
 

‎userspace/ksud/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ksud"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

‎userspace/ksud/src/apk_sign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{ensure, Result};
1+
use anyhow::{Result, ensure};
22
use std::io::{Read, Seek, SeekFrom};
33

44
pub fn get_apk_signature(apk: &str) -> Result<(u32, String)> {

‎userspace/ksud/src/boot_patch.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::path::PathBuf;
55
use std::process::Command;
66
use std::process::Stdio;
77

8+
use anyhow::Context;
9+
use anyhow::Result;
810
use anyhow::anyhow;
911
use anyhow::bail;
1012
use anyhow::ensure;
11-
use anyhow::Context;
12-
use anyhow::Result;
1313
use regex_lite::Regex;
1414
use which::which;
1515

@@ -97,7 +97,7 @@ pub fn get_current_kmi() -> Result<String> {
9797
}
9898

9999
fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
100-
use std::fs::{copy, File};
100+
use std::fs::{File, copy};
101101
use std::io::{BufReader, Read};
102102
let kernel_path = workdir.join("kernel");
103103
copy(kernel, &kernel_path).context("Failed to copy kernel")?;

‎userspace/ksud/src/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{ensure, Context, Ok, Result};
1+
use anyhow::{Context, Ok, Result, ensure};
22
use std::{
33
path::{Path, PathBuf},
44
process::Command,

‎userspace/ksud/src/init_event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{bail, Context, Result};
1+
use anyhow::{Context, Result, bail};
22
use log::{info, warn};
33
use std::{collections::HashMap, path::Path};
44

‎userspace/ksud/src/module.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
sepolicy, utils,
77
};
88

9-
use anyhow::{anyhow, bail, ensure, Context, Result};
9+
use anyhow::{Context, Result, anyhow, bail, ensure};
1010
use const_format::concatcp;
1111
use is_executable::is_executable;
1212
use java_properties::PropertiesIter;
@@ -16,7 +16,7 @@ use std::fs::OpenOptions;
1616
use std::{
1717
collections::HashMap,
1818
env::var as env_var,
19-
fs::{remove_dir_all, remove_file, set_permissions, File, Permissions},
19+
fs::{File, Permissions, remove_dir_all, remove_file, set_permissions},
2020
io::Cursor,
2121
path::{Path, PathBuf},
2222
process::{Command, Stdio},
@@ -672,12 +672,15 @@ fn _list_modules(path: &str) -> Vec<HashMap<String, String>> {
672672
});
673673

674674
if !module_prop_map.contains_key("id") || module_prop_map["id"].is_empty() {
675-
if let Some(id) = entry.file_name().to_str() {
676-
info!("Use dir name as module id: {}", id);
677-
module_prop_map.insert("id".to_owned(), id.to_owned());
678-
} else {
679-
info!("Failed to get module id: {:?}", module_prop);
680-
continue;
675+
match entry.file_name().to_str() {
676+
Some(id) => {
677+
info!("Use dir name as module id: {}", id);
678+
module_prop_map.insert("id".to_owned(), id.to_owned());
679+
}
680+
_ => {
681+
info!("Failed to get module id: {:?}", module_prop);
682+
continue;
683+
}
681684
}
682685
}
683686

‎userspace/ksud/src/mount.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, bail, Ok, Result};
1+
use anyhow::{Ok, Result, anyhow, bail};
22

33
#[cfg(any(target_os = "linux", target_os = "android"))]
44
use anyhow::Context;

‎userspace/ksud/src/restorecon.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::Path;
66
#[cfg(any(target_os = "linux", target_os = "android"))]
77
use anyhow::{Context, Ok};
88
#[cfg(any(target_os = "linux", target_os = "android"))]
9-
use extattr::{lsetxattr, Flags as XattrFlags};
9+
use extattr::{Flags as XattrFlags, lsetxattr};
1010

1111
pub const SYSTEM_CON: &str = "u:object_r:system_file:s0";
1212
pub const ADB_CON: &str = "u:object_r:adb_data_file:s0";

‎userspace/ksud/src/sepolicy.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use anyhow::{bail, Result};
1+
use anyhow::{Result, bail};
22
use derive_new::new;
33
use nom::{
4+
AsChar, IResult, Parser,
45
branch::alt,
5-
bytes::complete::{tag, take_while, take_while1, take_while_m_n},
6+
bytes::complete::{tag, take_while, take_while_m_n, take_while1},
67
character::complete::{space0, space1},
78
combinator::map,
8-
AsChar, IResult, Parser,
99
};
1010
use std::{ffi, path::Path, vec};
1111

‎userspace/ksud/src/su.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
#[cfg(any(target_os = "linux", target_os = "android"))]
1515
use rustix::{
1616
process::getuid,
17-
thread::{set_thread_res_gid, set_thread_res_uid, Gid, Uid},
17+
thread::{Gid, Uid, set_thread_res_gid, set_thread_res_uid},
1818
};
1919

2020
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -280,6 +280,6 @@ fn add_path_to_env(path: &str) -> Result<()> {
280280
let new_path = PathBuf::from(path.trim_end_matches('/'));
281281
paths.push(new_path);
282282
let new_path_env = env::join_paths(paths)?;
283-
env::set_var("PATH", new_path_env);
283+
unsafe { env::set_var("PATH", new_path_env) };
284284
Ok(())
285285
}

‎userspace/ksud/src/utils.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use anyhow::{bail, Context, Error, Ok, Result};
1+
use anyhow::{Context, Error, Ok, Result, bail};
22
use std::{
3-
fs::{create_dir_all, remove_file, write, File, OpenOptions},
3+
fs::{File, OpenOptions, create_dir_all, remove_file, write},
44
io::{
55
ErrorKind::{AlreadyExists, NotFound},
66
Write,
@@ -11,7 +11,7 @@ use std::{
1111

1212
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
1313
#[allow(unused_imports)]
14-
use std::fs::{set_permissions, Permissions};
14+
use std::fs::{Permissions, set_permissions};
1515
#[cfg(unix)]
1616
use std::os::unix::prelude::PermissionsExt;
1717

@@ -24,7 +24,7 @@ use std::path::PathBuf;
2424
#[cfg(any(target_os = "linux", target_os = "android"))]
2525
use rustix::{
2626
process,
27-
thread::{move_into_link_name_space, LinkNameSpaceType},
27+
thread::{LinkNameSpaceType, move_into_link_name_space},
2828
};
2929

3030
pub fn ensure_clean_dir(dir: impl AsRef<Path>) -> Result<()> {
@@ -129,7 +129,7 @@ pub fn get_zip_uncompressed_size(zip_path: &str) -> Result<u64> {
129129
pub fn switch_mnt_ns(pid: i32) -> Result<()> {
130130
use rustix::{
131131
fd::AsFd,
132-
fs::{open, Mode, OFlags},
132+
fs::{Mode, OFlags, open},
133133
};
134134
let path = format!("/proc/{pid}/ns/mnt");
135135
let fd = open(path, OFlags::RDONLY, Mode::from_raw_mode(0))?;

0 commit comments

Comments
 (0)
Please sign in to comment.