diff mbox series

COPY handler: rm FTW_CONTINUE and FTW_STOP

Message ID 20250516143048.2962050-1-joakim.tjernlund@infinera.com
State Rejected
Delegated to: Stefano Babic
Headers show
Series COPY handler: rm FTW_CONTINUE and FTW_STOP | expand

Commit Message

Joakim Tjernlund May 16, 2025, 2:30 p.m. UTC
These are a GNU extension not preset in MUSL. FTW_ACTIONRETVAL flag
must be passed to use it. As this flag is missing we can replace
FTW_CONTINUE and FTW_STOP with 0 resp. 1 and maintain same function.

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
 handlers/copy_handler.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Stefano Babic May 16, 2025, 2:34 p.m. UTC | #1
On 5/16/25 16:30, 'Joakim Tjernlund' via swupdate wrote:
> These are a GNU extension not preset in MUSL. FTW_ACTIONRETVAL flag
> must be passed to use it. As this flag is missing we can replace
> FTW_CONTINUE and FTW_STOP with 0 resp. 1 and maintain same function.
> 

...or add defines into include.h (or even here) in case they are not 
defined....

> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> ---
>   handlers/copy_handler.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
> index 222bc9f5..bea0899e 100644
> --- a/handlers/copy_handler.c
> +++ b/handlers/copy_handler.c
> @@ -151,7 +151,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
>   	char *dst;
>   	struct stat statbufdst;
>   	struct img_type cpyimg;
> -	int ret, result = FTW_CONTINUE;
> +	int ret, result = 0;
>   
>   	if (strstr(fpath, copyfrom) != fpath)
>   		return result;
> @@ -159,7 +159,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
>   	relpath = fpath + strlen(copyfrom);
>   
>   	if (!strlen(relpath))
> -		return FTW_CONTINUE;
> +		return 0;
>   
>   	dst = malloc(strlen(base_img->path) + strlen(relpath) + 1);
>   	strcpy(dst, base_img->path);
> @@ -189,7 +189,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
>   		 */
>   		swupdate_progress_addstep();
>   		if (copy_single_file(fpath, 0, &cpyimg, chained_handler))
> -			result = FTW_STOP;
> +			result = 1;
>   	}
>   
>   	free(dst);
Joakim Tjernlund (Nokia) May 16, 2025, 4:17 p.m. UTC | #2
On Fri, 2025-05-16 at 16:34 +0200, Stefano Babic wrote:
> On 5/16/25 16:30, 'Joakim Tjernlund' via swupdate wrote:
> > These are a GNU extension not preset in MUSL. FTW_ACTIONRETVAL flag
> > must be passed to use it. As this flag is missing we can replace
> > FTW_CONTINUE and FTW_STOP with 0 resp. 1 and maintain same function.
> > 
> 
> ...or add defines into include.h (or even here) in case they are not 
> defined....

But here they are wrongly used even for GNU, you can only use these if you set FTW_ACTIONRETVAL
Making #defines will hide errors if someone tries adds FTW_ACTIONRETVAL later

  Jocke
> 
> > Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> > ---
> >   handlers/copy_handler.c | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
> > index 222bc9f5..bea0899e 100644
> > --- a/handlers/copy_handler.c
> > +++ b/handlers/copy_handler.c
> > @@ -151,7 +151,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
> >   	char *dst;
> >   	struct stat statbufdst;
> >   	struct img_type cpyimg;
> > -	int ret, result = FTW_CONTINUE;
> > +	int ret, result = 0;
> >   
> >   	if (strstr(fpath, copyfrom) != fpath)
> >   		return result;
> > @@ -159,7 +159,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
> >   	relpath = fpath + strlen(copyfrom);
> >   
> >   	if (!strlen(relpath))
> > -		return FTW_CONTINUE;
> > +		return 0;
> >   
> >   	dst = malloc(strlen(base_img->path) + strlen(relpath) + 1);
> >   	strcpy(dst, base_img->path);
> > @@ -189,7 +189,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
> >   		 */
> >   		swupdate_progress_addstep();
> >   		if (copy_single_file(fpath, 0, &cpyimg, chained_handler))
> > -			result = FTW_STOP;
> > +			result = 1;
> >   	}
> >   
> >   	free(dst);
Stefano Babic May 16, 2025, 9:45 p.m. UTC | #3
Hi Jocke,

On 16.05.25 18:17, 'Joakim Tjernlund (Nokia)' via swupdate wrote:
> On Fri, 2025-05-16 at 16:34 +0200, Stefano Babic wrote:
>> On 5/16/25 16:30, 'Joakim Tjernlund' via swupdate wrote:
>>> These are a GNU extension not preset in MUSL. FTW_ACTIONRETVAL flag
>>> must be passed to use it. As this flag is missing we can replace
>>> FTW_CONTINUE and FTW_STOP with 0 resp. 1 and maintain same function.
>>>
>>
>> ...or add defines into include.h (or even here) in case they are not
>> defined....
> 
> But here they are wrongly used even for GNU, you can only use these if you set FTW_ACTIONRETVAL
> Making #defines will hide errors if someone tries adds FTW_ACTIONRETVAL later

I am yet not understanding where is the issue. Commit 58a1ec0708 
addresses exactly this topic, and set FTW_CONTINUE and FTW_STOP in case 
they are not set, that is for MUSL ( as the commit message says).

Regards,
Stefano

> 
>    Jocke
>>
>>> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
>>> ---
>>>    handlers/copy_handler.c | 6 +++---
>>>    1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
>>> index 222bc9f5..bea0899e 100644
>>> --- a/handlers/copy_handler.c
>>> +++ b/handlers/copy_handler.c
>>> @@ -151,7 +151,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
>>>    	char *dst;
>>>    	struct stat statbufdst;
>>>    	struct img_type cpyimg;
>>> -	int ret, result = FTW_CONTINUE;
>>> +	int ret, result = 0;
>>>    
>>>    	if (strstr(fpath, copyfrom) != fpath)
>>>    		return result;
>>> @@ -159,7 +159,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
>>>    	relpath = fpath + strlen(copyfrom);
>>>    
>>>    	if (!strlen(relpath))
>>> -		return FTW_CONTINUE;
>>> +		return 0;
>>>    
>>>    	dst = malloc(strlen(base_img->path) + strlen(relpath) + 1);
>>>    	strcpy(dst, base_img->path);
>>> @@ -189,7 +189,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
>>>    		 */
>>>    		swupdate_progress_addstep();
>>>    		if (copy_single_file(fpath, 0, &cpyimg, chained_handler))
>>> -			result = FTW_STOP;
>>> +			result = 1;
>>>    	}
>>>    
>>>    	free(dst);
>
Joakim Tjernlund (Nokia) May 17, 2025, 1:35 p.m. UTC | #4
On Fri, 2025-05-16 at 23:45 +0200, Stefano Babic wrote:
> 
> Hi Jocke,

Hi again :)

> 
> On 16.05.25 18:17, 'Joakim Tjernlund (Nokia)' via swupdate wrote:
> > On Fri, 2025-05-16 at 16:34 +0200, Stefano Babic wrote:
> > > On 5/16/25 16:30, 'Joakim Tjernlund' via swupdate wrote:
> > > > These are a GNU extension not preset in MUSL. FTW_ACTIONRETVAL flag
> > > > must be passed to use it. As this flag is missing we can replace
> > > > FTW_CONTINUE and FTW_STOP with 0 resp. 1 and maintain same function.
> > > > 
> > > 
> > > ...or add defines into include.h (or even here) in case they are not
> > > defined....
> > 
> > But here they are wrongly used even for GNU, you can only use these if you set FTW_ACTIONRETVAL
> > Making #defines will hide errors if someone tries adds FTW_ACTIONRETVAL later
> 
> I am yet not understanding where is the issue. Commit 58a1ec0708
> addresses exactly this topic, and set FTW_CONTINUE and FTW_STOP in case
> they are not set, that is for MUSL ( as the commit message says).

Ahh, I was working of the 2024 release as that is what we currently use and
missed this :(

My point with just #defining FTW_CONTINUE/FTW_STOP is that it gives you the
impression that a developer could start using FTW_ACTIONRETVAL and that would
break on non glibc based systems.

Anyhow you have a fix already so you can drop this one.

 Regards
          Joakim


> Regards,
> Stefano
> 
> > 
> >    Jocke
> > > 
> > > > Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> > > > ---
> > > >    handlers/copy_handler.c | 6 +++---
> > > >    1 file changed, 3 insertions(+), 3 deletions(-)
> > > > 
> > > > diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
> > > > index 222bc9f5..bea0899e 100644
> > > > --- a/handlers/copy_handler.c
> > > > +++ b/handlers/copy_handler.c
> > > > @@ -151,7 +151,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
> > > >     char *dst;
> > > >     struct stat statbufdst;
> > > >     struct img_type cpyimg;
> > > > -   int ret, result = FTW_CONTINUE;
> > > > +   int ret, result = 0;
> > > > 
> > > >     if (strstr(fpath, copyfrom) != fpath)
> > > >             return result;
> > > > @@ -159,7 +159,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
> > > >     relpath = fpath + strlen(copyfrom);
> > > > 
> > > >     if (!strlen(relpath))
> > > > -           return FTW_CONTINUE;
> > > > +           return 0;
> > > > 
> > > >     dst = malloc(strlen(base_img->path) + strlen(relpath) + 1);
> > > >     strcpy(dst, base_img->path);
> > > > @@ -189,7 +189,7 @@ static int recurse_directory(const char *fpath, const struct stat *sb,
> > > >              */
> > > >             swupdate_progress_addstep();
> > > >             if (copy_single_file(fpath, 0, &cpyimg, chained_handler))
> > > > -                   result = FTW_STOP;
> > > > +                   result = 1;
> > > >     }
> > > > 
> > > >     free(dst);
> >
diff mbox series

Patch

diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
index 222bc9f5..bea0899e 100644
--- a/handlers/copy_handler.c
+++ b/handlers/copy_handler.c
@@ -151,7 +151,7 @@  static int recurse_directory(const char *fpath, const struct stat *sb,
 	char *dst;
 	struct stat statbufdst;
 	struct img_type cpyimg;
-	int ret, result = FTW_CONTINUE;
+	int ret, result = 0;
 
 	if (strstr(fpath, copyfrom) != fpath)
 		return result;
@@ -159,7 +159,7 @@  static int recurse_directory(const char *fpath, const struct stat *sb,
 	relpath = fpath + strlen(copyfrom);
 
 	if (!strlen(relpath))
-		return FTW_CONTINUE;
+		return 0;
 
 	dst = malloc(strlen(base_img->path) + strlen(relpath) + 1);
 	strcpy(dst, base_img->path);
@@ -189,7 +189,7 @@  static int recurse_directory(const char *fpath, const struct stat *sb,
 		 */
 		swupdate_progress_addstep();
 		if (copy_single_file(fpath, 0, &cpyimg, chained_handler))
-			result = FTW_STOP;
+			result = 1;
 	}
 
 	free(dst);