git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] tar: on extract, -o is --no-same-owner

From
DVDenys Vlasenko <vda.linux@googlemail.com>
Date
Oct 24, 2009, 23:32 UTC
Message-ID
<200910250132.04187.vda.linux@googlemail.com>
In-Reply-To
<m2ocnxt6jl.fsf@whitebox.home>
On Saturday 24 October 2009 12:44, Andreas Schwab wrote:
Show 16 quoted lines
> Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> writes:
> 
> > On Sat, Oct 24, 2009 at 11:49:10AM +0200, Andreas Schwab wrote:
> >>Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> writes:
> >>
> >>> I suppose xf - -o would work?
> >>
> >>Isn't that the same as 'xfo -'?
> >
> > Not really (if you do not permute the arguments which we don't in
> > busybox, for size reasons).
> 
> There is no argument permutation.  The traditional argument parsing of
> tar does not cluster option letters with option arguments.
> 
> Of course, just using 'xof -' will work around this busybox bug.

From my side, I prefer to squash that busybox bug. This is the second time people complain about it, so it is a reoccurring problem.

The attached patch has been pushed to busybox git.

function old new delta tar_main 702 751 +49

-- vda

diff -d -urpN busybox.0/archival/tar.c busybox.1/archival/tar.c --- busybox.0/archival/tar.c 2009-10-20 22:11:09.000000000 +0200 +++ busybox.1/archival/tar.c 2009-10-25 01:27:38.000000000 +0200

@@ -841,6 +841,33 @@ int tar_main(int argc UNUSED_PARAM, char
 #if ENABLE_FEATURE_TAR_LONG_OPTIONS
 	applet_long_options = tar_longopts;
 #endif
+#if ENABLE_DESKTOP
+	if (argv[1][0] != '-') {
+		/* Compat:
+		 * 1st argument without dash handles options with parameters
+		 * differently from dashed one: it takes *next argv[i]*
+		 * as paramenter even if there are more chars in 1st argument:
+		 *  "tar fx TARFILE" - "x" is not taken as f's param
+		 *  but is interpreted as -x option
+		 *  "tar -xf TARFILE" - dashed equivalent of the above
+		 *  "tar -fx ..." - "x" is taken as f's param
+		 * getopt32 wouldn't handle 1st command correctly.
+		 * Unfortunately, people do use such commands.
+		 * We massage argv[1] to work around it by moving 'f'
+		 * to the end of the string.
+		 * More contrived "tar fCx TARFILE DIR" still fails,
+		 * but such commands are much less likely to be used.
+		 */
+		char *f = strchr(argv[1], 'f');
+		if (f) {
+			while (f[1] != '\0') {
+				*f = f[1];
+				f++;
+			}
+			*f = 'f';
+		}
+	}
+#endif
 	opt = getopt32(argv,
 		"txC:f:Opvk"
 		IF_FEATURE_TAR_CREATE(   "ch"  )
Previous: Junio C Hamano
Message 13 of 13 in “Re: [PATCH] tar: on extract, -o is --no-same-owner”
  1. Bernhard Reutner-FischerOct 23, 2009
  2. Bernhard Reutner-FischerOct 23, 2009
  3. Junio C HamanoOct 23, 2009
  4. Bernhard Reutner-FischerOct 24, 2009
  5. Andreas SchwabOct 24, 2009
  6. Jakub NarebskiOct 24, 2009
  7. Bernhard Reutner-FischerOct 24, 2009
  8. Andreas SchwabOct 24, 2009
  9. Bernhard Reutner-FischerOct 24, 2009
  10. Andreas SchwabOct 24, 2009
  11. Andreas SchwabOct 24, 2009
  12. Junio C HamanoOct 24, 2009
  13. Denys VlasenkoOct 24, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.