diff mbox series

[1/5] parser: Check image version after parsing to remove skipped images

Message ID 1516715761-3043-1-git-send-email-stefan@herbrechtsmeier.net
State Accepted
Headers show
Series [1/5] parser: Check image version after parsing to remove skipped images | expand

Commit Message

Stefan Herbrechtsmeier Jan. 23, 2018, 1:55 p.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Remove skipped images after parsing because they are removed anyway.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

 core/parser.c              | 47 +++++++++++++++++++++++++++++++++++++++++++
 corelib/installer.c        | 50 ----------------------------------------------
 corelib/stream_interface.c |  2 --
 include/installer.h        |  1 -
 4 files changed, 47 insertions(+), 53 deletions(-)

Comments

Stefano Babic Jan. 24, 2018, 9:27 a.m. UTC | #1
On 23/01/2018 14:55, stefan@herbrechtsmeier.net wrote:
> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> Remove skipped images after parsing because they are removed anyway.
> 
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> ---
> 
>  core/parser.c              | 47 +++++++++++++++++++++++++++++++++++++++++++
>  corelib/installer.c        | 50 ----------------------------------------------
>  corelib/stream_interface.c |  2 --
>  include/installer.h        |  1 -
>  4 files changed, 47 insertions(+), 53 deletions(-)
> 
> diff --git a/core/parser.c b/core/parser.c
> index 0df960f..0edbe1b 100644
> --- a/core/parser.c
> +++ b/core/parser.c
> @@ -130,6 +130,51 @@ static int check_handler_list(struct imglist *list,
>  	return 0;
>  }
>  
> +static int is_image_installed(struct swver *sw_ver_list,
> +				struct img_type *img)
> +{
> +	struct sw_version *swver;
> +
> +	if (!sw_ver_list)
> +		return false;
> +
> +	if (!strlen(img->id.name) || !strlen(img->id.version) ||
> +		!img->id.install_if_different)
> +		return false;
> +
> +	LIST_FOREACH(swver, sw_ver_list, next) {
> +		/*
> +		 * Check if name and version are identical
> +		 */
> +		if (!strncmp(img->id.name, swver->name, sizeof(img->id.name)) &&
> +		    !strncmp(img->id.version, swver->version, sizeof(img->id.version))) {
> +			TRACE("%s(%s) already installed, skipping...",
> +				img->id.name,
> +				img->id.version);
> +
> +			return true;
> +		}
> +	}
> +
> +	return false;
> +}
> +
> +/*
> + * Remove the image if the same version is already installed
> + */
> +static void remove_installed_image_list(struct imglist *img_list,
> +				struct swver *sw_ver_list)
> +{
> +	struct img_type *img;
> +
> +	LIST_FOREACH(img, img_list, next) {
> +		if (is_image_installed(sw_ver_list, img)) {
> +			LIST_REMOVE(img, next);
> +			free(img);
> +		}
> +	}
> +}
> +
>  int parse(struct swupdate_cfg *sw, const char *descfile)
>  {
>  	int ret = -1;
> @@ -204,6 +249,8 @@ int parse(struct swupdate_cfg *sw, const char *descfile)
>  #endif
>  #endif
>  
> +	remove_installed_image_list(&sw->images, &sw->installed_sw_list);
> +
>  	/*
>  	 * Compute the total number of installer
>  	 * to initialize the progress bar
> diff --git a/corelib/installer.c b/corelib/installer.c
> index f92ade9..c630b9d 100644
> --- a/corelib/installer.c
> +++ b/corelib/installer.c
> @@ -32,34 +32,6 @@
>  #include "bootloader.h"
>  #include "progress.h"
>  
> -static int isImageInstalled(struct swver *sw_ver_list,
> -				struct img_type *img)
> -{
> -	struct sw_version *swver;
> -
> -	if (!sw_ver_list)
> -		return false;
> -
> -	if (!strlen(img->id.name) || !strlen(img->id.version) ||
> -		!img->id.install_if_different)
> -		return false;
> -
> -	LIST_FOREACH(swver, sw_ver_list, next) {
> -		/*
> -		 * Check if name and version are identical
> -		 */
> -		if (!strncmp(img->id.name, swver->name, sizeof(img->id.name)) &&
> -		    !strncmp(img->id.version, swver->version, sizeof(img->id.version))) {
> -			TRACE("%s(%s) already installed, skipping...",
> -				img->id.name,
> -				img->id.version);
> -			return true;
> -		}
> -	}
> -
> -	return false;
> -}
> -
>  /*
>   * function returns:
>   * 0 = do not skip the file, it must be installed
> @@ -68,7 +40,6 @@ static int isImageInstalled(struct swver *sw_ver_list,
>   * -1= error found
>   */
>  int check_if_required(struct imglist *list, struct filehdr *pfdh,
> -				struct swver *sw_ver_list,
>  				const char *destdir,
>  				struct img_type **pimg)
>  {
> @@ -82,20 +53,6 @@ int check_if_required(struct imglist *list, struct filehdr *pfdh,
>  
>  	LIST_FOREACH(img, list, next) {
>  		if (strcmp(pfdh->filename, img->fname) == 0) {
> -
> -			/*
> -			 * Check the version. If this artifact is
> -			 * installed in the same version on the system,
> -			 * skip it
> -			 */
> -			if (isImageInstalled(sw_ver_list, img)) {
> -				/*
> -				 *  drop this from the list of images to be installed
> -				 */
> -				LIST_REMOVE(img, next);
> -				continue;
> -			}
> -
>  			skip = COPY_FILE;
>  			img->provided = 1;
>  			img->size = (unsigned int)pfdh->size;
> @@ -362,13 +319,6 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
>  			img->size = fdh.size;
>  			img->checksum = fdh.chksum;
>  			img->fdin = fdsw;
> -
> -			/*
> -			 * Skip if the image in the same version is already
> -			 * installed
> -			 */
> -			if (isImageInstalled(&sw->installed_sw_list, img))
> -				continue;
>  		}
>  
>  		if ((strlen(img->path) > 0) &&
> diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c
> index a5fd4a1..91f523f 100644
> --- a/corelib/stream_interface.c
> +++ b/corelib/stream_interface.c
> @@ -179,8 +179,6 @@ static int extract_files(int fd, struct swupdate_cfg *software)
>  
>  			for (unsigned int i = 0; i < ARRAY_SIZE(list); i++) {
>  				skip = check_if_required(list[i], &fdh,
> -						(list[i] == &software->images) ?
> -							&software->installed_sw_list : NULL,
>  						get_tmpdir(),
>  						&img);
>  
> diff --git a/include/installer.h b/include/installer.h
> index fc31c52..ab83691 100644
> --- a/include/installer.h
> +++ b/include/installer.h
> @@ -14,7 +14,6 @@
>  #include "cpiohdr.h"
>  
>  int check_if_required(struct imglist *list, struct filehdr *pfdh,
> -				struct swver *sw_ver_list,
>  				const char *destdir,
>  				struct img_type **pimg);
>  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile);
> 

It looks good !

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
Stefano Babic Jan. 26, 2018, 9:26 a.m. UTC | #2
On 23/01/2018 14:55, stefan@herbrechtsmeier.net wrote:
> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> Remove skipped images after parsing because they are removed anyway.
> 
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> ---
> 

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/core/parser.c b/core/parser.c
index 0df960f..0edbe1b 100644
--- a/core/parser.c
+++ b/core/parser.c
@@ -130,6 +130,51 @@  static int check_handler_list(struct imglist *list,
 	return 0;
 }
 
+static int is_image_installed(struct swver *sw_ver_list,
+				struct img_type *img)
+{
+	struct sw_version *swver;
+
+	if (!sw_ver_list)
+		return false;
+
+	if (!strlen(img->id.name) || !strlen(img->id.version) ||
+		!img->id.install_if_different)
+		return false;
+
+	LIST_FOREACH(swver, sw_ver_list, next) {
+		/*
+		 * Check if name and version are identical
+		 */
+		if (!strncmp(img->id.name, swver->name, sizeof(img->id.name)) &&
+		    !strncmp(img->id.version, swver->version, sizeof(img->id.version))) {
+			TRACE("%s(%s) already installed, skipping...",
+				img->id.name,
+				img->id.version);
+
+			return true;
+		}
+	}
+
+	return false;
+}
+
+/*
+ * Remove the image if the same version is already installed
+ */
+static void remove_installed_image_list(struct imglist *img_list,
+				struct swver *sw_ver_list)
+{
+	struct img_type *img;
+
+	LIST_FOREACH(img, img_list, next) {
+		if (is_image_installed(sw_ver_list, img)) {
+			LIST_REMOVE(img, next);
+			free(img);
+		}
+	}
+}
+
 int parse(struct swupdate_cfg *sw, const char *descfile)
 {
 	int ret = -1;
@@ -204,6 +249,8 @@  int parse(struct swupdate_cfg *sw, const char *descfile)
 #endif
 #endif
 
+	remove_installed_image_list(&sw->images, &sw->installed_sw_list);
+
 	/*
 	 * Compute the total number of installer
 	 * to initialize the progress bar
diff --git a/corelib/installer.c b/corelib/installer.c
index f92ade9..c630b9d 100644
--- a/corelib/installer.c
+++ b/corelib/installer.c
@@ -32,34 +32,6 @@ 
 #include "bootloader.h"
 #include "progress.h"
 
-static int isImageInstalled(struct swver *sw_ver_list,
-				struct img_type *img)
-{
-	struct sw_version *swver;
-
-	if (!sw_ver_list)
-		return false;
-
-	if (!strlen(img->id.name) || !strlen(img->id.version) ||
-		!img->id.install_if_different)
-		return false;
-
-	LIST_FOREACH(swver, sw_ver_list, next) {
-		/*
-		 * Check if name and version are identical
-		 */
-		if (!strncmp(img->id.name, swver->name, sizeof(img->id.name)) &&
-		    !strncmp(img->id.version, swver->version, sizeof(img->id.version))) {
-			TRACE("%s(%s) already installed, skipping...",
-				img->id.name,
-				img->id.version);
-			return true;
-		}
-	}
-
-	return false;
-}
-
 /*
  * function returns:
  * 0 = do not skip the file, it must be installed
@@ -68,7 +40,6 @@  static int isImageInstalled(struct swver *sw_ver_list,
  * -1= error found
  */
 int check_if_required(struct imglist *list, struct filehdr *pfdh,
-				struct swver *sw_ver_list,
 				const char *destdir,
 				struct img_type **pimg)
 {
@@ -82,20 +53,6 @@  int check_if_required(struct imglist *list, struct filehdr *pfdh,
 
 	LIST_FOREACH(img, list, next) {
 		if (strcmp(pfdh->filename, img->fname) == 0) {
-
-			/*
-			 * Check the version. If this artifact is
-			 * installed in the same version on the system,
-			 * skip it
-			 */
-			if (isImageInstalled(sw_ver_list, img)) {
-				/*
-				 *  drop this from the list of images to be installed
-				 */
-				LIST_REMOVE(img, next);
-				continue;
-			}
-
 			skip = COPY_FILE;
 			img->provided = 1;
 			img->size = (unsigned int)pfdh->size;
@@ -362,13 +319,6 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 			img->size = fdh.size;
 			img->checksum = fdh.chksum;
 			img->fdin = fdsw;
-
-			/*
-			 * Skip if the image in the same version is already
-			 * installed
-			 */
-			if (isImageInstalled(&sw->installed_sw_list, img))
-				continue;
 		}
 
 		if ((strlen(img->path) > 0) &&
diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c
index a5fd4a1..91f523f 100644
--- a/corelib/stream_interface.c
+++ b/corelib/stream_interface.c
@@ -179,8 +179,6 @@  static int extract_files(int fd, struct swupdate_cfg *software)
 
 			for (unsigned int i = 0; i < ARRAY_SIZE(list); i++) {
 				skip = check_if_required(list[i], &fdh,
-						(list[i] == &software->images) ?
-							&software->installed_sw_list : NULL,
 						get_tmpdir(),
 						&img);
 
diff --git a/include/installer.h b/include/installer.h
index fc31c52..ab83691 100644
--- a/include/installer.h
+++ b/include/installer.h
@@ -14,7 +14,6 @@ 
 #include "cpiohdr.h"
 
 int check_if_required(struct imglist *list, struct filehdr *pfdh,
-				struct swver *sw_ver_list,
 				const char *destdir,
 				struct img_type **pimg);
 int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile);