Explorar o código

Pass tar context pointer as an argument instead of a struct member

The context does not have anything to do with the TarInfo struct,
so pass it as a function argument either as 'void *' or as
'struct tarcontext *' if the type is known.
Guillem Jover %!s(int64=16) %!d(string=hai) anos
pai
achega
67d524ea0b
Modificáronse 4 ficheiros con 21 adicións e 24 borrados
  1. 8 9
      lib/dpkg/tarfn.c
  2. 3 4
      lib/dpkg/tarfn.h
  3. 9 10
      src/archives.c
  4. 1 1
      src/archives.h

+ 8 - 9
lib/dpkg/tarfn.c

@@ -176,7 +176,7 @@ struct symlinkList {
 };
 
 int
-TarExtractor(void *userData, const struct tar_operations *ops)
+TarExtractor(void *ctx, const struct tar_operations *ops)
 {
 	int status;
 	char buffer[TARBLKSZ];
@@ -194,9 +194,8 @@ TarExtractor(void *userData, const struct tar_operations *ops)
 
 	h.Name = NULL;
 	h.LinkName = NULL;
-	h.UserData = userData;
 
-	while ((status = ops->read(userData, buffer, TARBLKSZ)) == TARBLKSZ) {
+	while ((status = ops->read(ctx, buffer, TARBLKSZ)) == TARBLKSZ) {
 		int nameLength;
 
 		if (!DecodeTarHeader(buffer, &h)) {
@@ -236,7 +235,7 @@ TarExtractor(void *userData, const struct tar_operations *ops)
 		case NormalFile1:
 			/* Compatibility with pre-ANSI ustar. */
 			if (h.Name[nameLength - 1] != '/') {
-				status = ops->extract_file(&h);
+				status = ops->extract_file(ctx, &h);
 				break;
 			}
 			/* Else, fall through. */
@@ -244,10 +243,10 @@ TarExtractor(void *userData, const struct tar_operations *ops)
 			if (h.Name[nameLength - 1] == '/') {
 				h.Name[nameLength - 1] = '\0';
 			}
-			status = ops->mkdir(&h);
+			status = ops->mkdir(ctx, &h);
 			break;
 		case HardLink:
-			status = ops->link(&h);
+			status = ops->link(ctx, &h);
 			break;
 		case SymbolicLink:
 			symlink_node = m_malloc(sizeof(*symlink_node));
@@ -266,7 +265,7 @@ TarExtractor(void *userData, const struct tar_operations *ops)
 		case CharacterDevice:
 		case BlockDevice:
 		case FIFO:
-			status = ops->mknod(&h);
+			status = ops->mknod(ctx, &h);
 			break;
 		case GNU_LONGLINK:
 		case GNU_LONGNAME:
@@ -295,7 +294,7 @@ TarExtractor(void *userData, const struct tar_operations *ops)
 			     long_read -= TARBLKSZ) {
 				int copysize;
 
-				status = ops->read(userData, buffer, TARBLKSZ);
+				status = ops->read(ctx, buffer, TARBLKSZ);
 				/* If we didn't get TARBLKSZ bytes read, punt. */
 				if (status != TARBLKSZ) {
 					 /* Read partial header record? */
@@ -332,7 +331,7 @@ TarExtractor(void *userData, const struct tar_operations *ops)
 	while (symlink_head) {
 		symlink_node = symlink_head->next;
 		if (status == 0)
-			status = ops->symlink(&symlink_head->h);
+			status = ops->symlink(ctx, &symlink_head->h);
 		free(symlink_head->h.Name);
 		free(symlink_head->h.LinkName);
 		free(symlink_head);

+ 3 - 4
lib/dpkg/tarfn.h

@@ -50,7 +50,6 @@ enum TarFileType {
 
 struct	TarInfo {
 	enum tar_format	format;		/* Tar archive format. */
-	void *		UserData;	/* User passed this in as argument */
 	char *		Name;		/* File name */
 	mode_t		Mode;		/* Unix mode, including device bits. */
 	size_t		Size;		/* Size of file */
@@ -62,8 +61,8 @@ struct	TarInfo {
 	gid_t		GroupID;	/* Numeric GID */
 };
 
-typedef int (*tar_read_func)(void * userData, char * buffer, int length);
-typedef int (*tar_func)(struct TarInfo * h);
+typedef int (*tar_read_func)(void *ctx, char *buffer, int length);
+typedef int (*tar_func)(void *ctx, struct TarInfo *h);
 
 struct tar_operations {
 	tar_read_func read;
@@ -75,6 +74,6 @@ struct tar_operations {
 	tar_func mknod;
 };
 
-int TarExtractor(void *userData, const struct tar_operations *ops);
+int TarExtractor(void *ctx, const struct tar_operations *ops);
 
 #endif

+ 9 - 10
src/archives.c

@@ -180,9 +180,8 @@ int tarfileread(void *ud, char *buf, int len) {
 }
 
 static void
-tarfile_skip_one_forward(struct TarInfo *ti)
+tarfile_skip_one_forward(struct tarcontext *tc, struct TarInfo *ti)
 {
-  struct tarcontext *tc = (struct tarcontext *)ti->UserData;
   size_t r;
   char databuf[TARBLKSZ];
 
@@ -338,12 +337,10 @@ struct fileinlist *addfiletolist(struct tarcontext *tc,
 }
 
 static void
-remove_file_from_list(struct TarInfo *ti,
+remove_file_from_list(struct tarcontext *tc, struct TarInfo *ti,
                       struct fileinlist **oldnifd,
                       struct fileinlist *nifd)
 {
-  struct tarcontext *tc = (struct tarcontext *)ti->UserData;
-
   obstack_free(&tar_obs, nifd);
   tc->newfilesp = oldnifd;
   *oldnifd = NULL;
@@ -394,7 +391,9 @@ linktosameexistingdir(const struct TarInfo *ti, const char *fname,
   return true;
 }
 
-int tarobject(struct TarInfo *ti) {
+int
+tarobject(void *ctx, struct TarInfo *ti)
+{
   static struct varbuf conffderefn, hardlinkfn, symlinkfn;
   static int fd;
   const char *usename;
@@ -402,7 +401,7 @@ int tarobject(struct TarInfo *ti) {
   struct filenamenode *linknode;
 
   struct conffile *conff;
-  struct tarcontext *tc= (struct tarcontext*)ti->UserData;
+  struct tarcontext *tc = ctx;
   bool existingdirectory, keepexisting;
   int statr;
   ssize_t r;
@@ -621,15 +620,15 @@ int tarobject(struct TarInfo *ti) {
   }
 
   if (keepexisting) {
-    remove_file_from_list(ti, oldnifd, nifd);
-    tarfile_skip_one_forward(ti);
+    remove_file_from_list(tc, ti, oldnifd, nifd);
+    tarfile_skip_one_forward(tc, ti);
     return 0;
   }
 
   if (filter_should_skip(ti)) {
     nifd->namenode->flags &= ~fnnf_new_inarchive;
     nifd->namenode->flags |= fnnf_filtered;
-    tarfile_skip_one_forward(ti);
+    tarfile_skip_one_forward(tc, ti);
 
     return 0;
   }

+ 1 - 1
src/archives.h

@@ -64,7 +64,7 @@ void ok_prermdeconfigure(int argc, void **argv);
 void setupfnamevbs(const char *filename);
 int unlinkorrmdir(const char *filename);
 
-int tarobject(struct TarInfo *ti);
+int tarobject(void *ctx, struct TarInfo *ti);
 int tarfileread(void *ud, char *buf, int len);
 void tar_deferred_extract(struct fileinlist *files, struct pkginfo *pkg);