[neon/neon/settings/Neon/unstable] /: improve apt clean run condition

Harald Sitter null at kde.org
Wed Aug 18 12:21:47 BST 2021


Git commit 4bef4442976ab553a1b15cc50d2fd77138910d22 by Harald Sitter.
Committed on 18/08/2021 at 11:12.
Pushed by sitter into branch 'Neon/unstable'.

improve apt clean run condition

the path condition was woefully useless because the presence of the file
doesn't mean its locked. instead use a tiny script that warps around
lslocks and checks if any of the well known paths are locked, and use
that as a ExecCondition. not quite as ideal as a unit condition but
that's the best option we have I think.

the main settings package now depends on util-linux for lslocks

M  +1    -1    debian/control
M  +1    -3    lib/systemd/system/neon-apt-clean.service
A  +28   -0    usr/lib/neon_update/is_apt_locked.rb

https://invent.kde.org/neon/neon/settings/commit/4bef4442976ab553a1b15cc50d2fd77138910d22

diff --git a/debian/control b/debian/control
index 33fccc2..f7db915 100644
--- a/debian/control
+++ b/debian/control
@@ -11,7 +11,7 @@ Vcs-Git: git://packaging.neon.kde.org/neon/settings
 
 Package: neon-settings-2
 Architecture: all
-Depends: ruby, ${misc:Depends}
+Depends: ruby, util-linux, ${misc:Depends}
 Provides: neon-settings
 Conflicts: neon-settings (<< 0.4)
 Replaces: neon-settings (<< 0.4)
diff --git a/lib/systemd/system/neon-apt-clean.service b/lib/systemd/system/neon-apt-clean.service
index 9de3415..99ffc4d 100644
--- a/lib/systemd/system/neon-apt-clean.service
+++ b/lib/systemd/system/neon-apt-clean.service
@@ -4,12 +4,10 @@
 [Unit]
 Description=Apt cache cleanup
 ConditionACPower=true
-# No point starting (and failing) when the lock is currently held.
-ConditionPathExists=!/var/cache/apt/archives/lock
-# If packagekit is running wait until it is done. Otherwise we might block it with a temporary apt lock.
 After=packagekit.service
 
 [Service]
+ExecCondition=/usr/lib/neon_update/is_apt_locked.rb
 ExecStart=/usr/bin/apt-get autoclean
 Nice=9
 IOSchedulingPriority=6
diff --git a/usr/lib/neon_update/is_apt_locked.rb b/usr/lib/neon_update/is_apt_locked.rb
new file mode 100755
index 0000000..0f2098d
--- /dev/null
+++ b/usr/lib/neon_update/is_apt_locked.rb
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
+# SPDX-FileCopyrightText: 2021 Harald Sitter <sitter at kde.org>
+
+# This is meant to be used for ExecCondition checks. Exit codes have meaning!
+# https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecCondition=
+
+require 'open3'
+
+LOCKS = %w[
+  /var/cache/apt/archives/lock
+  /var/lib/dpkg/lock
+  /var/lib/dpkg/lock-frontend
+].freeze
+
+paths, status = Open3.capture2(*%w[lslocks --raw --output PATH])
+exit 255 unless status.success? # can't tell -> fail the unit
+
+paths.split("\n").each do |path|
+  next unless LOCKS.any? { |lock| lock == path }
+
+  warn "Lock held: #{path}"
+  exit 1
+end
+
+exit 0



More information about the Neon-commits mailing list