From f3cad926b0b536049a692b4ea7a0a2df41db6d6a Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Fri, 18 Sep 2026 06:25:21 +0800 Subject: [PATCH] fix: distinguish ENOENT from lock in isFileLocked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: isFileLocked() returned true for all open() failures, conflating "file not found" (ENOENT) with "file is locked", causing misleading "Dpkg locked" timeout errors 2. Fix: add errno check after open() failure, return false for ENOENT (file not found = not locked), keep true for other failures (defensive conservative behavior) 3. Impact: callers aptinstaller.cpp and debinstaller.cpp no longer retry indefinitely when dpkg lock file is absent Log: fix incorrect Dpkg locked error when lock file is missing Influence: 1. Test package uninstall when dpkg lock file exists and is locked 2. Test package uninstall when dpkg lock file does not exist 3. Verify normal package install/uninstall works correctly fix: 区分文件不存在与文件锁定状态 1. 根因:isFileLocked() 对所有 open() 失败统一返回 true,将 文件不存在(ENOENT)与文件被锁定混淆,导致锁文件缺失时 误报 Dpkg locked 超时错误 2. 方案:open() 失败后检查 errno,ENOENT 返回 false(未锁定), 其他错误保持返回 true(保守视为已锁定) 3. 影响:aptinstaller.cpp 和 debinstaller.cpp 调用方在锁文件 不存在时不再无限重试 Log: 修复锁文件不存在时误报 Dpkg locked 的问题 Influence: 1. 测试 dpkg 锁文件存在且被锁定时的卸载操作 2. 测试 dpkg 锁文件不存在时的卸载操作 3. 验证正常的安装卸载功能不受影响 PMS: DEFECT-001 --- .../deepin-devicecontrol/src/drivercontrol/utils.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/deepin-devicemanager-server/deepin-devicecontrol/src/drivercontrol/utils.cpp b/deepin-devicemanager-server/deepin-devicecontrol/src/drivercontrol/utils.cpp index 9fc154e17..d50052f31 100644 --- a/deepin-devicemanager-server/deepin-devicecontrol/src/drivercontrol/utils.cpp +++ b/deepin-devicemanager-server/deepin-devicecontrol/src/drivercontrol/utils.cpp @@ -16,6 +16,7 @@ #include #include #include +#include using namespace DDLog; @@ -214,9 +215,14 @@ bool Utils::isFileLocked(const QString &filepath, bool bread) fl.l_pid = getpid(); /* PID */ int fd = open(filepath.toStdString().c_str(), opentype); - //文件打开失败默认为被锁住 + //文件打开失败,区分文件不存在与其他错误 if (fd < 0) { - return true; + if (errno == ENOENT) { + //文件不存在,未被锁定 + return false; + } + //其他原因无法打开文件,保守起见视为已锁定 + return true; } if (-1 == fcntl(fd, F_SETLK, &fl)) {