Skip to content

fix(oma-pm,oma-pm-operate-type)!: fix calculate need disk size #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions oma-pm-operation-type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct OmaOperation {
pub total_download_size: u64,
pub suggest: Vec<(String, String)>,
pub recommend: Vec<(String, String)>,
pub max_old_installed_size: u64,
}

impl Display for OmaOperation {
Expand Down
21 changes: 20 additions & 1 deletion oma-pm/src/apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ impl OmaApt {
let mut suggest = HashSet::with_hasher(ahash::RandomState::new());
let mut recommend = HashSet::with_hasher(ahash::RandomState::new());

let mut max_old_installed_size = 0;

for pkg in changes {
if pkg.marked_new_install() {
let cand = pkg
Expand Down Expand Up @@ -886,6 +888,8 @@ impl OmaApt {
}

if pkg.marked_upgrade() {
swap_max_old_instaalled_size(&mut max_old_installed_size, &pkg);

let install_entry = pkg_delta(
&pkg,
InstallOperation::Upgrade,
Expand Down Expand Up @@ -952,6 +956,8 @@ impl OmaApt {
}

if pkg.marked_reinstall() {
swap_max_old_instaalled_size(&mut max_old_installed_size, &pkg);

// 如果一个包被标记为重装,则肯定已经安装
// 所以请求已安装版本应该直接 unwrap
let version = pkg.installed().unwrap();
Expand Down Expand Up @@ -986,6 +992,8 @@ impl OmaApt {
}

if pkg.marked_downgrade() {
swap_max_old_instaalled_size(&mut max_old_installed_size, &pkg);

let install_entry = pkg_delta(
&pkg,
InstallOperation::Downgrade,
Expand Down Expand Up @@ -1058,14 +1066,17 @@ impl OmaApt {
autoremovable,
suggest: suggest.into_iter().collect(),
recommend: recommend.into_iter().collect(),
max_old_installed_size,
})
}

/// Check available disk space
pub fn check_disk_size(&self, op: &OmaOperation) -> OmaAptResult<()> {
let download_size = op.total_download_size as i64;

let need_space = download_size + op.disk_size_delta;
// dpkg 需要先解压新版本的文件,在删除老版本的文件
// 所以要加上被卸载掉的包的 最大的包的安装大小
let need_space = download_size + op.disk_size_delta + op.max_old_installed_size as i64;

let available_disk_size =
fs4::available_space(self.config.get("Dir").unwrap_or("/".to_string()))
Expand Down Expand Up @@ -1110,6 +1121,14 @@ impl OmaApt {
}
}

fn swap_max_old_instaalled_size(max_old_installed_size: &mut u64, pkg: &Package<'_>) {
let installed_size = pkg.installed().unwrap().installed_size();

if installed_size > *max_old_installed_size {
*max_old_installed_size = installed_size;
}
}

fn dpkg_exit_status(mut cmd: std::process::Child) -> Result<(), OmaAptError> {
match cmd.wait() {
Ok(status) => match status.code() {
Expand Down
Loading