Skip to content

Commit cc1f814

Browse files
committed
style: fix and enforce formatting
1 parent 96ac6b8 commit cc1f814

7 files changed

Lines changed: 126 additions & 74 deletions

File tree

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
commit-message:
8+
prefix: chore
9+
include: scope
10+
ignore:
11+
- dependency-name: dtolnay/rust-toolchain

.github/workflows/CI.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
push:
3+
branches: [master]
4+
pull_request:
5+
6+
name: Continuous integration
7+
8+
jobs:
9+
10+
fmt:
11+
name: format
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v6
15+
- uses: dtolnay/rust-toolchain@nightly
16+
with:
17+
components: rustfmt
18+
- run: cargo fmt --all --check

daemon/src/cli/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ const UPGRADE_RESULT_ERROR: &str = "release upgrade aborted";
4343
pub struct Client(client::Client);
4444

4545
impl Client {
46-
pub fn new() -> Result<Self, client::Error> {
47-
client::Client::new().map(Client)
48-
}
46+
pub fn new() -> Result<Self, client::Error> { client::Client::new().map(Client) }
4947

5048
/// Executes the recovery subcommand of the client.
5149
pub fn recovery(&self, matches: &ArgMatches) -> anyhow::Result<()> {

daemon/src/daemon/mod.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,18 @@ pub const INSTALL_DATE: &str = "/usr/lib/pop-upgrade/install_date";
8585

8686
#[derive(Debug)]
8787
pub enum Event {
88-
FetchUpdates { apt_uris: HashSet<AptRequest>, download_only: bool },
88+
FetchUpdates {
89+
apt_uris: HashSet<AptRequest>,
90+
download_only: bool,
91+
},
8992
PackageUpgrade,
9093
RecoveryUpgrade(RecoveryUpgradeMethod),
91-
ReleaseUpgrade { how: ReleaseUpgradeMethod, from: String, to: String, await_recovery: bool },
94+
ReleaseUpgrade {
95+
how: ReleaseUpgradeMethod,
96+
from: String,
97+
to: String,
98+
await_recovery: bool,
99+
},
92100
}
93101

94102
#[derive(Debug)]
@@ -97,55 +105,53 @@ pub enum FgEvent {
97105
}
98106

99107
pub struct LastKnown {
100-
development: bool,
101-
fetch: Result<(), ReleaseError>,
108+
development: bool,
109+
fetch: Result<(), ReleaseError>,
102110
recovery_upgrade: Result<(), RecoveryError>,
103-
release_upgrade: Result<(), ReleaseError>,
111+
release_upgrade: Result<(), ReleaseError>,
104112
}
105113

106114
impl Default for LastKnown {
107115
fn default() -> Self {
108116
Self {
109-
development: false,
110-
fetch: Ok(()),
117+
development: false,
118+
fetch: Ok(()),
111119
recovery_upgrade: Ok(()),
112-
release_upgrade: Ok(()),
120+
release_upgrade: Ok(()),
113121
}
114122
}
115123
}
116124

117125
pub struct ReleaseUpgradeState {
118126
action: release::UpgradeMethod,
119-
from: Box<str>,
120-
to: Box<str>,
127+
from: Box<str>,
128+
to: Box<str>,
121129
}
122130

123131
#[derive(Clone, Copy, Debug)]
124132
struct FetchState {
125133
progress: u64,
126-
total: u64,
134+
total: u64,
127135
}
128136

129137
impl FetchState {
130-
pub const fn new(progress: u64, total: u64) -> Self {
131-
Self { progress, total }
132-
}
138+
pub const fn new(progress: u64, total: u64) -> Self { Self { progress, total } }
133139
}
134140

135141
unsafe impl bytemuck::NoUninit for FetchState {}
136142

137143
struct SharedState {
138144
// In case a UI is being constructed after a task has already started, it may request
139145
// for the curernt progress of a task.
140-
fetching_state: Atomic<FetchState>,
146+
fetching_state: Atomic<FetchState>,
141147
// The status of the event loop thread, which indicates the current task, or lack thereof.
142-
status: Atomic<DaemonStatus>,
148+
status: Atomic<DaemonStatus>,
143149
// As well as the current sub-status, if relevant.
144-
sub_status: AtomicU8,
150+
sub_status: AtomicU8,
145151
// Cancels a process that is currently active.
146-
shutdown: Mutex<Shutdown<()>>,
152+
shutdown: Mutex<Shutdown<()>>,
147153
// Development release
148-
force_next: AtomicBool,
154+
force_next: AtomicBool,
149155
// Indicates that it is now uncancellable
150156
release_upgrade_began: AtomicBool,
151157
}
@@ -157,12 +163,12 @@ enum ReleaseCheck {
157163
}
158164

159165
pub struct Daemon {
160-
event_tx: UnboundedSender<Event>,
161-
last_known: LastKnown,
166+
event_tx: UnboundedSender<Event>,
167+
last_known: LastKnown,
162168
perform_upgrade: bool,
163-
release_check: ReleaseCheck,
169+
release_check: ReleaseCheck,
164170
release_upgrade: Option<ReleaseUpgradeState>,
165-
shared_state: Arc<SharedState>,
171+
shared_state: Arc<SharedState>,
166172
}
167173

168174
impl Daemon {
@@ -180,11 +186,11 @@ impl Daemon {
180186

181187
// State shared between the background task thread, and the foreground DBus event loop.
182188
let shared_state = Arc::new(SharedState {
183-
status: Atomic::new(DaemonStatus::Inactive),
184-
sub_status: AtomicU8::new(0),
185-
fetching_state: Atomic::new(FetchState::new(0, 0)),
186-
shutdown: Mutex::new(Shutdown::new()),
187-
force_next: AtomicBool::new(false),
189+
status: Atomic::new(DaemonStatus::Inactive),
190+
sub_status: AtomicU8::new(0),
191+
fetching_state: Atomic::new(FetchState::new(0, 0)),
192+
shutdown: Mutex::new(Shutdown::new()),
193+
force_next: AtomicBool::new(false),
188194
release_upgrade_began: AtomicBool::new(false),
189195
});
190196

@@ -1023,8 +1029,8 @@ impl Daemon {
10231029

10241030
let event = Event::RecoveryUpgrade(RecoveryUpgradeMethod::FromRelease {
10251031
version: if version.is_empty() { None } else { Some(version.into()) },
1026-
arch: if arch.is_empty() { None } else { Some(arch.into()) },
1027-
flags: RecoveryReleaseFlags::from_bits_truncate(flags),
1032+
arch: if arch.is_empty() { None } else { Some(arch.into()) },
1033+
flags: RecoveryReleaseFlags::from_bits_truncate(flags),
10281034
});
10291035

10301036
self.submit_event(event)

daemon/src/fetch/apt.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ pub async fn fetch_uris(
4444
.noninteractive()
4545
.fetch_uris(&args)
4646
.await
47-
.context("failed to exec `apt-get install --print-uris` or `apt-get download --print-uris`")?
48-
.context("failed to fetch package URIs from `apt-get install` or `apt-get download`")?;
47+
.context(
48+
"failed to exec `apt-get install --print-uris` or `apt-get download \
49+
--print-uris`",
50+
)?
51+
.context(
52+
"failed to fetch package URIs from `apt-get install` or `apt-get download`",
53+
)?;
4954

5055
for uri in install_uris {
5156
uris.insert(uri);

daemon/src/release/mod.rs

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ pub const STARTUP_UPGRADE_FILE: &str = "/pop-upgrade";
4242
/// Packages which need to be removed *before* the sources are reset to defaults
4343
/// and updates are applied (e.g. DKMS packages that work with the Pop!_OS kernel when
4444
/// installed from third-party sources, but not when installed from the Ubuntu repo).
45-
const REMOVE_PACKAGES_EARLY: &[&str] = &[
46-
"openrazer-driver-dkms",
47-
];
45+
const REMOVE_PACKAGES_EARLY: &[&str] = &["openrazer-driver-dkms"];
4846

4947
/// Packages which should be removed before upgrading.
5048
///
@@ -176,13 +174,19 @@ impl From<UpgradeEvent> for &'static str {
176174
}
177175
UpgradeEvent::Failure => "an error occurred while setting up the release upgrade",
178176
UpgradeEvent::FetchingPackages => "fetching updated packages for the current release",
179-
UpgradeEvent::FetchingPackagesForNewRelease => "fetching updated packages for the new release",
180-
UpgradeEvent::FetchingAdditionalPackagesForNewRelease => "fetching additional packages for the new release",
177+
UpgradeEvent::FetchingPackagesForNewRelease => {
178+
"fetching updated packages for the new release"
179+
}
180+
UpgradeEvent::FetchingAdditionalPackagesForNewRelease => {
181+
"fetching additional packages for the new release"
182+
}
181183
UpgradeEvent::InstallingPackages => {
182184
"ensuring that system-critical packages are installed"
183185
}
184186
UpgradeEvent::RemovingConflicts => "removing deprecated and/or conflicting packages",
185-
UpgradeEvent::RemovingWacomConflicts => "replacing Surface-tailored Wacom packages with standard ones",
187+
UpgradeEvent::RemovingWacomConflicts => {
188+
"replacing Surface-tailored Wacom packages with standard ones"
189+
}
186190
UpgradeEvent::Success => "new release is ready to install",
187191
UpgradeEvent::SuccessLive => "new release was successfully installed",
188192
UpgradeEvent::UpdatingPackageLists => "updating package lists",
@@ -469,7 +473,7 @@ pub async fn upgrade<'a>(
469473

470474
// Ensure packages are not newer than what's in the repositories.
471475
downgrade_packages().await?;
472-
476+
473477
// Replace problematic Wacom packages with supported ones.
474478
remove_wacom_packages(logger).await?;
475479

@@ -493,7 +497,7 @@ pub async fn upgrade<'a>(
493497

494498
// Reset system76-power modprobe configurations to the system defaults.
495499
_ = switchable_graphics::reset_to_default();
496-
500+
497501
// Reset the user shell to /bin/bash in case the shell was removed in upgrade
498502
_ = logins::reset_shell();
499503

@@ -533,17 +537,20 @@ async fn downgrade_packages() -> Result<(), ReleaseError> {
533537
if package.contains("pop-upgrade") || package.contains("pop-system-updater") {
534538
continue;
535539
}
536-
540+
537541
// Papirus's elementary variant must be removed prior to downgrading the main package.
538542
if package.contains("papirus-icon-theme") {
539543
info!("papirus-icon-theme will be downgraded, so removing epapirus-icon-theme");
540544
let mut remove_epapirus_cmd = AptGet::new().allow_downgrades().force().noninteractive();
541545
remove_epapirus_cmd.arg("remove");
542546
remove_epapirus_cmd.arg("epapirus-icon-theme");
543-
let _remove_epapirus = remove_epapirus_cmd.status().await
544-
.context("apt-get remove epapirus-icon-theme").map_err(ReleaseError::Downgrade);
547+
let _remove_epapirus = remove_epapirus_cmd
548+
.status()
549+
.await
550+
.context("apt-get remove epapirus-icon-theme")
551+
.map_err(ReleaseError::Downgrade);
545552
}
546-
553+
547554
// In Ubuntu 22.04, the `ansible` and `ansible-core` packages are not compatible.
548555
// If `ansible-core` is downgradable, check if `ansible` is downgradable;
549556
// if so, remove `ansible-core` and skip adding it to the downgrade command.
@@ -552,11 +559,15 @@ async fn downgrade_packages() -> Result<(), ReleaseError> {
552559
for (package, _version) in &downgradable {
553560
if package.eq("ansible") {
554561
info!("ansible will also be downgraded, so removing ansible-core");
555-
let mut remove_ansible_core_cmd = AptGet::new().allow_downgrades().force().noninteractive();
556-
remove_ansible_core_cmd.arg("remove");
557-
remove_ansible_core_cmd.arg("ansible-core");
558-
let _remove_ansible_core = remove_ansible_core_cmd.status().await
559-
.context("apt-get remove ansible-core").map_err(ReleaseError::Downgrade);
562+
let mut remove_ansible_core_cmd =
563+
AptGet::new().allow_downgrades().force().noninteractive();
564+
remove_ansible_core_cmd.arg("remove");
565+
remove_ansible_core_cmd.arg("ansible-core");
566+
let _remove_ansible_core = remove_ansible_core_cmd
567+
.status()
568+
.await
569+
.context("apt-get remove ansible-core")
570+
.map_err(ReleaseError::Downgrade);
560571
continue 'downgrades;
561572
}
562573
}
@@ -611,8 +622,9 @@ async fn remove_wacom_packages(logger: &dyn Fn(UpgradeEvent)) -> Result<(), Rele
611622
// This must be done before checking for remoteless packages,
612623
// as other related packages will also be removed.
613624
let mut conflicting_surface = (async {
614-
let (mut child, package_stream) =
615-
DpkgQuery::new().show_installed(["libwacom-common-surface", "libwacom9-surface"]).await?;
625+
let (mut child, package_stream) = DpkgQuery::new()
626+
.show_installed(["libwacom-common-surface", "libwacom9-surface"])
627+
.await?;
616628

617629
futures_util::pin_mut!(package_stream);
618630

@@ -630,7 +642,7 @@ async fn remove_wacom_packages(logger: &dyn Fn(UpgradeEvent)) -> Result<(), Rele
630642
.await
631643
.context("check for known-conflicting Wacom/Surface packages")
632644
.map_err(ReleaseError::ConflictRemoval)?;
633-
645+
634646
if !conflicting_surface.is_empty() {
635647
apt_lock_wait().await;
636648
(logger)(UpgradeEvent::RemovingWacomConflicts);
@@ -643,11 +655,15 @@ async fn remove_wacom_packages(logger: &dyn Fn(UpgradeEvent)) -> Result<(), Rele
643655
.context("conflict removal (libwacom Surface packages)")
644656
.map_err(ReleaseError::ConflictRemoval)?;
645657
}
646-
658+
647659
Ok(())
648660
}
649661

650-
async fn remove_conflicting_packages(logger: &dyn Fn(UpgradeEvent), packages: &[&str], remoteless: bool) -> Result<(), ReleaseError> {
662+
async fn remove_conflicting_packages(
663+
logger: &dyn Fn(UpgradeEvent),
664+
packages: &[&str],
665+
remoteless: bool,
666+
) -> Result<(), ReleaseError> {
651667
let mut conflicting = (async {
652668
let (mut child, package_stream) = DpkgQuery::new().show_installed(packages).await?;
653669

@@ -788,9 +804,10 @@ async fn fetch_new_release_packages<'b>(
788804

789805
// If upgrading to 24.04, download an additional package.
790806
if to == "24.04" {
791-
//const NEW_PACKAGES &[&str] = &["gnome-online-accounts-gtk"];
792-
//new_packages = Some(ExtraPackages::Static(NEW_PACKAGES));
793-
additional_fetch(&Shutdown::new(), logger, fetch, &["gnome-online-accounts-gtk"]).await?;
807+
// const NEW_PACKAGES &[&str] = &["gnome-online-accounts-gtk"];
808+
// new_packages = Some(ExtraPackages::Static(NEW_PACKAGES));
809+
additional_fetch(&Shutdown::new(), logger, fetch, &["gnome-online-accounts-gtk"])
810+
.await?;
794811
}
795812

796813
snapd::hold_transitional_packages().await?;
@@ -926,24 +943,23 @@ mod logins {
926943
use std::process::{Command, Stdio};
927944

928945
fn login_is_disabled(user: &str) -> bool {
929-
Command::new("getent")
930-
.args(&["passwd", user])
931-
.stdout(Stdio::piped())
932-
.output()
933-
.map_or(true, |output| {
946+
Command::new("getent").args(&["passwd", user]).stdout(Stdio::piped()).output().map_or(
947+
true,
948+
|output| {
934949
let stdout = output.stdout.trim_end();
935950
stdout.ends_with(b"/bin/false") || stdout.ends_with(b"/usr/sbin/nologin")
936-
})
951+
},
952+
)
937953
}
938-
954+
939955
/// Reset the user shell to /bin/bash in case the shell was removed in upgrade
940956
pub fn reset_shell() -> anyhow::Result<()> {
941957
let (uid_min, uid_max) = crate::misc::uid_min_max()?;
942-
958+
943959
for user in unsafe { uzers::all_users() } {
944960
if user.uid() >= uid_min && user.uid() <= uid_max {
945961
let name = user.name();
946-
962+
947963
if let Some(name) = name.to_str() {
948964
if !login_is_disabled(name) {
949965
_ = std::process::Command::new("usermod")
@@ -953,7 +969,7 @@ mod logins {
953969
}
954970
}
955971
}
956-
972+
957973
Ok(())
958974
}
959-
}
975+
}

0 commit comments

Comments
 (0)