ksud: fallback to system mount when rust lib mount failed
This commit is contained in:
@@ -505,9 +505,7 @@ fn do_install_module(zip: String) -> Result<()> {
|
|||||||
// mount the modules_update.img to mountpoint
|
// mount the modules_update.img to mountpoint
|
||||||
println!("- Mounting image");
|
println!("- Mounting image");
|
||||||
|
|
||||||
{
|
mount::AutoMountExt4::try_new(tmp_module_img, module_update_tmp_dir)?;
|
||||||
// we need auto drop, so we use a block here
|
|
||||||
mount::mount_ext4(tmp_module_img, module_update_tmp_dir, true)?;
|
|
||||||
|
|
||||||
setsyscon(module_update_tmp_dir)?;
|
setsyscon(module_update_tmp_dir)?;
|
||||||
|
|
||||||
@@ -530,10 +528,6 @@ fn do_install_module(zip: String) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exec_install_script(&zip)?;
|
exec_install_script(&zip)?;
|
||||||
}
|
|
||||||
|
|
||||||
// remove modules_update dir, ignore the error
|
|
||||||
remove_dir_all(module_update_tmp_dir)?;
|
|
||||||
|
|
||||||
// all done, rename the tmp image to modules_update.img
|
// all done, rename the tmp image to modules_update.img
|
||||||
if std::fs::rename(tmp_module_img, defs::MODULE_UPDATE_IMG).is_err() {
|
if std::fs::rename(tmp_module_img, defs::MODULE_UPDATE_IMG).is_err() {
|
||||||
@@ -551,7 +545,6 @@ pub fn install_module(zip: String) -> Result<()> {
|
|||||||
// error happened, do some cleanup!
|
// error happened, do some cleanup!
|
||||||
let _ = std::fs::remove_file(defs::MODULE_UPDATE_TMP_IMG);
|
let _ = std::fs::remove_file(defs::MODULE_UPDATE_TMP_IMG);
|
||||||
let _ = mount::umount_dir(defs::MODULE_UPDATE_TMP_DIR);
|
let _ = mount::umount_dir(defs::MODULE_UPDATE_TMP_DIR);
|
||||||
let _ = std::fs::remove_dir_all(defs::MODULE_UPDATE_TMP_DIR);
|
|
||||||
println!("- Error: {e}");
|
println!("- Error: {e}");
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
@@ -588,13 +581,11 @@ where
|
|||||||
ensure_clean_dir(update_dir)?;
|
ensure_clean_dir(update_dir)?;
|
||||||
|
|
||||||
// mount the modules_update img
|
// mount the modules_update img
|
||||||
mount::mount_ext4(defs::MODULE_UPDATE_TMP_IMG, update_dir, true)?;
|
mount::AutoMountExt4::try_new(defs::MODULE_UPDATE_TMP_IMG, update_dir)?;
|
||||||
|
|
||||||
// call the operation func
|
// call the operation func
|
||||||
let result = func(id, update_dir);
|
let result = func(id, update_dir);
|
||||||
|
|
||||||
// umount modules_update.img
|
|
||||||
let _ = mount::umount_dir(update_dir);
|
|
||||||
let _ = remove_dir_all(update_dir);
|
let _ = remove_dir_all(update_dir);
|
||||||
|
|
||||||
std::fs::rename(modules_update_tmp_img, defs::MODULE_UPDATE_IMG)?;
|
std::fs::rename(modules_update_tmp_img, defs::MODULE_UPDATE_IMG)?;
|
||||||
|
|||||||
@@ -7,15 +7,16 @@ use retry::delay::NoDelay;
|
|||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
use sys_mount::{unmount, FilesystemType, Mount, MountFlags, Unmount, UnmountFlags};
|
use sys_mount::{unmount, FilesystemType, Mount, MountFlags, Unmount, UnmountFlags};
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[allow(dead_code)]
|
||||||
struct AutoMountExt4 {
|
pub struct AutoMountExt4 {
|
||||||
mnt: String,
|
mnt: String,
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
mount: Option<Mount>,
|
mount: Option<Mount>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl AutoMountExt4 {
|
impl AutoMountExt4 {
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
pub fn try_new(src: &str, mnt: &str) -> Result<Self> {
|
pub fn try_new(src: &str, mnt: &str) -> Result<Self> {
|
||||||
let result = Mount::builder()
|
let result = Mount::builder()
|
||||||
.fstype(FilesystemType::from("ext4"))
|
.fstype(FilesystemType::from("ext4"))
|
||||||
@@ -50,6 +51,12 @@ impl AutoMountExt4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
pub fn try_new(_src: &str, _mnt: &str) -> Result<Self> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
pub fn umount(&self) -> Result<()> {
|
pub fn umount(&self) -> Result<()> {
|
||||||
match self.mount {
|
match self.mount {
|
||||||
Some(ref mount) => mount
|
Some(ref mount) => mount
|
||||||
|
|||||||
Reference in New Issue
Block a user