Browse Source

libdpkg: Uppercase tar related enum values

Guillem Jover 9 years ago
parent
commit
90d16af060
4 changed files with 75 additions and 75 deletions
  1. 26 26
      lib/dpkg/tarfn.c
  2. 15 15
      lib/dpkg/tarfn.h
  3. 31 31
      src/archives.c
  4. 3 3
      src/filters.c

+ 26 - 26
lib/dpkg/tarfn.c

@@ -3,7 +3,7 @@
  * tarfn.c - tar archive extraction functions
  *
  * Copyright © 1995 Bruce Perens
- * Copyright © 2007-2011,2013 Guillem Jover <guillem@debian.org>
+ * Copyright © 2007-2011,2013-2014 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -99,26 +99,26 @@ get_unix_mode(struct tar_header *h)
 	type = (enum tar_filetype)h->linkflag;
 
 	switch (type) {
-	case tar_filetype_file0:
-	case tar_filetype_file:
+	case TAR_FILETYPE_FILE0:
+	case TAR_FILETYPE_FILE:
 		mode = S_IFREG;
 		break;
-	case tar_filetype_symlink:
+	case TAR_FILETYPE_SYMLINK:
 		mode = S_IFLNK;
 		break;
-	case tar_filetype_dir:
+	case TAR_FILETYPE_DIR:
 		mode = S_IFDIR;
 		break;
-	case tar_filetype_chardev:
+	case TAR_FILETYPE_CHARDEV:
 		mode = S_IFCHR;
 		break;
-	case tar_filetype_blockdev:
+	case TAR_FILETYPE_BLOCKDEV:
 		mode = S_IFBLK;
 		break;
-	case tar_filetype_fifo:
+	case TAR_FILETYPE_FIFO:
 		mode = S_IFIFO;
 		break;
-	case tar_filetype_hardlink:
+	case TAR_FILETYPE_HARDLINK:
 	default:
 		mode = 0;
 		break;
@@ -160,18 +160,18 @@ tar_header_decode(struct tar_header *h, struct tar_entry *d)
 	long checksum;
 
 	if (memcmp(h->magic, TAR_MAGIC_GNU, 6) == 0)
-		d->format = tar_format_gnu;
+		d->format = TAR_FORMAT_GNU;
 	else if (memcmp(h->magic, TAR_MAGIC_USTAR, 6) == 0)
-		d->format = tar_format_ustar;
+		d->format = TAR_FORMAT_USTAR;
 	else
-		d->format = tar_format_old;
+		d->format = TAR_FORMAT_OLD;
 
 	d->type = (enum tar_filetype)h->linkflag;
-	if (d->type == tar_filetype_file0)
-		d->type = tar_filetype_file;
+	if (d->type == TAR_FILETYPE_FILE0)
+		d->type = TAR_FILETYPE_FILE;
 
 	/* Concatenate prefix and name to support ustar style long names. */
-	if (d->format == tar_format_ustar && h->prefix[0] != '\0')
+	if (d->format == TAR_FORMAT_USTAR && h->prefix[0] != '\0')
 		d->name = get_prefix_name(h);
 	else
 		d->name = m_strndup(h->name, sizeof(h->name));
@@ -294,8 +294,8 @@ tar_extractor(void *ctx, const struct tar_operations *ops)
 			tar_entry_destroy(&h);
 			break;
 		}
-		if (h.type != tar_filetype_gnu_longlink &&
-		    h.type != tar_filetype_gnu_longname) {
+		if (h.type != TAR_FILETYPE_GNU_LONGLINK &&
+		    h.type != TAR_FILETYPE_GNU_LONGNAME) {
 			if (next_long_name)
 				h.name = next_long_name;
 
@@ -317,23 +317,23 @@ tar_extractor(void *ctx, const struct tar_operations *ops)
 		name_len = strlen(h.name);
 
 		switch (h.type) {
-		case tar_filetype_file:
+		case TAR_FILETYPE_FILE:
 			/* Compatibility with pre-ANSI ustar. */
 			if (h.name[name_len - 1] != '/') {
 				status = ops->extract_file(ctx, &h);
 				break;
 			}
 			/* Else, fall through. */
-		case tar_filetype_dir:
+		case TAR_FILETYPE_DIR:
 			if (h.name[name_len - 1] == '/') {
 				h.name[name_len - 1] = '\0';
 			}
 			status = ops->mkdir(ctx, &h);
 			break;
-		case tar_filetype_hardlink:
+		case TAR_FILETYPE_HARDLINK:
 			status = ops->link(ctx, &h);
 			break;
-		case tar_filetype_symlink:
+		case TAR_FILETYPE_SYMLINK:
 			symlink_node = m_malloc(sizeof(*symlink_node));
 			memcpy(&symlink_node->h, &h, sizeof(struct tar_entry));
 			symlink_node->h.name = m_strdup(h.name);
@@ -347,15 +347,15 @@ tar_extractor(void *ctx, const struct tar_operations *ops)
 			symlink_tail = symlink_node;
 			status = 0;
 			break;
-		case tar_filetype_chardev:
-		case tar_filetype_blockdev:
-		case tar_filetype_fifo:
+		case TAR_FILETYPE_CHARDEV:
+		case TAR_FILETYPE_BLOCKDEV:
+		case TAR_FILETYPE_FIFO:
 			status = ops->mknod(ctx, &h);
 			break;
-		case tar_filetype_gnu_longlink:
+		case TAR_FILETYPE_GNU_LONGLINK:
 			status = tar_gnu_long(ctx, ops, &h, &next_long_link);
 			break;
-		case tar_filetype_gnu_longname:
+		case TAR_FILETYPE_GNU_LONGNAME:
 			status = tar_gnu_long(ctx, ops, &h, &next_long_name);
 			break;
 		default:

+ 15 - 15
lib/dpkg/tarfn.h

@@ -3,7 +3,7 @@
  * tarfn.h - tar archive extraction functions
  *
  * Copyright © 1995 Bruce Perens
- * Copyright © 2009-2010 Guillem Jover <guillem@debian.org>
+ * Copyright © 2009-2014 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -35,24 +35,24 @@
 #define TARBLKSZ	512
 
 enum tar_format {
-	tar_format_old,
-	tar_format_gnu,
-	tar_format_ustar,
-	tar_format_pax,
+	TAR_FORMAT_OLD,
+	TAR_FORMAT_GNU,
+	TAR_FORMAT_USTAR,
+	TAR_FORMAT_PAX,
 };
 
 enum tar_filetype {
 	/** For compatibility with decades-old bug. */
-	tar_filetype_file0 = '\0',
-	tar_filetype_file = '0',
-	tar_filetype_hardlink = '1',
-	tar_filetype_symlink = '2',
-	tar_filetype_chardev = '3',
-	tar_filetype_blockdev = '4',
-	tar_filetype_dir = '5',
-	tar_filetype_fifo = '6',
-	tar_filetype_gnu_longlink = 'K',
-	tar_filetype_gnu_longname = 'L',
+	TAR_FILETYPE_FILE0 = '\0',
+	TAR_FILETYPE_FILE = '0',
+	TAR_FILETYPE_HARDLINK = '1',
+	TAR_FILETYPE_SYMLINK = '2',
+	TAR_FILETYPE_CHARDEV = '3',
+	TAR_FILETYPE_BLOCKDEV = '4',
+	TAR_FILETYPE_DIR = '5',
+	TAR_FILETYPE_FIFO = '6',
+	TAR_FILETYPE_GNU_LONGLINK = 'K',
+	TAR_FILETYPE_GNU_LONGNAME = 'L',
 };
 
 struct tar_entry {

+ 31 - 31
src/archives.c

@@ -264,7 +264,7 @@ tarobject_skip_entry(struct tarcontext *tc, struct tar_entry *ti)
 {
   /* We need to advance the tar file to the next object, so read the
    * file data and set it to oblivion. */
-  if (ti->type == tar_filetype_file) {
+  if (ti->type == TAR_FILETYPE_FILE) {
     struct dpkg_error err;
     char fnamebuf[256];
 
@@ -326,7 +326,7 @@ tarobject_extract(struct tarcontext *tc, struct tar_entry *te,
   char *newhash;
 
   switch (te->type) {
-  case tar_filetype_file:
+  case TAR_FILETYPE_FILE:
     /* We create the file with mode 0 to make sure nobody can do anything with
      * it until we apply the proper mode, which might be a statoverride. */
     fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0);
@@ -367,22 +367,22 @@ tarobject_extract(struct tarcontext *tc, struct tar_entry *te,
     if (close(fd))
       ohshite(_("error closing/writing `%.255s'"), te->name);
     break;
-  case tar_filetype_fifo:
+  case TAR_FILETYPE_FIFO:
     if (mkfifo(path, 0))
       ohshite(_("error creating pipe `%.255s'"), te->name);
     debug(dbg_eachfiledetail, "tarobject fifo");
     break;
-  case tar_filetype_chardev:
+  case TAR_FILETYPE_CHARDEV:
     if (mknod(path, S_IFCHR, te->dev))
       ohshite(_("error creating device `%.255s'"), te->name);
     debug(dbg_eachfiledetail, "tarobject chardev");
     break;
-  case tar_filetype_blockdev:
+  case TAR_FILETYPE_BLOCKDEV:
     if (mknod(path, S_IFBLK, te->dev))
       ohshite(_("error creating device `%.255s'"), te->name);
     debug(dbg_eachfiledetail, "tarobject blockdev");
     break;
-  case tar_filetype_hardlink:
+  case TAR_FILETYPE_HARDLINK:
     varbuf_reset(&hardlinkfn);
     varbuf_add_str(&hardlinkfn, instdir);
     varbuf_add_char(&hardlinkfn, '/');
@@ -397,13 +397,13 @@ tarobject_extract(struct tarcontext *tc, struct tar_entry *te,
     namenode->newhash = linknode->newhash;
     debug(dbg_eachfiledetail, "tarobject hardlink hash=%s", namenode->newhash);
     break;
-  case tar_filetype_symlink:
+  case TAR_FILETYPE_SYMLINK:
     /* We've already checked for an existing directory. */
     if (symlink(te->linkname, path))
       ohshite(_("error creating symbolic link `%.255s'"), te->name);
     debug(dbg_eachfiledetail, "tarobject symlink creating");
     break;
-  case tar_filetype_dir:
+  case TAR_FILETYPE_DIR:
     /* We've already checked for an existing directory. */
     if (mkdir(path, 0))
       ohshite(_("error creating directory `%.255s'"), te->name);
@@ -418,7 +418,7 @@ static void
 tarobject_hash(struct tarcontext *tc, struct tar_entry *te,
                struct filenamenode *namenode)
 {
-  if (te->type == tar_filetype_file) {
+  if (te->type == TAR_FILETYPE_FILE) {
     struct dpkg_error err;
     char fnamebuf[256];
     char *newhash;
@@ -431,7 +431,7 @@ tarobject_hash(struct tarcontext *tc, struct tar_entry *te,
 
     namenode->newhash = newhash;
     debug(dbg_eachfiledetail, "tarobject file hash=%s", namenode->newhash);
-  } else if (te->type == tar_filetype_hardlink) {
+  } else if (te->type == TAR_FILETYPE_HARDLINK) {
     struct filenamenode *linknode;
 
     linknode = findnamenode(te->linkname, 0);
@@ -450,7 +450,7 @@ tarobject_set_mtime(struct tar_entry *te, const char *path)
   tv[1].tv_sec = te->mtime;
   tv[1].tv_usec = 0;
 
-  if (te->type == tar_filetype_symlink) {
+  if (te->type == TAR_FILETYPE_SYMLINK) {
 #ifdef HAVE_LUTIMES
     if (lutimes(path, tv) && errno != ENOSYS)
       ohshite(_("error setting timestamps of `%.255s'"), path);
@@ -464,10 +464,10 @@ tarobject_set_mtime(struct tar_entry *te, const char *path)
 static void
 tarobject_set_perms(struct tar_entry *te, const char *path, struct file_stat *st)
 {
-  if (te->type == tar_filetype_file)
+  if (te->type == TAR_FILETYPE_FILE)
     return; /* Already handled using the file descriptor. */
 
-  if (te->type == tar_filetype_symlink) {
+  if (te->type == TAR_FILETYPE_SYMLINK) {
     if (lchown(path, st->uid, st->gid))
       ohshite(_("error setting ownership of symlink `%.255s'"), path);
   } else {
@@ -587,10 +587,10 @@ tarobject_matches(struct tarcontext *tc,
   debug(dbg_eachfiledetail, "tarobject matches on-disk object?");
 
   switch (te->type) {
-  case tar_filetype_dir:
+  case TAR_FILETYPE_DIR:
     /* Nothing to check for a new directory. */
     return;
-  case tar_filetype_symlink:
+  case TAR_FILETYPE_SYMLINK:
     /* Symlinks to existing dirs have already been dealt with, only
      * reamin real symlinks where we can compare the target. */
     if (!S_ISLNK(stab->st_mode))
@@ -610,21 +610,21 @@ tarobject_matches(struct tarcontext *tc,
       free(linkname);
     }
     break;
-  case tar_filetype_chardev:
+  case TAR_FILETYPE_CHARDEV:
     if (S_ISCHR(stab->st_mode) && stab->st_rdev == te->dev)
       return;
     break;
-  case tar_filetype_blockdev:
+  case TAR_FILETYPE_BLOCKDEV:
     if (S_ISBLK(stab->st_mode) && stab->st_rdev == te->dev)
       return;
     break;
-  case tar_filetype_fifo:
+  case TAR_FILETYPE_FIFO:
     if (S_ISFIFO(stab->st_mode))
       return;
     break;
-  case tar_filetype_hardlink:
+  case TAR_FILETYPE_HARDLINK:
     /* Fall through. */
-  case tar_filetype_file:
+  case TAR_FILETYPE_FILE:
     /* Only check metadata for non-conffiles. */
     if (!(namenode->flags & fnnf_new_conff) &&
         !(S_ISREG(stab->st_mode) && te->size == stab->st_size))
@@ -871,7 +871,7 @@ tarobject(void *ctx, struct tar_entry *ti)
    * a file overwriting conflict. */
   existingdir = false;
   switch (ti->type) {
-  case tar_filetype_symlink:
+  case TAR_FILETYPE_SYMLINK:
     /* If it's already an existing directory, do nothing. */
     if (!statr && S_ISDIR(stab.st_mode)) {
       debug(dbg_eachfiledetail, "tarobject symlink exists as directory");
@@ -881,18 +881,18 @@ tarobject(void *ctx, struct tar_entry *ti)
         existingdir = true;
     }
     break;
-  case tar_filetype_dir:
+  case TAR_FILETYPE_DIR:
     /* If it's already an existing directory, do nothing. */
     if (!stat(fnamevb.buf,&stabtmp) && S_ISDIR(stabtmp.st_mode)) {
       debug(dbg_eachfiledetail, "tarobject directory exists");
       existingdir = true;
     }
     break;
-  case tar_filetype_file:
-  case tar_filetype_chardev:
-  case tar_filetype_blockdev:
-  case tar_filetype_fifo:
-  case tar_filetype_hardlink:
+  case TAR_FILETYPE_FILE:
+  case TAR_FILETYPE_CHARDEV:
+  case TAR_FILETYPE_BLOCKDEV:
+  case TAR_FILETYPE_FIFO:
+  case TAR_FILETYPE_HARDLINK:
     break;
   default:
     ohshit(_("archive contained object `%.255s' of unknown type 0x%x"),
@@ -941,7 +941,7 @@ tarobject(void *ctx, struct tar_entry *ti)
        * not exist assume it's also a directory and skip further checks.
        * XXX: Ideally with more information about the installed files we
        * could perform more clever checks. */
-      if (statr != 0 && ti->type == tar_filetype_dir) {
+      if (statr != 0 && ti->type == TAR_FILETYPE_DIR) {
         debug(dbg_eachfile, "tarobject ... assuming shared directory");
         continue;
       }
@@ -1119,7 +1119,7 @@ tarobject(void *ctx, struct tar_entry *ti)
     /* Don't try to back it up if it didn't exist. */
     debug(dbg_eachfiledetail,"tarobject new - no backup");
   } else {
-    if (ti->type == tar_filetype_dir || S_ISDIR(stab.st_mode)) {
+    if (ti->type == TAR_FILETYPE_DIR || S_ISDIR(stab.st_mode)) {
       /* One of the two is a directory - can't do atomic install. */
       debug(dbg_eachfiledetail,"tarobject directory, nonatomic");
       nifd->namenode->flags |= fnnf_no_atomic_overwrite;
@@ -1158,8 +1158,8 @@ tarobject(void *ctx, struct tar_entry *ti)
    * in .dpkg-new.
    */
 
-  if (ti->type == tar_filetype_file || ti->type == tar_filetype_hardlink ||
-      ti->type == tar_filetype_symlink) {
+  if (ti->type == TAR_FILETYPE_FILE || ti->type == TAR_FILETYPE_HARDLINK ||
+      ti->type == TAR_FILETYPE_SYMLINK) {
     nifd->namenode->flags |= fnnf_deferred_rename;
 
     debug(dbg_eachfiledetail, "tarobject done and installation deferred");

+ 3 - 3
src/filters.c

@@ -3,7 +3,7 @@
  * filters.c - filtering routines for excluding bits of packages
  *
  * Copyright © 2007, 2008 Tollef Fog Heen <tfheen@err.no>
- * Copyright © 2008, 2010 Guillem Jover <guillem@debian.org>
+ * Copyright © 2008, 2010, 2012-2014 Guillem Jover <guillem@debian.org>
  * Copyright © 2010 Canonical Ltd.
  *   written by Martin Pitt <martin.pitt@canonical.com>
  *
@@ -93,8 +93,8 @@ filter_should_skip(struct tar_entry *ti)
 	 * directories than necessary, but better err on the side of caution
 	 * than failing with “no such file or directory” (which would leave
 	 * the package in a very bad state). */
-	if (skip && (ti->type == tar_filetype_dir ||
-	             ti->type == tar_filetype_symlink)) {
+	if (skip && (ti->type == TAR_FILETYPE_DIR ||
+	             ti->type == TAR_FILETYPE_SYMLINK)) {
 		debug(dbg_eachfile,
 		      "filter seeing if '%s' needs to be reincluded",
 		      &ti->name[1]);