Fix cpio -Hustar -o

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Fix cpio -Hustar -o

Christian Weisgerber
I found this discrepancy surprising:

$ find /bin -print | cpio -o -Hustar >foo
$ file foo
foo: POSIX tar archive
$ find /bin -print | cpio -Hustar -o >foo
$ file foo                                
foo: ASCII cpio archive (SVR4 with CRC)

The argument order should not matter here.

Fix: When processing the -o switch, only set the archive format if
not already set.

ok?

Index: bin/pax/options.c
===================================================================
RCS file: /cvs/src/bin/pax/options.c,v
retrieving revision 1.102
diff -u -p -r1.102 options.c
--- bin/pax/options.c 13 Sep 2018 12:33:43 -0000 1.102
+++ bin/pax/options.c 14 Nov 2019 20:59:04 -0000
@@ -1226,7 +1226,8 @@ cpio_options(int argc, char **argv)
  * create an archive
  */
  act = ARCHIVE;
- frmt = &(fsub[F_CPIO]);
+ if (frmt == NULL)
+ frmt = &(fsub[F_CPIO]);
  break;
  case 'p':
  /*
--
Christian "naddy" Weisgerber                          [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Fix cpio -Hustar -o

Klemens Nanni-2
On Thu, Nov 14, 2019 at 10:09:20PM +0100, Christian Weisgerber wrote:
> The argument order should not matter here.
The synopsis however seems to dictate it coming first:

cpio -o [-AaBcjLvZz] [-C bytes] [-F archive] [-H format] [-O archive]
     < name-list [> archive]
cpio -i [-6BbcdfjmrSstuvZz] [-C bytes] [-E file] [-F archive] [-H format]
     [-I archive] [pattern ...] [< archive]
cpio -p [-adLlmuv] destination-directory < name-list

Are -o/-i/-p each coming first to properly separate the three use cases
or doas that actually mean "-o must come first"?

Reply | Threaded
Open this post in threaded view
|

Re: Fix cpio -Hustar -o

Christian Weisgerber
Klemens Nanni:

> cpio -o [-AaBcjLvZz] [-C bytes] [-F archive] [-H format] [-O archive]
>      < name-list [> archive]
> cpio -i [-6BbcdfjmrSstuvZz] [-C bytes] [-E file] [-F archive] [-H format]
>      [-I archive] [pattern ...] [< archive]
> cpio -p [-adLlmuv] destination-directory < name-list
>
> Are -o/-i/-p each coming first to properly separate the three use cases

Exactly.

--
Christian "naddy" Weisgerber                          [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Fix cpio -Hustar -o

Philip Guenther-2
In reply to this post by Christian Weisgerber
On Thu, Nov 14, 2019 at 1:36 PM Christian Weisgerber <[hidden email]>
wrote:

> I found this discrepancy surprising:
>
> $ find /bin -print | cpio -o -Hustar >foo
> $ file foo
> foo: POSIX tar archive
> $ find /bin -print | cpio -Hustar -o >foo
> $ file foo
> foo: ASCII cpio archive (SVR4 with CRC)
>
> The argument order should not matter here.
>
> Fix: When processing the -o switch, only set the archive format if
> not already set.
>
> ok?
>
> Index: bin/pax/options.c
> ===================================================================
> RCS file: /cvs/src/bin/pax/options.c,v
> retrieving revision 1.102
> diff -u -p -r1.102 options.c
> --- bin/pax/options.c   13 Sep 2018 12:33:43 -0000      1.102
> +++ bin/pax/options.c   14 Nov 2019 20:59:04 -0000
> @@ -1226,7 +1226,8 @@ cpio_options(int argc, char **argv)
>                                  * create an archive
>                                  */
>                                 act = ARCHIVE;
> -                               frmt = &(fsub[F_CPIO]);
> +                               if (frmt == NULL)
> +                                       frmt = &(fsub[F_CPIO]);
>                                 break;
>                         case 'p':
>                                 /*
>

ok guenther@