mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-21 23:47:39 +00:00
Box CpioEntry
This commit is contained in:
parent
7e8e013832
commit
c874391be4
@ -94,7 +94,7 @@ struct CpioHeader {
|
||||
}
|
||||
|
||||
pub(crate) struct Cpio {
|
||||
pub(crate) entries: BTreeMap<String, CpioEntry>,
|
||||
pub(crate) entries: BTreeMap<String, Box<CpioEntry>>,
|
||||
}
|
||||
|
||||
pub(crate) struct CpioEntry {
|
||||
@ -138,14 +138,14 @@ impl Cpio {
|
||||
continue;
|
||||
}
|
||||
let file_size = x8u::<usize>(&hdr.filesize)?;
|
||||
let entry = CpioEntry {
|
||||
let entry = Box::new(CpioEntry {
|
||||
mode: x8u(&hdr.mode)?,
|
||||
uid: x8u(&hdr.uid)?,
|
||||
gid: x8u(&hdr.gid)?,
|
||||
rdevmajor: x8u(&hdr.rdevmajor)?,
|
||||
rdevminor: x8u(&hdr.rdevminor)?,
|
||||
data: data[pos..pos + file_size].to_vec(),
|
||||
};
|
||||
});
|
||||
pos += file_size;
|
||||
cpio.entries.insert(name, entry);
|
||||
pos = align_4(pos);
|
||||
@ -303,14 +303,14 @@ impl Cpio {
|
||||
};
|
||||
self.entries.insert(
|
||||
norm_path(path),
|
||||
CpioEntry {
|
||||
Box::new(CpioEntry {
|
||||
mode,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdevmajor,
|
||||
rdevminor,
|
||||
data: content,
|
||||
},
|
||||
}),
|
||||
);
|
||||
eprintln!("Add file [{}] ({:04o})", path, mode);
|
||||
Ok(())
|
||||
@ -319,14 +319,14 @@ impl Cpio {
|
||||
fn mkdir(&mut self, mode: &mode_t, dir: &str) {
|
||||
self.entries.insert(
|
||||
norm_path(dir),
|
||||
CpioEntry {
|
||||
Box::new(CpioEntry {
|
||||
mode: *mode | S_IFDIR,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdevmajor: 0,
|
||||
rdevminor: 0,
|
||||
data: vec![],
|
||||
},
|
||||
}),
|
||||
);
|
||||
eprintln!("Create directory [{}] ({:04o})", dir, mode);
|
||||
}
|
||||
@ -334,14 +334,14 @@ impl Cpio {
|
||||
fn ln(&mut self, src: &str, dst: &str) {
|
||||
self.entries.insert(
|
||||
norm_path(dst),
|
||||
CpioEntry {
|
||||
Box::new(CpioEntry {
|
||||
mode: S_IFLNK,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdevmajor: 0,
|
||||
rdevminor: 0,
|
||||
data: norm_path(src).as_bytes().to_vec(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
eprintln!("Create symlink [{}] -> [{}]", dst, src);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ impl MagiskCpio for Cpio {
|
||||
}
|
||||
|
||||
fn restore(&mut self) -> anyhow::Result<()> {
|
||||
let mut backups = HashMap::<String, CpioEntry>::new();
|
||||
let mut backups = HashMap::<String, Box<CpioEntry>>::new();
|
||||
let mut rm_list = String::new();
|
||||
self.entries
|
||||
.drain_filter(|name, _| name.starts_with(".backup/"))
|
||||
@ -121,18 +121,18 @@ impl MagiskCpio for Cpio {
|
||||
}
|
||||
|
||||
fn backup(&mut self, origin: &Utf8CStr) -> anyhow::Result<()> {
|
||||
let mut backups = HashMap::<String, CpioEntry>::new();
|
||||
let mut backups = HashMap::<String, Box<CpioEntry>>::new();
|
||||
let mut rm_list = String::new();
|
||||
backups.insert(
|
||||
".backup".to_string(),
|
||||
CpioEntry {
|
||||
Box::new(CpioEntry {
|
||||
mode: S_IFDIR,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdevmajor: 0,
|
||||
rdevminor: 0,
|
||||
data: vec![],
|
||||
},
|
||||
}),
|
||||
);
|
||||
let mut o = Cpio::load_from_file(origin)?;
|
||||
o.rm(".backup", true);
|
||||
@ -143,7 +143,7 @@ impl MagiskCpio for Cpio {
|
||||
|
||||
loop {
|
||||
enum Action<'a> {
|
||||
Backup(String, CpioEntry),
|
||||
Backup(String, Box<CpioEntry>),
|
||||
Record(&'a String),
|
||||
Noop,
|
||||
}
|
||||
@ -190,14 +190,14 @@ impl MagiskCpio for Cpio {
|
||||
if !rm_list.is_empty() {
|
||||
backups.insert(
|
||||
".backup/.rmlist".to_string(),
|
||||
CpioEntry {
|
||||
Box::new(CpioEntry {
|
||||
mode: S_IFREG,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdevmajor: 0,
|
||||
rdevminor: 0,
|
||||
data: rm_list.as_bytes().to_vec(),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
self.entries.extend(backups);
|
||||
|
Loading…
x
Reference in New Issue
Block a user