From 1d8d3c282861d3889826d0db493bedf3a2aa1f06 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 18 Feb 2019 15:58:05 +0100 Subject: [PATCH] Add small helper to check if dpkg is in a broken state --- src/yunohost/utils/packages.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/yunohost/utils/packages.py b/src/yunohost/utils/packages.py index 5ef97618b..9cb3bd974 100644 --- a/src/yunohost/utils/packages.py +++ b/src/yunohost/utils/packages.py @@ -19,6 +19,7 @@ """ import re +import os import logging from collections import OrderedDict @@ -470,3 +471,11 @@ def ynh_packages_version(*args, **kwargs): 'yunohost', 'yunohost-admin', 'moulinette', 'ssowat', with_repo=True ) + + +def dpkg_is_broken(): + # If dpkg is broken, /var/lib/dpkg/updates + # will contains files like 0001, 0002, ... + # ref: https://sources.debian.org/src/apt/1.4.9/apt-pkg/deb/debsystem.cc/#L141-L174 + return any(re.match("^[0-9]+$", f) + for f in os.listdir("/var/lib/dpkg/updates/"))