From 5c52ac5be0e2b042635da7bb24595ac39cd07922 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Fri, 18 Sep 2026 06:23:42 +0800 Subject: [PATCH] fix(drivercontrol): distinguish file-not-found from locked in isFileLocked() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add #include for errno and ENOENT definitions - Modify isFileLocked() to return false when errno is ENOENT (file does not exist), instead of returning true - Keep returning true for other open() failures as conservative locked behavior 修复(drivercontrol): 区分文件不存在与文件被锁定的情况 - 新增 #include 头文件,用于 errno 和 ENOENT 定义 - 修改 isFileLocked() 函数,当 errno 为 ENOENT(文件不存在)时返回 false,不再误报为已锁定 - 其余 open() 失败情况保持返回 true,保守视为已锁定 Log: 修复 isFileLocked() 在文件不存在时误报锁定的问题,区分 ENOENT 与其他打开失败 Influence: 仅修改 utils.cpp 中 isFileLocked() 函数逻辑及头文件包含,API 签名不变,行为向后兼容 PMS: https://pms.uniontech.com/bug-view-1.html --- .../deepin-devicecontrol/src/drivercontrol/utils.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/deepin-devicemanager-server/deepin-devicecontrol/src/drivercontrol/utils.cpp b/deepin-devicemanager-server/deepin-devicecontrol/src/drivercontrol/utils.cpp index 9fc154e17..35939c15e 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; @@ -216,7 +217,12 @@ bool Utils::isFileLocked(const QString &filepath, bool bread) 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)) {