[PATCH 1/2] tar: read mode for all entity types

From: Brad Barden <brad_AT_13os.net>
Date: Sun, 6 Dec 2015 02:48:38 -0600

---
 tar.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/tar.c b/tar.c
index e8dd26a..507a23d 100644
--- a/tar.c
+++ b/tar.c
_AT_@ -258,6 +258,8 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
 
 	if (!mflag && ((mtime = strtol(h->mtime, &p, 8)) < 0 || *p != '\0'))
 		eprintf("strtol %s: invalid number\n", h->mtime);
+	if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
+		eprintf("strtol %s: invalid number\n", h->mode);
 	if (remove(fname) < 0 && errno != ENOENT)
 		eprintf("remove %s:", fname);
 
_AT_@ -269,8 +271,6 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
 	case REG:
 	case AREG:
 	case RESERVED:
-		if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
-			eprintf("strtol %s: invalid number\n", h->mode);
 		fd = open(fname, O_WRONLY | O_TRUNC | O_CREAT, 0600);
 		if (fd < 0)
 			eprintf("open %s:", fname);
_AT_@ -285,16 +285,12 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
 				fname, lname);
 		break;
 	case DIRECTORY:
-		if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
-			eprintf("strtol %s: invalid number\n", h->mode);
 		if (mkdir(fname, (mode_t)mode) < 0 && errno != EEXIST)
 			eprintf("mkdir %s:", fname);
 		pushdirtime(fname, mtime);
 		break;
 	case CHARDEV:
 	case BLOCKDEV:
-		if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
-			eprintf("strtol %s: invalid number\n", h->mode);
 		if ((major = strtol(h->major, &p, 8)) < 0 || *p != '\0')
 			eprintf("strtol %s: invalid number\n", h->major);
 		if ((minor = strtol(h->minor, &p, 8)) < 0 || *p != '\0')
_AT_@ -304,8 +300,6 @@ unarchive(char *fname, ssize_t l, char b[BLKSIZ])
 			eprintf("mknod %s:", fname);
 		break;
 	case FIFO:
-		if ((mode = strtol(h->mode, &p, 8)) < 0 || *p != '\0')
-			eprintf("strtol %s: invalid number\n", h->mode);
 		if (mknod(fname, S_IFIFO | mode, 0) < 0)
 			eprintf("mknod %s:", fname);
 		break;
-- 
2.3.6
--c3bfwLpm8qysLVxt
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-tar-set-mode-directly-on-new-files.patch"
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sun Dec 06 2015 - 17:00:13 CET