Skip to contentSkip to conversation

tar: on extract, -o is --no-same-owner

PATCH Bernhard Reutner-Fischer 5 participants 13 messages Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 2 lines · Bernhard Reutner-Fischer

GNU tar-1.22 handles 'o' as no-same-owner only on extract, on create, 'o' would be --old-archive.

FYI this was prompted by:

templates/Makefile +1 -1
diff -rdup git-1.6.5.oorig/templates/Makefile git-1.6.5/templates/Makefile
@@ -50,4 +50,4 @@ clean:
 install: all
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
 	(cd blt && $(TAR) cf - .) | \
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) x --no-numeric-owner -f -)

Someone should try to ask the git people not to rely on getopt permuting options.. xof would be gentle to folks who don't want to turn on getopt_long though.

cheers,

#2 lore raw
Quoted 15 lines · Bernhard Reutner-Fischer
Quoted 2 lines · Bernhard Reutner-Fischer

GNU tar-1.22 handles 'o' as no-same-owner only on extract, on create, 'o' would be --old-archive.

FYI this was prompted by:

diff -rdup git-1.6.5.oorig/templates/Makefile git-1.6.5/templates/Makefile

templates/Makefile +0 -0
@@ -50,4 +50,4 @@ clean:

install: all

	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
	(cd blt && $(TAR) cf - .) | \

templates/Makefile clean: · line 53

Quoted 2 lines
templates/Makefile +1 -1
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) x --no-numeric-owner -f -)

argh, sorry! --no-same-owner of course.

Quoted 3 lines

Someone should try to ask the git people not to rely on getopt permuting options.. xof would be gentle to folks who don't want to turn on getopt_long though.

#3 lore raw
Quoted 9 lines · Bernhard Reutner-Fischer
Quoted 8 lines · Bernhard Reutner-Fischer
Quoted 2 lines · Bernhard Reutner-Fischer

GNU tar-1.22 handles 'o' as no-same-owner only on extract, on create, 'o' would be --old-archive.

FYI this was prompted by:

Quoted 11 lines

templates/Makefile clean: · line 53

Quoted 9 lines

diff -rdup git-1.6.5.oorig/templates/Makefile git-1.6.5/templates/Makefile

templates/Makefile +0 -0
@@ -50,4 +50,4 @@ clean:

install: all

	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
	(cd blt && $(TAR) cf - .) | \
templates/Makefile +1 -1
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) x --no-numeric-owner -f -)

argh, sorry! --no-same-owner of course.

Either way, your change would break non-GNU tar implementations that are properly POSIX.1, isn't it?

#4 lore raw
Quoted 23 lines · Junio C Hamano
Quoted 9 lines · Bernhard Reutner-Fischer
Quoted 8 lines · Bernhard Reutner-Fischer
Quoted 2 lines · Bernhard Reutner-Fischer

GNU tar-1.22 handles 'o' as no-same-owner only on extract, on create, 'o' would be --old-archive.

FYI this was prompted by:

Quoted 11 lines

templates/Makefile clean: · line 53

Quoted 9 lines

diff -rdup git-1.6.5.oorig/templates/Makefile git-1.6.5/templates/Makefile

templates/Makefile +0 -0
@@ -50,4 +50,4 @@ clean:

install: all

	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
	(cd blt && $(TAR) cf - .) | \
templates/Makefile +1 -1
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) x --no-numeric-owner -f -)

argh, sorry! --no-same-owner of course.

Quoted 2 lines

Either way, your change would break non-GNU tar implementations that are properly POSIX.1, isn't it?

I suppose xf - -o would work?

#5 lore raw
Quoted 24 lines · Bernhard Reutner-Fischer
Quoted 23 lines · Junio C Hamano
Quoted 20 lines · Bernhard Reutner-Fischer
Quoted 15 lines · Bernhard Reutner-Fischer
Quoted 2 lines · Bernhard Reutner-Fischer

GNU tar-1.22 handles 'o' as no-same-owner only on extract, on create, 'o' would be --old-archive.

FYI this was prompted by:

diff -rdup git-1.6.5.oorig/templates/Makefile git-1.6.5/templates/Makefile

templates/Makefile +0 -0
@@ -50,4 +50,4 @@ clean:

install: all

	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
	(cd blt && $(TAR) cf - .) | \

templates/Makefile clean: · line 53

Quoted 2 lines
templates/Makefile +1 -1
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) x --no-numeric-owner -f -)

argh, sorry! --no-same-owner of course.

Quoted 4 lines
Quoted 2 lines

Either way, your change would break non-GNU tar implementations that are properly POSIX.1, isn't it?

I suppose xf - -o would work?

Isn't that the same as 'xfo -'?

(tar isn't specified by POSIX, btw.)

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#6 lore raw
Quoted 26 lines · Andreas Schwab
Quoted 24 lines · Bernhard Reutner-Fischer
Quoted 23 lines · Junio C Hamano
Quoted 20 lines · Bernhard Reutner-Fischer
Quoted 15 lines · Bernhard Reutner-Fischer
Quoted 2 lines · Bernhard Reutner-Fischer

GNU tar-1.22 handles 'o' as no-same-owner only on extract, on create, 'o' would be --old-archive.

FYI this was prompted by:

diff -rdup git-1.6.5.oorig/templates/Makefile git-1.6.5/templates/Makefile

templates/Makefile +0 -0
@@ -50,4 +50,4 @@ clean:

install: all

	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
	(cd blt && $(TAR) cf - .) | \

templates/Makefile clean: · line 53

Quoted 2 lines
templates/Makefile +1 -1
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) x --no-numeric-owner -f -)

argh, sorry! --no-same-owner of course.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Either way, your change would break non-GNU tar implementations that are properly POSIX.1, isn't it?

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).
f specifies the file so "fo" acts on file "o".
"xof -" would work for me as well as "xf - -o", it's just that "xfo -" does not work.

#7 lore raw
Quoted 9 lines · Bernhard Reutner-Fischer
Quoted 5 lines · Andreas Schwab
Quoted 1 line · Bernhard Reutner-Fischer

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.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#8 lore raw
Quoted 9 lines · Andreas Schwab
Quoted 7 lines · Bernhard Reutner-Fischer
Quoted 5 lines · Andreas Schwab
Quoted 1 line · Bernhard Reutner-Fischer

I suppose xf - -o would work?

Isn't that the same as 'xfo -'?

Quoted 7 lines
Quoted 2 lines

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

archival/tar.c +27 -0
diff -d -urpN busybox.0/archival/tar.c busybox.1/archival/tar.c
@@ -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"  )
#9 lore raw
In reply to Andreas Schwab
Quoted 9 lines · Andreas Schwab
Quoted 7 lines · Bernhard Reutner-Fischer
Quoted 5 lines · Andreas Schwab
Quoted 1 line · Bernhard Reutner-Fischer

I suppose xf - -o would work?

Isn't that the same as 'xfo -'?

Quoted 7 lines
Quoted 2 lines

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.

Like this.

Andreas.

Quoted 1 line

From ebadb41b346c305b94f27e3bb787bf0ba6bb8a5b Mon Sep 17 00:00:00 2001

From: Andreas Schwab <[email protected]>
Date: Sat, 24 Oct 2009 15:01:03 +0200
Subject: [PATCH] Work around option parsing bug in the busybox tar implementation

Traditionally the first argument of the tar command was interpreted a bundle of letters specifying the mode of operation and additional options, with any option arguments taken from subsequent words on the command line as needed. The implementation of tar in busybox apparently treats this bundle as if preceded by a dash and then parses it by getopt rules, which mishandles 'tar xfo -'. Use 'tar xof -' instead which is parsed the same way by both traditional tar implementations and busybox.

---
 templates/Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
templates/Makefile +1 -1
index a12c6e2..408f013 100644
@@ -50,4 +50,4 @@ clean:
 install: all
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
 	(cd blt && $(TAR) cf - .) | \
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xof -)
Signature · 7 lines
1.6.5.1


-- 
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#10 lore raw
Quoted 1 line · Andreas Schwab

Like this.

Yeah, correct and it beautifly explains the issue. Thanks.

Quoted 36 lines
Quoted 1 line

From ebadb41b346c305b94f27e3bb787bf0ba6bb8a5b Mon Sep 17 00:00:00 2001

From: Andreas Schwab <[email protected]>
Date: Sat, 24 Oct 2009 15:01:03 +0200
Subject: [PATCH] Work around option parsing bug in the busybox tar implementation

Traditionally the first argument of the tar command was interpreted a bundle of letters specifying the mode of operation and additional options, with any option arguments taken from subsequent words on the command line as needed. The implementation of tar in busybox apparently treats this bundle as if preceded by a dash and then parses it by getopt rules, which mishandles 'tar xfo -'. Use 'tar xof -' instead which is parsed the same way by both traditional tar implementations and busybox.

---
 templates/Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
templates/Makefile +1 -1
index a12c6e2..408f013 100644
@@ -50,4 +50,4 @@ clean:
 install: all
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
 	(cd blt && $(TAR) cf - .) | \
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xof -)
Signature · 7 lines
1.6.5.1


-- 
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#11 lore raw
In reply to Andreas Schwab
Quoted 16 lines · Andreas Schwab
Quoted 15 lines · Bernhard Reutner-Fischer
Quoted 14 lines · Junio C Hamano
Quoted 12 lines · Bernhard Reutner-Fischer

templates/Makefile clean: · line 53

Quoted 9 lines · Bernhard Reutner-Fischer
Quoted 3 lines · Bernhard Reutner-Fischer

GNU tar-1.22 handles 'o' as no-same-owner only on extract, on create, 'o' would be --old-archive.

templates/Makefile +1 -1
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
 	(cd blt && $(TAR) cf - .) | \
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) x --no-numeric-owner -f -)

argh, sorry! --no-same-owner of course.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Either way, your change would break non-GNU tar implementations that are properly POSIX.1, isn't it?

I suppose xf - -o would work?

Isn't that the same as 'xfo -'?

(tar isn't specified by POSIX, btw.)

I don't quite understand why 'o' has to be spelled using long name --no-same-owner, instead of just correcting the ordering of "old style" short options to have 'f' last, i.e.

  $(TAR) xof -

and not (current)

  $(TAR) xfo -
Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#12 lore raw
Quoted 20 lines · Jakub Narebski
Quoted 19 lines · Andreas Schwab
Quoted 18 lines · Bernhard Reutner-Fischer
Quoted 16 lines · Junio C Hamano
Quoted 6 lines · Bernhard Reutner-Fischer
Quoted 4 lines · Bernhard Reutner-Fischer
Quoted 3 lines · Bernhard Reutner-Fischer

GNU tar-1.22 handles 'o' as no-same-owner only on extract, on create, 'o' would be --old-archive.

Quoted 6 lines

templates/Makefile clean: · line 53

Quoted 4 lines
templates/Makefile +1 -1
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(template_instdir_SQ)'
 	(cd blt && $(TAR) cf - .) | \
-	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) xfo -)
+	(cd '$(DESTDIR_SQ)$(template_instdir_SQ)' && umask 022 && $(TAR) x --no-numeric-owner -f -)

argh, sorry! --no-same-owner of course.

Either way, your change would break non-GNU tar implementations that are properly POSIX.1, isn't it?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I suppose xf - -o would work?

Isn't that the same as 'xfo -'?

(tar isn't specified by POSIX, btw.)

I don't quite understand why 'o' has to be spelled using long name --no-same-owner, instead of just correcting the ordering of "old style"

It doesn't have to be, right.

Quoted 7 lines

short options to have 'f' last, i.e.

$(TAR) xof -

and not (current)

$(TAR) xfo -

any of "xf - -o" or "xof -" would work for me.

#13 lore raw
In reply to Jakub Narebski
Quoted 9 lines · Jakub Narebski

I don't quite understand why 'o' has to be spelled using long name --no-same-owner, instead of just correcting the ordering of "old style" short options to have 'f' last, i.e.

  $(TAR) xof -

and not (current)

  $(TAR) xfo -

Both do exactly the same, traditionally. Note the lack of '-' preceding 'xfo', which does not use getopt-style option parsing.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."