Skip to content

Commit dd2bb2b

Browse files
committed
Update resetprop to support --compact
1 parent 1d4fbd9 commit dd2bb2b

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

native/src/core/resetprop/cli.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct ResetProp {
2727
context: bool,
2828
#[argh(switch, short = 'n', long = none)]
2929
skip_svc: bool,
30+
#[argh(switch, short = 'c', long = "compact")]
31+
compact: bool,
3032
#[argh(option, short = 'f')]
3133
file: Option<Utf8CString>,
3234
#[argh(option, short = 'd', long = "delete")]
@@ -59,6 +61,7 @@ General flags:
5961
-h,--help show this message
6062
-v,--verbose print verbose output to stderr
6163
-w switch to wait mode
64+
-c,--compact compact property area (optional: context label)
6265
6366
Read mode flags:
6467
-p also read persistent properties from storage
@@ -177,6 +180,16 @@ impl ResetProp {
177180
ret
178181
}
179182

183+
fn compact(&self) -> bool {
184+
if let Some(context) = self.args.first() {
185+
debug!("resetprop: compact property area [{context}]");
186+
SYS_PROP.compact_context(context)
187+
} else {
188+
debug!("resetprop: compact property area");
189+
SYS_PROP.compact()
190+
}
191+
}
192+
180193
fn wait(&self) {
181194
let key = &self.args[0];
182195
let val = self.args.get(1).map(|s| &**s);
@@ -227,7 +240,11 @@ impl ResetProp {
227240
}
228241

229242
fn run(self) -> LoggedResult<()> {
230-
if self.wait_mode {
243+
if self.compact {
244+
if !self.compact() {
245+
return log_err!();
246+
}
247+
} else if self.wait_mode {
231248
self.wait();
232249
} else if let Some(file) = &self.file {
233250
self.load_file(file)?;
@@ -269,6 +286,9 @@ pub fn resetprop_main(argc: i32, argv: *mut *mut c_char) -> i32 {
269286
}
270287
special_mode += 1;
271288
}
289+
if cli.compact {
290+
special_mode += 1;
291+
}
272292
if cli.file.is_some() {
273293
special_mode += 1;
274294
}

native/src/core/resetprop/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ unsafe extern "C" {
8282
fn sys_prop_delete(key: CharPtr, prune: bool) -> i32;
8383
#[link_name = "__system_property_get_context"]
8484
fn sys_prop_get_context(key: CharPtr) -> CharPtr;
85+
#[link_name = "__system_property_compact"]
86+
fn sys_prop_compact() -> bool;
87+
#[link_name = "__system_property_compact_context"]
88+
fn sys_prop_compact_context(context: CharPtr) -> bool;
8589
#[link_name = "__system_property_area_serial2"]
8690
fn sys_prop_area_serial() -> u32;
8791
}
@@ -175,6 +179,14 @@ impl SysProp {
175179
unsafe { Utf8CStr::from_ptr_unchecked(sys_prop_get_context(key.as_ptr())) }
176180
}
177181

182+
fn compact(&self) -> bool {
183+
unsafe { sys_prop_compact() }
184+
}
185+
186+
fn compact_context(&self, context: &Utf8CStr) -> bool {
187+
unsafe { sys_prop_compact_context(context.as_ptr()) }
188+
}
189+
178190
fn area_serial(&self) -> u32 {
179191
unsafe { sys_prop_area_serial() }
180192
}

0 commit comments

Comments
 (0)