From patchwork Tue Dec 22 13:58:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10694 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2E942C0F1A for ; Tue, 22 Dec 2020 13:58:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4278615B1; Tue, 22 Dec 2020 14:58:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="P2FLc5/w"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E106E6158A for ; Tue, 22 Dec 2020 14:58:54 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6BA24A1B; Tue, 22 Dec 2020 14:58:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1608645534; bh=OBNrnrqJW2DnMs6EmJ5KgbhJTJpvqM8D+XBPKjpj6dU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P2FLc5/wWnZefv7+YiDyQPL9IfDBLN79qCjawNESkbnwlchEPHJnfaTLj3uWfHXFT dULD3jQt1IaZBBJEdcvhUqfIGwdnnXWlVy/qHhwUaWg0vZ3mKxp/xC0TaZZYR56uTG rnpUmezWyuqmXOmUu7Fy3SG9peN9Veuzws645Vns= From: Kieran Bingham To: libcamera devel Date: Tue, 22 Dec 2020 13:58:48 +0000 Message-Id: <20201222135849.38052-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201222135849.38052-1-kieran.bingham@ideasonboard.com> References: <20201222135849.38052-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] test: file: Check that directories are not treated as files X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Directories can not be opened as a file, so the exists() check should not return true for a path which points to a directory. Directories are not handled by the File class. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/file.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/file.cpp b/test/file.cpp index f458f355ccad..b80667ae5b2f 100644 --- a/test/file.cpp +++ b/test/file.cpp @@ -49,6 +49,11 @@ protected: return TestFail; } + if (File::exists("/dev")) { + cerr << "Directories should not be treated as files" << endl; + return TestFail; + } + /* Test unnamed file. */ File file; From patchwork Tue Dec 22 13:58:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10695 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0EAC1C0F1A for ; Tue, 22 Dec 2020 13:58:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 42A45615B0; Tue, 22 Dec 2020 14:58:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="n1+azX+g"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D6E6615AC for ; Tue, 22 Dec 2020 14:58:55 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B9B89122D; Tue, 22 Dec 2020 14:58:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1608645534; bh=R4Wh/zlrA6x3NiPzgk5P/f3VImanYz6p9nc32FLlknA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n1+azX+gvZQLN07jOhMLMfuQ1C+gqw+B16UeNwfUtiWJGK7zul8aI6pAcqGHV+O6R CUmC9+slT204qWGnFjmsC/h8dQqF1hVvqZUPQZbEvp1xxLzP/+7TU04o85BkCVYEy+ fi7EzXu5ksfoYhtoIcu53EMlDYs/cxuoE0cI0QVE= From: Kieran Bingham To: libcamera devel Date: Tue, 22 Dec 2020 13:58:49 +0000 Message-Id: <20201222135849.38052-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201222135849.38052-1-kieran.bingham@ideasonboard.com> References: <20201222135849.38052-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: file: Check files exist() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Ensure that when we check for existence with File() it will only return if the path leads to a file, and not a directory. Device nodes which could still be opened by this class are still supported. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/file.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/file.cpp b/src/libcamera/file.cpp index 3a3f5bb63ffc..bce2b6138239 100644 --- a/src/libcamera/file.cpp +++ b/src/libcamera/file.cpp @@ -458,7 +458,8 @@ bool File::exists(const std::string &name) if (ret < 0) return false; - return true; + /* Directories can not be handled here, even if they exist. */ + return !S_ISDIR(st.st_mode); } } /* namespace libcamera */