Skip to content

Commit

Permalink
… aaaand the even longer awaited functionality to append a slash to a
Browse files Browse the repository at this point in the history
directory’s name upon ustar creation (like gtar)
  • Loading branch information
mirabilos committed Aug 16, 2011
1 parent fb63d86 commit a6b9738
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
8 changes: 6 additions & 2 deletions cpio.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $MirOS: src/bin/pax/cpio.1,v 1.22 2011/08/16 13:27:01 tg Exp $
.\" $MirOS: src/bin/pax/cpio.1,v 1.23 2011/08/16 13:45:00 tg Exp $
.\" $OpenBSD: cpio.1,v 1.26 2007/05/31 19:19:15 jmc Exp $
.\"
.\" Copyright (c) 2005, 2009 Thorsten Glaser <[email protected]>
Expand Down Expand Up @@ -287,6 +287,8 @@ to turn them off, or not, to turn them on:
0x0040: Extract hard links by copying if linking fails.
.It Ar numid
0x0080: Use only numeric uid and gid values.
.It Ar gslash
0x0100: Append a slash after directory names.
.El
.Pp
This option is only implemented for the cpio, sv4cpio,
Expand All @@ -298,7 +300,9 @@ and
specifiers are ignored.
For all formats except ustar, the
.Ar numid
specifier is ignored.
and
.Ar gslash
specifiers are ignored.
.It Fl O Ar archive
Use the specified file name as the archive to write to.
.It Fl v
Expand Down
4 changes: 3 additions & 1 deletion options.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#endif

__SCCSID("@(#)options.c 8.2 (Berkeley) 4/18/94");
__RCSID("$MirOS: src/bin/pax/options.c,v 1.32 2011/08/16 13:27:01 tg Exp $");
__RCSID("$MirOS: src/bin/pax/options.c,v 1.33 2011/08/16 13:45:00 tg Exp $");

#ifdef __GLIBC__
char *fgetln(FILE *, size_t *);
Expand Down Expand Up @@ -1752,6 +1752,8 @@ process_M(const char *arg, void (*call_usage)(void))
k = ANON_LNCP;
} else if (!strncmp(arg, "numid", 5)) {
k = ANON_NUMID;
} else if (!strncmp(arg, "gslash", 6)) {
k = ANON_DIRSLASH;
} else
call_usage();
if (j)
Expand Down
5 changes: 3 additions & 2 deletions options.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** $MirOS: src/bin/pax/options.h,v 1.5 2011/08/16 13:27:02 tg Exp $ */
/** $MirOS: src/bin/pax/options.h,v 1.6 2011/08/16 13:45:01 tg Exp $ */
/* $OpenBSD: options.h,v 1.4 2003/06/13 17:51:14 millert Exp $ */
/* $NetBSD: options.h,v 1.3 1995/03/21 09:07:32 cgd Exp $ */

Expand Down Expand Up @@ -125,7 +125,8 @@
#define ANON_DEBUG 0x0020
#define ANON_LNCP 0x0040
#define ANON_NUMID 0x0080
#define ANON_MAXVAL 0x00FF
#define ANON_DIRSLASH 0x0100
#define ANON_MAXVAL 0x01FF
extern int anonarch;
void anonarch_init(void);

Expand Down
8 changes: 6 additions & 2 deletions pax.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $MirOS: src/bin/pax/pax.1,v 1.13 2011/08/16 13:27:02 tg Exp $
.\" $MirOS: src/bin/pax/pax.1,v 1.14 2011/08/16 13:45:01 tg Exp $
.\" $OpenBSD: pax.1,v 1.52 2007/05/31 19:19:15 jmc Exp $
.\" $NetBSD: pax.1,v 1.3 1995/03/21 09:07:37 cgd Exp $
.\"
Expand Down Expand Up @@ -605,6 +605,8 @@ for a comprehensive list and compatibility notes.
0x0040: Extract hard links by copying if linking fails.
.It Ar numid
0x0080: Use only numeric uid and gid values.
.It Ar gslash
0x0100: Append a slash after directory names.
.El
.Pp
This option is only implemented for the cpio, sv4cpio,
Expand All @@ -616,7 +618,9 @@ and
specifiers are ignored.
For all formats except ustar, the
.Ar numid
specifier is ignored.
and
.Ar gslash
specifiers are ignored.
TODO: The
.Nm pax
frontend should be using the
Expand Down
8 changes: 6 additions & 2 deletions tar.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $MirOS: src/bin/pax/tar.1,v 1.14 2011/08/16 13:27:02 tg Exp $
.\" $MirOS: src/bin/pax/tar.1,v 1.15 2011/08/16 13:45:01 tg Exp $
.\" $OpenBSD: tar.1,v 1.48 2007/05/31 19:19:15 jmc Exp $
.\"
.\" Copyright (c) 1996 SigmaSoft, Th. Lockert
Expand Down Expand Up @@ -310,6 +310,8 @@ for a comprehensive list and compatibility notes.
0x0040: Extract hard links by copying if linking fails.
.It Ar numid
0x0080: Use only numeric uid and gid values.
.It Ar gslash
0x0100: Append a slash after directory names.
.El
.Pp
This option is only implemented for the cpio, sv4cpio,
Expand All @@ -321,7 +323,9 @@ and
specifiers are ignored.
For all formats except ustar, the
.Ar numid
specifier is ignored.
and
.Ar gslash
specifiers are ignored.
.It Fl m
Do not preserve modification time.
.It Fl O
Expand Down
13 changes: 11 additions & 2 deletions tar.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** $MirOS: src/bin/pax/tar.c,v 1.6 2011/08/16 13:27:03 tg Exp $ */
/** $MirOS: src/bin/pax/tar.c,v 1.7 2011/08/16 13:45:02 tg Exp $ */
/* $OpenBSD: tar.c,v 1.41 2006/03/04 20:24:55 otto Exp $ */
/* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */

Expand Down Expand Up @@ -49,7 +49,7 @@
#include "options.h"

__SCCSID("@(#)tar.c 8.2 (Berkeley) 4/18/94");
__RCSID("$MirOS: src/bin/pax/tar.c,v 1.6 2011/08/16 13:27:03 tg Exp $");
__RCSID("$MirOS: src/bin/pax/tar.c,v 1.7 2011/08/16 13:45:02 tg Exp $");

/*
* Routines for reading, writing and header identify of various versions of tar
Expand Down Expand Up @@ -938,6 +938,15 @@ ustar_wr(ARCHD *arcn)
return(1);
}

/*
* if -M gslash: append a slash if directory
*/
if ((anonarch & ANON_DIRSLASH) && arcn->type == PAX_DIR &&
(size_t)arcn->nlen < (sizeof(arcn->name) - 1)) {
arcn->name[arcn->nlen++] = '/';
arcn->name[arcn->nlen] = '\0';
}

/*
* split the path name into prefix and name fields (if needed). if
* pt != arcn->name, the name has to be split
Expand Down

0 comments on commit a6b9738

Please sign in to comment.