From 499dd2ce838a330b8f0f01aad7d24a24547622e0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 20 Sep 2018 15:38:26 +0200 Subject: [PATCH] [fsresizer] Document configuration - Add some notes on configuration of fsresizer - Convenience methods for checking validity. --- src/modules/fsresizer/ResizeFSJob.cpp | 5 +++++ src/modules/fsresizer/ResizeFSJob.h | 17 +++++++++++++++++ src/modules/fsresizer/fsresizer.conf | 5 ++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/modules/fsresizer/ResizeFSJob.cpp b/src/modules/fsresizer/ResizeFSJob.cpp index e10894c30..925301e42 100644 --- a/src/modules/fsresizer/ResizeFSJob.cpp +++ b/src/modules/fsresizer/ResizeFSJob.cpp @@ -85,6 +85,11 @@ ResizeFSJob::prettyName() const Calamares::JobResult ResizeFSJob::exec() { + if ( !isValid() ) + return Calamares::JobResult::error( + tr( "Invalid configuration" ), + tr( "The file-system resize job has an invalid configuration " + "and will not run." ) ); return Calamares::JobResult::ok(); } diff --git a/src/modules/fsresizer/ResizeFSJob.h b/src/modules/fsresizer/ResizeFSJob.h index 415d04c81..6308f12ed 100644 --- a/src/modules/fsresizer/ResizeFSJob.h +++ b/src/modules/fsresizer/ResizeFSJob.h @@ -33,6 +33,12 @@ class PLUGINDLLEXPORT ResizeFSJob : public Calamares::CppJob Q_OBJECT public: + /** @brief Size expressions + * + * Sizes can be specified in MiB or percent (of the device they + * are on). This class handles parsing of such strings from the + * config file. + */ class RelativeSize { public: @@ -49,6 +55,11 @@ public: int value() const { return m_value; } Unit unit() const { return m_unit; } + constexpr bool isValid() const + { + return ( unit() != None ) && ( value() > 0 ); + } + private: int m_value; Unit m_unit; @@ -63,6 +74,12 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; + constexpr bool isValid() const + { + return ( !m_fsname.isEmpty() || !m_devicename.isEmpty() ) && + m_size.isValid(); + } + private: RelativeSize m_size; RelativeSize m_atleast; diff --git a/src/modules/fsresizer/fsresizer.conf b/src/modules/fsresizer/fsresizer.conf index 5a5700a79..f02983e45 100644 --- a/src/modules/fsresizer/fsresizer.conf +++ b/src/modules/fsresizer/fsresizer.conf @@ -21,10 +21,13 @@ fs: / # in percent, so set it to 100. Perhaps a fixed size is # needed (that would be weird though, since you don't know # how big the card is), use MiB as suffix in that case. +# If missing, then it's assumed to be 0, and no resizing +# will happen. size: 100% # Resizing might not be worth it, though. Set the minimum # that it must grow; if it cannot grow that much, the # resizing is skipped. Can be in percentage or absolute -# size, as above. +# size, as above. If missing, then it's assumed to be 0, +# which means resizing is always worthwhile. atleast: 1000MiB