diff mbox series

core: don't unlink if final equals temp location

Message ID 20170920153433.15343-1-christian.storm@siemens.com
State Accepted
Headers show
Series core: don't unlink if final equals temp location | expand

Commit Message

Storm, Christian Sept. 20, 2017, 3:34 p.m. UTC
If the temporary location of an artifact happens to
be identical to the final location of the artifact,
SWUpdate deletes the artifact after installation
(if CONFIG_NOCLEANUP isn't set, that is).

Consider the following sw-description with default
TMPDIR=/tmp set:

software =
{
    version = "0.0.1";
    files: (
        {
            filename = "dummy.file";
            path = "/tmp/dummy.file";
        }
    );
}

After installation, /tmp/dummy.file will be removed.
Prevent its removal and issue a warning. Additionally,
if dummy.file is referenced more than once, issue a
warning stating its removal reason.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 corelib/installer.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Comments

Stefano Babic Sept. 22, 2017, 9:37 a.m. UTC | #1
On 20/09/2017 17:34, Christian Storm wrote:
> If the temporary location of an artifact happens to
> be identical to the final location of the artifact,
> SWUpdate deletes the artifact after installation
> (if CONFIG_NOCLEANUP isn't set, that is).
> 
> Consider the following sw-description with default
> TMPDIR=/tmp set:
> 
> software =
> {
>     version = "0.0.1";
>     files: (
>         {
>             filename = "dummy.file";
>             path = "/tmp/dummy.file";
>         }
>     );
> }
> 
> After installation, /tmp/dummy.file will be removed.
> Prevent its removal and issue a warning. Additionally,
> if dummy.file is referenced more than once, issue a
> warning stating its removal reason.
> 
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
>  corelib/installer.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/corelib/installer.c b/corelib/installer.c
> index 8a188a1..6c6271c 100644
> --- a/corelib/installer.c
> +++ b/corelib/installer.c
> @@ -326,7 +326,23 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
>  				continue;
>  		}
>  
> -		ret = install_single_image(img);
> +		if (strncmp(img->path, img->extract_file, sizeof(img->path)) == 0) {
> +			struct img_type *tmpimg;
> +			WARN("Temporary and final location for %s is identical, skip "
> +			     "processing.", img->path);
> +			LIST_REMOVE(img, next);
> +			LIST_FOREACH(tmpimg, &sw->images, next) {
> +				if (strncmp(tmpimg->fname, img->fname, sizeof(img->fname)) == 0) {
> +					WARN("%s will be removed, it's referenced more "
> +					     "than once.", img->path);
> +					break;
> +				}
> +			}
> +			free(img);
> +			ret = 0;
> +		} else {
> +			ret = install_single_image(img);
> +		}
>  
>  		if (!fromfile)
>  			close(img->fdin);
> 

Applied to -master, thanks!

Best regards,
Stefano Babic
Storm, Christian Sept. 27, 2017, 12:37 p.m. UTC | #2
Hi Stefano,

> On 20/09/2017 17:34, Christian Storm wrote:
> > If the temporary location of an artifact happens to
> > be identical to the final location of the artifact,
> > SWUpdate deletes the artifact after installation
> > (if CONFIG_NOCLEANUP isn't set, that is).
> > 
> > Consider the following sw-description with default
> > TMPDIR=/tmp set:
> > 
> > software =
> > {
> >     version = "0.0.1";
> >     files: (
> >         {
> >             filename = "dummy.file";
> >             path = "/tmp/dummy.file";
> >         }
> >     );
> > }
> > 
> > After installation, /tmp/dummy.file will be removed.
> > Prevent its removal and issue a warning. Additionally,
> > if dummy.file is referenced more than once, issue a
> > warning stating its removal reason.
> > 
> > Signed-off-by: Christian Storm <christian.storm@siemens.com>
> > ---
> >  corelib/installer.c | 18 +++++++++++++++++-
> >  1 file changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/corelib/installer.c b/corelib/installer.c
> > index 8a188a1..6c6271c 100644
> > --- a/corelib/installer.c
> > +++ b/corelib/installer.c
> > @@ -326,7 +326,23 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
> >  				continue;
> >  		}
> >  
> > -		ret = install_single_image(img);
> > +		if (strncmp(img->path, img->extract_file, sizeof(img->path)) == 0) {
> > +			struct img_type *tmpimg;
> > +			WARN("Temporary and final location for %s is identical, skip "
> > +			     "processing.", img->path);
> > +			LIST_REMOVE(img, next);
> > +			LIST_FOREACH(tmpimg, &sw->images, next) {
> > +				if (strncmp(tmpimg->fname, img->fname, sizeof(img->fname)) == 0) {
> > +					WARN("%s will be removed, it's referenced more "
> > +					     "than once.", img->path);
> > +					break;
> > +				}
> > +			}
> > +			free(img);
> > +			ret = 0;
> > +		} else {
> > +			ret = install_single_image(img);
> > +		}
> >  
> >  		if (!fromfile)
> >  			close(img->fdin);
> > 
> 
> Applied to -master, thanks!

Hm, I cannot find it upstream on -master and it's gone in patchwork
as well. Am I bind or has it slipped through?


Kind regards,
   Christian
Stefano Babic Sept. 27, 2017, 12:44 p.m. UTC | #3
On 27/09/2017 14:37, Christian Storm wrote:
> Hi Stefano,
> 
>> On 20/09/2017 17:34, Christian Storm wrote:
>>> If the temporary location of an artifact happens to
>>> be identical to the final location of the artifact,
>>> SWUpdate deletes the artifact after installation
>>> (if CONFIG_NOCLEANUP isn't set, that is).
>>>
>>> Consider the following sw-description with default
>>> TMPDIR=/tmp set:
>>>
>>> software =
>>> {
>>>     version = "0.0.1";
>>>     files: (
>>>         {
>>>             filename = "dummy.file";
>>>             path = "/tmp/dummy.file";
>>>         }
>>>     );
>>> }
>>>
>>> After installation, /tmp/dummy.file will be removed.
>>> Prevent its removal and issue a warning. Additionally,
>>> if dummy.file is referenced more than once, issue a
>>> warning stating its removal reason.
>>>
>>> Signed-off-by: Christian Storm <christian.storm@siemens.com>
>>> ---
>>>  corelib/installer.c | 18 +++++++++++++++++-
>>>  1 file changed, 17 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/corelib/installer.c b/corelib/installer.c
>>> index 8a188a1..6c6271c 100644
>>> --- a/corelib/installer.c
>>> +++ b/corelib/installer.c
>>> @@ -326,7 +326,23 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
>>>  				continue;
>>>  		}
>>>  
>>> -		ret = install_single_image(img);
>>> +		if (strncmp(img->path, img->extract_file, sizeof(img->path)) == 0) {
>>> +			struct img_type *tmpimg;
>>> +			WARN("Temporary and final location for %s is identical, skip "
>>> +			     "processing.", img->path);
>>> +			LIST_REMOVE(img, next);
>>> +			LIST_FOREACH(tmpimg, &sw->images, next) {
>>> +				if (strncmp(tmpimg->fname, img->fname, sizeof(img->fname)) == 0) {
>>> +					WARN("%s will be removed, it's referenced more "
>>> +					     "than once.", img->path);
>>> +					break;
>>> +				}
>>> +			}
>>> +			free(img);
>>> +			ret = 0;
>>> +		} else {
>>> +			ret = install_single_image(img);
>>> +		}
>>>  
>>>  		if (!fromfile)
>>>  			close(img->fdin);
>>>
>>
>> Applied to -master, thanks!
> 
> Hm, I cannot find it upstream on -master and it's gone in patchwork
> as well. Am I bind or has it slipped through?

I do not know what went wrong - I picked it up again and pushedit, thanks !

Best regards,
Stefano
diff mbox series

Patch

diff --git a/corelib/installer.c b/corelib/installer.c
index 8a188a1..6c6271c 100644
--- a/corelib/installer.c
+++ b/corelib/installer.c
@@ -326,7 +326,23 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 				continue;
 		}
 
-		ret = install_single_image(img);
+		if (strncmp(img->path, img->extract_file, sizeof(img->path)) == 0) {
+			struct img_type *tmpimg;
+			WARN("Temporary and final location for %s is identical, skip "
+			     "processing.", img->path);
+			LIST_REMOVE(img, next);
+			LIST_FOREACH(tmpimg, &sw->images, next) {
+				if (strncmp(tmpimg->fname, img->fname, sizeof(img->fname)) == 0) {
+					WARN("%s will be removed, it's referenced more "
+					     "than once.", img->path);
+					break;
+				}
+			}
+			free(img);
+			ret = 0;
+		} else {
+			ret = install_single_image(img);
+		}
 
 		if (!fromfile)
 			close(img->fdin);