[libcamera-devel,1/2] test: file: Check that directories are not treated as files
diff mbox series

Message ID 20201222135849.38052-2-kieran.bingham@ideasonboard.com
State Accepted
Commit 8f4e16f014c820a0ecb85e28453b88c277bc859f
Delegated to: Kieran Bingham
Headers show
Series
  • libcamera: file: Don't parse directories
Related show

Commit Message

Kieran Bingham Dec. 22, 2020, 1:58 p.m. UTC
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 <kieran.bingham@ideasonboard.com>
---
 test/file.cpp | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Laurent Pinchart Dec. 22, 2020, 3:51 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Tue, Dec 22, 2020 at 01:58:48PM +0000, Kieran Bingham wrote:
> 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 <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  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;
>
Niklas Söderlund Dec. 27, 2020, 10:53 a.m. UTC | #2
Hi Kieran,

On 2020-12-22 13:58:48 +0000, Kieran Bingham wrote:
> 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 <kieran.bingham@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  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;
>  
> -- 
> 2.25.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch
diff mbox series

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;