apt upgrade

This commit is contained in:
Ward from fusion-voyager-3 2024-07-11 02:53:33 +03:00
parent 5b7f096621
commit 9e08875179
3 changed files with 30 additions and 19 deletions

View File

@ -8,15 +8,7 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="df2ca9e1-e07d-43f4-bc68-0a6113fc1fa2" name="Changes" comment=""> <list default="true" id="df2ca9e1-e07d-43f4-bc68-0a6113fc1fa2" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/bin/apt/apt_full_upgrade/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/bin/apt/apt_full_upgrade/main.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/bin/apt/apt_full_upgrade/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/bin/apt/apt_full_upgrade/main.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/bin/apt/apt_update/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/bin/apt/apt_update/main.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/bin/gui/apt_update_page/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/bin/gui/apt_update_page/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/bin/gui/apt_update_page/process.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/bin/gui/apt_update_page/process.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/lib/apt_install_progress_socket/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/apt_install_progress_socket/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/lib/apt_update_progress_socket/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/apt_update_progress_socket/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/lib/lib.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/lib.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/lib/pika_unixsocket_tools/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/pika_unixsocket_tools/mod.rs" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -141,7 +133,7 @@
<workItem from="1720556059466" duration="12649000" /> <workItem from="1720556059466" duration="12649000" />
<workItem from="1720594302708" duration="52000" /> <workItem from="1720594302708" duration="52000" />
<workItem from="1720597532937" duration="7050000" /> <workItem from="1720597532937" duration="7050000" />
<workItem from="1720648284536" duration="6532000" /> <workItem from="1720648284536" duration="7092000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -5,13 +5,14 @@ use rust_apt::new_cache;
use rust_apt::progress::{AcquireProgress, InstallProgress}; use rust_apt::progress::{AcquireProgress, InstallProgress};
use std::fs::*; use std::fs::*;
use std::process::exit; use std::process::exit;
use rust_apt::cache::Upgrade;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
fn main() { fn main() {
let cache = new_cache!().unwrap();
let percent_socket_path = "/tmp/pika_apt_upgrade_percent.sock"; let percent_socket_path = "/tmp/pika_apt_upgrade_percent.sock";
let status_socket_path = "/tmp/pika_apt_upgrade_status.sock"; let status_socket_path = "/tmp/pika_apt_upgrade_status.sock";
let json_file_path = "/tmp/pika-apt-exclusions.json"; let json_file_path = "/tmp/pika-apt-exclusions.json";
let mut excluded_updates_vec = Vec::new();
let json: serde_json::Value = serde_json::from_str( let json: serde_json::Value = serde_json::from_str(
&std::fs::read_to_string(json_file_path).expect("Unable to read file"), &std::fs::read_to_string(json_file_path).expect("Unable to read file"),
@ -20,11 +21,32 @@ fn main() {
if let serde_json::Value::Array(exclusions) = &json["exclusions"] { if let serde_json::Value::Array(exclusions) = &json["exclusions"] {
for exclusion in exclusions { for exclusion in exclusions {
println!("{}", exclusion["package"]) excluded_updates_vec.push(exclusion["package"].as_str().unwrap());
} }
} }
let pkg = cache.get("neovim").unwrap(); let apt_cache = new_cache!().unwrap();
let apt_upgrade_cache = new_cache!().unwrap();
apt_cache.upgrade(Upgrade::FullUpgrade).unwrap();
for change in apt_cache.get_changes(false) {
if !excluded_updates_vec
.iter()
.any(|e| change.name().contains(e))
{
let pkg = apt_upgrade_cache.get(change.name()).unwrap();
if change.marked_upgrade() || change.marked_install() || change.marked_downgrade() {
pkg.mark_install(true, false);
} else if change.marked_delete() {
pkg.mark_delete(false);
}
pkg.protect();
}
}
apt_upgrade_cache.resolve(true).unwrap();
let mut acquire_progress = AcquireProgress::new(AptUpdateProgressSocket::new( let mut acquire_progress = AcquireProgress::new(AptUpdateProgressSocket::new(
percent_socket_path, percent_socket_path,
status_socket_path, status_socket_path,
@ -34,13 +56,9 @@ fn main() {
status_socket_path, status_socket_path,
)); ));
pkg.mark_install(true, true); apt_upgrade_cache.resolve(true).unwrap();
pkg.protect();
cache.resolve(true).unwrap();
exit(1); match apt_upgrade_cache.get_archives(&mut acquire_progress) {
match cache.get_archives(&mut acquire_progress) {
Ok(_) => { Ok(_) => {
Runtime::new() Runtime::new()
.unwrap() .unwrap()
@ -60,7 +78,7 @@ fn main() {
} }
}; };
match cache.do_install(&mut install_progress) { match apt_upgrade_cache.do_install(&mut install_progress) {
Ok(_) => { Ok(_) => {
Runtime::new() Runtime::new()
.unwrap() .unwrap()

View File

@ -123,6 +123,7 @@ fn apt_confirm_window(excluded_updates_vec: &Vec<String>, window: adw::Applicati
} else if change.marked_delete() { } else if change.marked_delete() {
pkg.mark_delete(false); pkg.mark_delete(false);
} }
pkg.protect();
} }
} }