[v18,12/12] config: Check configuration file version
diff mbox series

Message ID 20250912142915.53949-14-mzamazal@redhat.com
State Accepted
Headers show
Series
  • Add global configuration file
Related show

Commit Message

Milan Zamazal Sept. 12, 2025, 2:29 p.m. UTC
We don't know what the future versions of the configuration file will
look like.  The current code can process only version 1; let's check
that the read configuration is of this version.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 src/libcamera/global_configuration.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Laurent Pinchart Sept. 21, 2025, 1:07 a.m. UTC | #1
Hi Milan,

Thank you for the patch.

On Fri, Sep 12, 2025 at 04:29:14PM +0200, Milan Zamazal wrote:
> We don't know what the future versions of the configuration file will
> look like.  The current code can process only version 1; let's check
> that the read configuration is of this version.
> 
> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
> ---
>  src/libcamera/global_configuration.cpp | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/libcamera/global_configuration.cpp b/src/libcamera/global_configuration.cpp
> index 8c2670e03..2eec45363 100644
> --- a/src/libcamera/global_configuration.cpp
> +++ b/src/libcamera/global_configuration.cpp
> @@ -67,6 +67,15 @@ bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)
>  		return true;
>  	}
>  
> +	const std::optional<int> version = (*configuration)["version"].get<int>();
> +	if (version != 1) {
> +		LOG(Configuration, Error)
> +			<< "Failed to read configuration file due to unsupported version "

s/read/load/

I'll fix this when applying.

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

> +			<< (version ? std::to_string(version.value()) : "\"unspecified\"")
> +			<< ", expected version 1";
> +		return true;
> +	}
> +
>  	yamlConfiguration_ = std::move(configuration);
>  	return true;
>  }

Patch
diff mbox series

diff --git a/src/libcamera/global_configuration.cpp b/src/libcamera/global_configuration.cpp
index 8c2670e03..2eec45363 100644
--- a/src/libcamera/global_configuration.cpp
+++ b/src/libcamera/global_configuration.cpp
@@ -67,6 +67,15 @@  bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName)
 		return true;
 	}
 
+	const std::optional<int> version = (*configuration)["version"].get<int>();
+	if (version != 1) {
+		LOG(Configuration, Error)
+			<< "Failed to read configuration file due to unsupported version "
+			<< (version ? std::to_string(version.value()) : "\"unspecified\"")
+			<< ", expected version 1";
+		return true;
+	}
+
 	yamlConfiguration_ = std::move(configuration);
 	return true;
 }