[PATCH master 2/3] Clean up tabs in uncpio.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 pyanaconda/isys/uncpio.c |  674 +++++++++++++++++++++++-----------------------
 1 files changed, 336 insertions(+), 338 deletions(-)

diff --git a/pyanaconda/isys/uncpio.c b/pyanaconda/isys/uncpio.c
index 2e686a3..9bbfe62 100644
--- a/pyanaconda/isys/uncpio.c
+++ b/pyanaconda/isys/uncpio.c
@@ -47,9 +47,9 @@
 #include <sys/mkdev.h>
 #endif
 
-#define CPIO_NEWC_MAGIC	"070701"
-#define CPIO_CRC_MAGIC	"070702"
-#define TRAILER		"TRAILER!!!"
+#define CPIO_NEWC_MAGIC "070701"
+#define CPIO_CRC_MAGIC  "070702"
+#define TRAILER         "TRAILER!!!"
 
 /* FIXME: We don't translate between cpio and system mode bits! These
    should both be the same, but really odd things are going to happen if
@@ -63,11 +63,11 @@ struct ourfd {
 
 struct hardLink {
     struct hardLink * next;
-    char ** files;		/* there are nlink of these, used by install */
-    int * fileMaps;		/* used by build */
+    char ** files;              /* there are nlink of these, used by install */
+    int * fileMaps;             /* used by build */
     dev_t dev;
     ino_t inode;
-    int nlink;			
+    int nlink;
     int linksLeft;
     int createdPath;
     struct stat sb;
@@ -87,10 +87,10 @@ struct cpioCrcPhysicalHeader {
     char rdevMajor[8];
     char rdevMinor[8];
     char namesize[8];
-    char checksum[8];			/* ignored !! */
+    char checksum[8];                   /* ignored !! */
 };
 
-#define PHYS_HDR_SIZE	110		/* don't depend on sizeof(struct) */
+#define PHYS_HDR_SIZE 110               /* don't depend on sizeof(struct) */
 
 struct cpioHeader {
     ino_t inode;
@@ -109,21 +109,21 @@ static inline off_t ourread(struct ourfd * thefd, void * buf, size_t size) {
 
     i = gunzip_read(thefd->fd, buf, size);
     thefd->pos += i;
-    
+
     return i;
 }
 
 static inline void padinfd(struct ourfd * fd, int modulo) {
     int buf[10];
     int amount;
-    
+
     amount = (modulo - fd->pos % modulo) % modulo;
     ourread(fd, buf, amount);
 }
 
 static inline int padoutfd(struct ourfd * fd, size_t * where, int modulo) {
     /*static int buf[10] = { '\0', '\0', '\0', '\0', '\0', 
-			   '\0', '\0', '\0', '\0', '\0' };*/
+                            '\0', '\0', '\0', '\0', '\0' };*/
     int amount;
     static int buf[512];
 
@@ -131,7 +131,7 @@ static inline int padoutfd(struct ourfd * fd, size_t * where, int modulo) {
     *where += amount;
 
     if (gzip_write(fd->fd, buf, amount) != amount)
-	return CPIOERR_WRITE_FAILED;
+        return CPIOERR_WRITE_FAILED;
 
     return 0;
 }
@@ -146,36 +146,36 @@ static int strntoul(const char * str, char ** endptr, int base, int num) {
 
     ret = strtoul(buf, &end, base);
     if (*end)
-	*endptr = (char *)(str + (end - buf));	/* XXX discards const */
+        *endptr = (char *)(str + (end - buf));  /* XXX discards const */
     else
-	*endptr = "";
+        *endptr = "";
 
     return strtoul(buf, endptr, base);
 }
 
 #define GET_NUM_FIELD(phys, log) \
-	log = strntoul(phys, &end, 16, sizeof(phys)); \
-	if (*end) return CPIOERR_BAD_HEADER;
+        log = strntoul(phys, &end, 16, sizeof(phys)); \
+        if (*end) return CPIOERR_BAD_HEADER;
 #define SET_NUM_FIELD(phys, val, space) \
-	sprintf(space, "%8.8lx", (unsigned long) (val)); \
-	memcpy(phys, space, 8);
+        sprintf(space, "%8.8lx", (unsigned long) (val)); \
+        memcpy(phys, space, 8);
 
 static int getNextHeader(struct ourfd * fd, struct cpioHeader * chPtr,
-			 struct cpioCrcPhysicalHeader * physHeaderPtr) {
+                         struct cpioCrcPhysicalHeader * physHeaderPtr) {
     struct cpioCrcPhysicalHeader physHeader;
     int nameSize;
     char * end;
     int major, minor;
 
     if (ourread(fd, &physHeader, PHYS_HDR_SIZE) != PHYS_HDR_SIZE) 
-	return CPIOERR_READ_FAILED;
+        return CPIOERR_READ_FAILED;
 
     if (physHeaderPtr)
-	memcpy(physHeaderPtr, &physHeader, PHYS_HDR_SIZE);
+        memcpy(physHeaderPtr, &physHeader, PHYS_HDR_SIZE);
 
     if (strncmp(CPIO_CRC_MAGIC, physHeader.magic, strlen(CPIO_CRC_MAGIC)) &&
-	strncmp(CPIO_NEWC_MAGIC, physHeader.magic, strlen(CPIO_NEWC_MAGIC)))
-	return CPIOERR_BAD_MAGIC;
+        strncmp(CPIO_NEWC_MAGIC, physHeader.magic, strlen(CPIO_NEWC_MAGIC)))
+        return CPIOERR_BAD_MAGIC;
 
     GET_NUM_FIELD(physHeader.inode, chPtr->inode);
     GET_NUM_FIELD(physHeader.mode, chPtr->mode);
@@ -197,8 +197,8 @@ static int getNextHeader(struct ourfd * fd, struct cpioHeader * chPtr,
 
     chPtr->path = malloc(nameSize + 1);
     if (ourread(fd, chPtr->path, nameSize) != nameSize) {
-	free(chPtr->path);
-	return CPIOERR_BAD_HEADER;
+        free(chPtr->path);
+        return CPIOERR_BAD_HEADER;
     }
 
     /* this is unecessary chPtr->path[nameSize] = '\0'; */
@@ -221,32 +221,32 @@ static int createDirectory(char * path, mode_t perms) {
     int dounlink;
 
     if (!lstat(path, &sb)) {
-	if (S_ISDIR(sb.st_mode)) {
-	    return 0;
-	} else if (S_ISLNK(sb.st_mode)) {
-	    if (stat(path, &sb)) {
-		if (errno != ENOENT) 
-		    return CPIOERR_STAT_FAILED;
-		dounlink = 1;
-	    } else {
-		if (S_ISDIR(sb.st_mode))
-		    return 0;
-		dounlink = 1;
-	    }
-	} else {
-	    dounlink = 1;
-	}
-
-	if (dounlink && unlink(path)) {
-	    return CPIOERR_UNLINK_FAILED;
-	}
+        if (S_ISDIR(sb.st_mode)) {
+                return 0;
+        } else if (S_ISLNK(sb.st_mode)) {
+            if (stat(path, &sb)) {
+                if (errno != ENOENT)
+                    return CPIOERR_STAT_FAILED;
+                dounlink = 1;
+            } else {
+                if (S_ISDIR(sb.st_mode))
+                    return 0;
+                dounlink = 1;
+            }
+        } else {
+            dounlink = 1;
+        }
+
+        if (dounlink && unlink(path)) {
+            return CPIOERR_UNLINK_FAILED;
+        }
     }
 
     if (mkdir(path, 000))
-	return CPIOERR_MKDIR_FAILED;
+        return CPIOERR_MKDIR_FAILED;
 
     if (chmod(path, perms))
-	return CPIOERR_CHMOD_FAILED;
+        return CPIOERR_CHMOD_FAILED;
 
     return 0;
 }
@@ -259,16 +259,16 @@ static int setInfo(struct cpioHeader * hdr) {
     stamp.modtime = hdr->mtime;
 
     if (!S_ISLNK(hdr->mode)) {
-	if (!getuid() && chown(hdr->path, hdr->uid, hdr->gid))
-	    rc = CPIOERR_CHOWN_FAILED;
-	if (!rc && chmod(hdr->path, hdr->mode & 07777))
-	    rc = CPIOERR_CHMOD_FAILED;
-	if (!rc && utime(hdr->path, &stamp))
-	    rc = CPIOERR_UTIME_FAILED;
+        if (!getuid() && chown(hdr->path, hdr->uid, hdr->gid))
+            rc = CPIOERR_CHOWN_FAILED;
+        if (!rc && chmod(hdr->path, hdr->mode & 07777))
+            rc = CPIOERR_CHMOD_FAILED;
+        if (!rc && utime(hdr->path, &stamp))
+            rc = CPIOERR_UTIME_FAILED;
     } else {
 #       if ! CHOWN_FOLLOWS_SYMLINK
-	    if (!getuid() && !rc && lchown(hdr->path, hdr->uid, hdr->gid))
-		rc = CPIOERR_CHOWN_FAILED;
+            if (!getuid() && !rc && lchown(hdr->path, hdr->uid, hdr->gid))
+                rc = CPIOERR_CHOWN_FAILED;
 #       endif
     }
 
@@ -288,7 +288,7 @@ static int checkDirectory(char * filename) {
     strcpy(buf, filename);
 
     for (chptr = buf + length - 1; chptr > buf; chptr--) {
-	if (*chptr == '/') break;
+        if (*chptr == '/') break;
     }
 
     if (chptr == buf) return 0;     /* /filename - no directories */
@@ -299,20 +299,20 @@ static int checkDirectory(char * filename) {
     if (lastDirLength == length && !strcmp(buf, lastDir)) return 0;
 
     if (lastDirAlloced < (length + 1)) {
-	lastDirAlloced = length + 100;
-	lastDir = realloc(lastDir, lastDirAlloced);
+        lastDirAlloced = length + 100;
+        lastDir = realloc(lastDir, lastDirAlloced);
     }
 
     strcpy(lastDir, buf);
     lastDirLength = length;
 
     for (chptr = buf + 1; *chptr; chptr++) {
-	if (*chptr == '/') {
-	    *chptr = '\0';
-	    rc = createDirectory(buf, 0755);
-	    *chptr = '/';
-	    if (rc) return rc;
-	}
+        if (*chptr == '/') {
+            *chptr = '\0';
+            rc = createDirectory(buf, 0755);
+            *chptr = '/';
+            if (rc) return rc;
+        }
     }
     rc = createDirectory(buf, 0755);
 
@@ -320,7 +320,7 @@ static int checkDirectory(char * filename) {
 }
 
 static int expandRegular(struct ourfd * fd, struct cpioHeader * hdr,
-			 cpioCallback cb, void * cbData) {
+                         cpioCallback cb, void * cbData) {
     int out;
     char buf[8192];
     int bytesRead;
@@ -330,40 +330,40 @@ static int expandRegular(struct ourfd * fd, struct cpioHeader * hdr,
     struct stat sb;
 
     if (!lstat(hdr->path, &sb))
-	if (unlink(hdr->path))
-	    return CPIOERR_UNLINK_FAILED;
+        if (unlink(hdr->path))
+            return CPIOERR_UNLINK_FAILED;
 
     out = open(hdr->path, O_CREAT | O_WRONLY, 0);
     if (out < 0) 
-	return CPIOERR_OPEN_FAILED;
+        return CPIOERR_OPEN_FAILED;
 
     cbInfo.file = hdr->path;
     cbInfo.fileSize = hdr->size;
 
     while (left) {
-	bytesRead = ourread(fd, buf, left < sizeof(buf) ? left : sizeof(buf));
-	if (bytesRead <= 0) {
-	    rc = CPIOERR_READ_FAILED;
-	    break;
-	}
-
-	if (write(out, buf, bytesRead) != bytesRead) {
-	    rc = CPIOERR_COPY_FAILED;
-	    break;
-	}
-
-	left -= bytesRead;
-
-	/* don't call this with fileSize == fileComplete */
-	if (!rc && cb && left) {
-	    cbInfo.fileComplete = hdr->size - left;
-	    cbInfo.bytesProcessed = fd->pos;
-	    cb(&cbInfo, cbData);
-	}
+        bytesRead = ourread(fd, buf, left < sizeof(buf) ? left : sizeof(buf));
+        if (bytesRead <= 0) {
+            rc = CPIOERR_READ_FAILED;
+            break;
+        }
+
+        if (write(out, buf, bytesRead) != bytesRead) {
+            rc = CPIOERR_COPY_FAILED;
+            break;
+        }
+
+        left -= bytesRead;
+
+        /* don't call this with fileSize == fileComplete */
+        if (!rc && cb && left) {
+            cbInfo.fileComplete = hdr->size - left;
+            cbInfo.bytesProcessed = fd->pos;
+            cb(&cbInfo, cbData);
+        }
     }
 
     close(out);
-    
+
     return rc;
 }
 
@@ -373,28 +373,28 @@ static int expandSymlink(struct ourfd * fd, struct cpioHeader * hdr) {
     int len;
 
     if ((hdr->size + 1)> sizeof(buf))
-	return CPIOERR_INTERNAL;
+        return CPIOERR_INTERNAL;
 
     if (ourread(fd, buf, hdr->size) != hdr->size)
-	return CPIOERR_READ_FAILED;
+        return CPIOERR_READ_FAILED;
 
     buf[hdr->size] = '\0';
 
     if (!lstat(hdr->path, &sb)) {
-	if (S_ISLNK(sb.st_mode)) {
-	    len = readlink(hdr->path, buf2, sizeof(buf2) - 1);
-	    if (len > 0) {
-		buf2[len] = '\0';
-		if (!strcmp(buf, buf2)) return 0;
-	    }
-	}
-
-	if (unlink(hdr->path))
-	    return CPIOERR_UNLINK_FAILED;
+        if (S_ISLNK(sb.st_mode)) {
+            len = readlink(hdr->path, buf2, sizeof(buf2) - 1);
+            if (len > 0) {
+                buf2[len] = '\0';
+                if (!strcmp(buf, buf2)) return 0;
+            }
+        }
+
+        if (unlink(hdr->path))
+            return CPIOERR_UNLINK_FAILED;
     }
 
     if (symlink(buf, hdr->path) < 0)
-	return CPIOERR_SYMLINK_FAILED;
+        return CPIOERR_SYMLINK_FAILED;
 
     return 0;
 }
@@ -403,14 +403,14 @@ static int expandFifo(struct ourfd * fd, struct cpioHeader * hdr) {
     struct stat sb;
 
     if (!lstat(hdr->path, &sb)) {
-	if (S_ISFIFO(sb.st_mode)) return 0;
+        if (S_ISFIFO(sb.st_mode)) return 0;
 
-	if (unlink(hdr->path))
-	    return CPIOERR_UNLINK_FAILED;
+        if (unlink(hdr->path))
+            return CPIOERR_UNLINK_FAILED;
     }
 
     if (mkfifo(hdr->path, 0))
-	return CPIOERR_MKFIFO_FAILED;
+        return CPIOERR_MKFIFO_FAILED;
 
     return 0; 
 }
@@ -419,16 +419,16 @@ static int expandDevice(struct ourfd * fd, struct cpioHeader * hdr) {
     struct stat sb;
 
     if (!lstat(hdr->path, &sb)) {
-	if ((S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) && 
-		(sb.st_rdev == hdr->rdev))
-	    return 0;
-	if (unlink(hdr->path))
-	    return CPIOERR_UNLINK_FAILED;
+        if ((S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) &&
+            (sb.st_rdev == hdr->rdev))
+            return 0;
+        if (unlink(hdr->path))
+            return CPIOERR_UNLINK_FAILED;
     }
 
     if (mknod(hdr->path, hdr->mode & (~0777), hdr->rdev))
-	return CPIOERR_MKNOD_FAILED;
-    
+        return CPIOERR_MKNOD_FAILED;
+
     return 0;
 }
 
@@ -436,7 +436,7 @@ static void freeLink(struct hardLink * li) {
     int i;
 
     for (i = 0; i < li->nlink; i++) {
-	if (li->files[i]) free(li->files[i]);
+        if (li->files[i]) free(li->files[i]);
     }
     free(li->files);
 }
@@ -446,24 +446,24 @@ static int createLinks(struct hardLink * li, const char ** failedFile) {
     struct stat sb;
 
     for (i = 0; i < li->nlink; i++) {
-	if (i == li->createdPath) continue;
-	if (!li->files[i]) continue;
-
-	if (!lstat(li->files[i], &sb)) {
-	    if (unlink(li->files[i])) {
-		*failedFile = strdup(li->files[i]);
-		return CPIOERR_UNLINK_FAILED;
-	    }
-	}
-
-	if (link(li->files[li->createdPath], li->files[i])) {
-	    *failedFile = strdup(li->files[i]);
-	    return CPIOERR_LINK_FAILED;
-	}
-
-	free(li->files[i]);
-	li->files[i] = NULL;
-	li->linksLeft--;
+        if (i == li->createdPath) continue;
+        if (!li->files[i]) continue;
+
+        if (!lstat(li->files[i], &sb)) {
+            if (unlink(li->files[i])) {
+                *failedFile = strdup(li->files[i]);
+                return CPIOERR_UNLINK_FAILED;
+            }
+        }
+
+        if (link(li->files[li->createdPath], li->files[i])) {
+            *failedFile = strdup(li->files[i]);
+            return CPIOERR_LINK_FAILED;
+        }
+
+        free(li->files[i]);
+        li->files[i] = NULL;
+        li->linksLeft--;
     }
 
     return 0;
@@ -472,20 +472,20 @@ static int createLinks(struct hardLink * li, const char ** failedFile) {
 static int eatBytes(struct ourfd * fd, unsigned long amount) {
     char buf[4096];
     unsigned long bite;
-   
+
     while (amount) {
-	bite = (amount > sizeof(buf)) ? sizeof(buf) : amount;
-	if (ourread(fd, buf, bite) != bite)
-	    return CPIOERR_READ_FAILED;
-	amount -= bite;
+        bite = (amount > sizeof(buf)) ? sizeof(buf) : amount;
+        if (ourread(fd, buf, bite) != bite)
+            return CPIOERR_READ_FAILED;
+        amount -= bite;
     }
 
     return 0;
 }
 
-int myCpioInstallArchive(gzFile stream, struct cpioFileMapping * mappings, 
-		       int numMappings, cpioCallback cb, void * cbData,
-		       const char ** failedFile) {
+int myCpioInstallArchive(gzFile stream, struct cpioFileMapping * mappings,
+                         int numMappings, cpioCallback cb, void * cbData,
+                         const char ** failedFile) {
     struct cpioHeader ch;
     struct ourfd fd;
     int rc = 0;
@@ -504,159 +504,159 @@ int myCpioInstallArchive(gzFile stream, struct cpioFileMapping * mappings,
     *failedFile = NULL;
 
     do {
-	if ((rc = getNextHeader(&fd, &ch, NULL))) {
-	    logMessage( WARNING, _("error %d reading header: %s\n"), rc,
-		    myCpioStrerror(rc));
-	    return CPIOERR_BAD_HEADER;
-	}
-
-	if (!strcmp(ch.path, TRAILER)) {
-	    free(ch.path);
-	    break;
-	}
-
-	if (mappings) {
-	    needle.archivePath = ch.path;
-	    map = bsearch(&needle, mappings, numMappings, sizeof(needle),
-			  myCpioFileMapCmp);
-	}
-
-	if (mappings && !map) {
-	    eatBytes(&fd, ch.size);
-	} else {
-	    cpioMode = ch.mode;
-
-	    if (map) {
-		if (map->mapFlags & CPIO_MAP_PATH) {
-		    free(ch.path);
-		    ch.path = strdup(map->fsPath);
-		} 
-
-		if (map->mapFlags & CPIO_MAP_MODE)
-		    ch.mode = map->finalMode;
-		if (map->mapFlags & CPIO_MAP_UID)
-		    ch.uid = map->finalUid;
-		if (map->mapFlags & CPIO_MAP_GID)
-		    ch.gid = map->finalGid;
-	    }
-
-	    /* This won't get hard linked symlinks right, but I can't seem 
-	       to create those anyway */
-
-	    if (S_ISREG(ch.mode) && ch.nlink > 1) {
-		li = links;
-		for (li = links; li; li = li->next) {
-		    if (li->inode == ch.inode && li->dev == ch.dev) break;
-		}
-
-		if (!li) {
-		    li = malloc(sizeof(*li));
-		    li->inode = ch.inode;
-		    li->dev = ch.dev;
-		    li->nlink = ch.nlink;
-		    li->linksLeft = ch.nlink;
-		    li->createdPath = -1;
-		    li->files = calloc(sizeof(char *), li->nlink);
-		    li->next = links;
-		    links = li;
-		}
-
-		for (linkNum = 0; linkNum < li->nlink; linkNum++)
-		    if (!li->files[linkNum]) break;
-		li->files[linkNum] = strdup(ch.path);
-	    }
-		
-	    if ((ch.nlink > 1) && S_ISREG(ch.mode) && !ch.size &&
-		li->createdPath == -1) {
-		/* defer file creation */
-	    } else if ((ch.nlink > 1) && S_ISREG(ch.mode) && 
-		       (li->createdPath != -1)) {
-		createLinks(li, failedFile);
-
-		/* this only happens for cpio archives which contain
-		   hardlinks w/ the contents of each hardlink being
-		   listed (intead of the data being given just once. This
-		   shouldn't happen, but I've made it happen w/ buggy
-		   code, so what the heck? GNU cpio handles this well fwiw */
-		if (ch.size) eatBytes(&fd, ch.size);
-	    } else {
-		rc = checkDirectory(ch.path);
-
-		if (!rc) {
-		    if (S_ISREG(ch.mode))
-			rc = expandRegular(&fd, &ch, cb, cbData);
-		    else if (S_ISDIR(ch.mode))
-			rc = createDirectory(ch.path, 000);
-		    else if (S_ISLNK(ch.mode))
-			rc = expandSymlink(&fd, &ch);
-		    else if (S_ISFIFO(ch.mode))
-			rc = expandFifo(&fd, &ch);
-		    else if (S_ISCHR(ch.mode) || S_ISBLK(ch.mode))
-			rc = expandDevice(&fd, &ch);
-		    else if (S_ISSOCK(ch.mode)) {
-			/* this mimicks cpio but probably isnt' right */
-			rc = expandFifo(&fd, &ch);
-		    } else {
-			rc = CPIOERR_INTERNAL;
-		    }
-		}
-
-		if (!rc)
-		    rc = setInfo(&ch);
-
-		if (S_ISREG(ch.mode) && ch.nlink > 1) {
-		    li->createdPath = linkNum;
-		    li->linksLeft--;
-		    rc = createLinks(li, failedFile);
-		}
-	    }
-
-	    if (rc && !*failedFile) {
-		*failedFile = strdup(ch.path);
-
-		olderr = errno;
-		unlink(ch.path);
-		errno = olderr;
-	    }
-	}
-
-	padinfd(&fd, 4);
-
-	if (!rc && cb) {
-	    cbInfo.file = ch.path;
-	    cbInfo.fileSize = ch.size;
-	    cbInfo.fileComplete = ch.size;
-	    cbInfo.bytesProcessed = fd.pos;
-	    cb(&cbInfo, cbData);
-	}
-
-	free(ch.path);
+        if ((rc = getNextHeader(&fd, &ch, NULL))) {
+            logMessage( WARNING, _("error %d reading header: %s\n"), rc,
+            myCpioStrerror(rc));
+            return CPIOERR_BAD_HEADER;
+        }
+
+        if (!strcmp(ch.path, TRAILER)) {
+            free(ch.path);
+            break;
+        }
+
+        if (mappings) {
+            needle.archivePath = ch.path;
+            map = bsearch(&needle, mappings, numMappings, sizeof(needle),
+                          myCpioFileMapCmp);
+        }
+
+        if (mappings && !map) {
+            eatBytes(&fd, ch.size);
+        } else {
+            cpioMode = ch.mode;
+
+            if (map) {
+                if (map->mapFlags & CPIO_MAP_PATH) {
+                    free(ch.path);
+                    ch.path = strdup(map->fsPath);
+                }
+
+                if (map->mapFlags & CPIO_MAP_MODE)
+                    ch.mode = map->finalMode;
+                if (map->mapFlags & CPIO_MAP_UID)
+                    ch.uid = map->finalUid;
+                if (map->mapFlags & CPIO_MAP_GID)
+                    ch.gid = map->finalGid;
+            }
+
+            /* This won't get hard linked symlinks right, but I can't seem
+               to create those anyway */
+
+            if (S_ISREG(ch.mode) && ch.nlink > 1) {
+                li = links;
+                for (li = links; li; li = li->next) {
+                    if (li->inode == ch.inode && li->dev == ch.dev) break;
+                }
+
+                if (!li) {
+                    li = malloc(sizeof(*li));
+                    li->inode = ch.inode;
+                    li->dev = ch.dev;
+                    li->nlink = ch.nlink;
+                    li->linksLeft = ch.nlink;
+                    li->createdPath = -1;
+                    li->files = calloc(sizeof(char *), li->nlink);
+                    li->next = links;
+                    links = li;
+                }
+
+                for (linkNum = 0; linkNum < li->nlink; linkNum++)
+                    if (!li->files[linkNum]) break;
+                li->files[linkNum] = strdup(ch.path);
+            }
+
+            if ((ch.nlink > 1) && S_ISREG(ch.mode) && !ch.size &&
+                li->createdPath == -1) {
+                /* defer file creation */
+            } else if ((ch.nlink > 1) && S_ISREG(ch.mode) &&
+                       (li->createdPath != -1)) {
+                createLinks(li, failedFile);
+
+                /* this only happens for cpio archives which contain
+                   hardlinks w/ the contents of each hardlink being
+                   listed (intead of the data being given just once. This
+                   shouldn't happen, but I've made it happen w/ buggy
+                   code, so what the heck? GNU cpio handles this well fwiw */
+                if (ch.size) eatBytes(&fd, ch.size);
+            } else {
+                rc = checkDirectory(ch.path);
+
+                if (!rc) {
+                    if (S_ISREG(ch.mode))
+                        rc = expandRegular(&fd, &ch, cb, cbData);
+                    else if (S_ISDIR(ch.mode))
+                        rc = createDirectory(ch.path, 000);
+                    else if (S_ISLNK(ch.mode))
+                        rc = expandSymlink(&fd, &ch);
+                    else if (S_ISFIFO(ch.mode))
+                        rc = expandFifo(&fd, &ch);
+                    else if (S_ISCHR(ch.mode) || S_ISBLK(ch.mode))
+                        rc = expandDevice(&fd, &ch);
+                    else if (S_ISSOCK(ch.mode)) {
+                        /* this mimicks cpio but probably isnt' right */
+                        rc = expandFifo(&fd, &ch);
+                    } else {
+                        rc = CPIOERR_INTERNAL;
+                    }
+                }
+
+                if (!rc)
+                    rc = setInfo(&ch);
+
+                if (S_ISREG(ch.mode) && ch.nlink > 1) {
+                    li->createdPath = linkNum;
+                    li->linksLeft--;
+                    rc = createLinks(li, failedFile);
+                }
+            }
+
+            if (rc && !*failedFile) {
+                *failedFile = strdup(ch.path);
+
+                olderr = errno;
+                unlink(ch.path);
+                errno = olderr;
+            }
+        }
+
+        padinfd(&fd, 4);
+
+        if (!rc && cb) {
+            cbInfo.file = ch.path;
+            cbInfo.fileSize = ch.size;
+            cbInfo.fileComplete = ch.size;
+            cbInfo.bytesProcessed = fd.pos;
+            cb(&cbInfo, cbData);
+        }
+
+        free(ch.path);
     } while (1 && !rc);
 
     li = links;
     while (li && !rc) {
-	if (li->linksLeft) {
-	    if (li->createdPath == -1)
-		rc = CPIOERR_INTERNAL;
-	    else 
-		rc = createLinks(li, failedFile);
-	}
-
-	freeLink(li);
-
-	links = li;
-	li = li->next;
-	free(links);
-	links = li;
+        if (li->linksLeft) {
+            if (li->createdPath == -1)
+                rc = CPIOERR_INTERNAL;
+            else
+                rc = createLinks(li, failedFile);
+        }
+
+        freeLink(li);
+
+        links = li;
+        li = li->next;
+        free(links);
+        links = li;
     }
 
     li = links;
     /* if an error got us here links will still be eating some memory */
     while (li) {
-	freeLink(li);
-	links = li;
-	li = li->next;
-	free(links);
+        freeLink(li);
+        links = li;
+        li = li->next;
+        free(links);
     }
 
     return rc;
@@ -671,50 +671,48 @@ const char * myCpioStrerror(int rc)
     strcpy(msg, "cpio: ");
     switch (rc) {
     default:
-	s = msg + strlen(msg);
-	sprintf(s, _("(error 0x%x)"), rc);
-	s = NULL;
-	break;
-    case CPIOERR_BAD_MAGIC:	s = _("Bad magic");		break;
-    case CPIOERR_BAD_HEADER:	s = _("Bad header");		break;
-
-    case CPIOERR_OPEN_FAILED:	s = "open";	break;
-    case CPIOERR_CHMOD_FAILED:	s = "chmod";	break;
-    case CPIOERR_CHOWN_FAILED:	s = "chown";	break;
-    case CPIOERR_WRITE_FAILED:	s = "write";	break;
-    case CPIOERR_UTIME_FAILED:	s = "utime";	break;
-    case CPIOERR_UNLINK_FAILED:	s = "unlink";	break;
-    case CPIOERR_SYMLINK_FAILED: s = "symlink";	break;
-    case CPIOERR_STAT_FAILED:	s = "stat";	break;
-    case CPIOERR_MKDIR_FAILED:	s = "mkdir";	break;
-    case CPIOERR_MKNOD_FAILED:	s = "mknod";	break;
-    case CPIOERR_MKFIFO_FAILED:	s = "mkfifo";	break;
-    case CPIOERR_LINK_FAILED:	s = "link";	break;
-    case CPIOERR_READLINK_FAILED: s = "readlink";	break;
-    case CPIOERR_READ_FAILED:	s = "read";	break;
-    case CPIOERR_COPY_FAILED:	s = "copy";	break;
-
-    case CPIOERR_INTERNAL:	s = _("Internal error");	break;
-    case CPIOERR_HDR_SIZE:	s = _("Header size too big");	break;
-    case CPIOERR_UNKNOWN_FILETYPE: s = _("Unknown file type");	break;
+        s = msg + strlen(msg);
+        sprintf(s, _("(error 0x%x)"), rc);
+        s = NULL;
+        break;
+    case CPIOERR_BAD_MAGIC:             s = _("Bad magic");     break;
+    case CPIOERR_BAD_HEADER:            s = _("Bad header");    break;
+    case CPIOERR_OPEN_FAILED:           s = "open";             break;
+    case CPIOERR_CHMOD_FAILED:          s = "chmod";            break;
+    case CPIOERR_CHOWN_FAILED:          s = "chown";            break;
+    case CPIOERR_WRITE_FAILED:          s = "write";            break;
+    case CPIOERR_UTIME_FAILED:          s = "utime";            break;
+    case CPIOERR_UNLINK_FAILED:         s = "unlink";           break;
+    case CPIOERR_SYMLINK_FAILED:        s = "symlink";          break;
+    case CPIOERR_STAT_FAILED:           s = "stat";             break;
+    case CPIOERR_MKDIR_FAILED:          s = "mkdir";            break;
+    case CPIOERR_MKNOD_FAILED:          s = "mknod";            break;
+    case CPIOERR_MKFIFO_FAILED:         s = "mkfifo";           break;
+    case CPIOERR_LINK_FAILED:           s = "link";             break;
+    case CPIOERR_READLINK_FAILED:       s = "readlink";         break;
+    case CPIOERR_READ_FAILED:           s = "read";             break;
+    case CPIOERR_COPY_FAILED:           s = "copy";             break;
+    case CPIOERR_INTERNAL:              s = _("Internal error");break;
+    case CPIOERR_HDR_SIZE:              s = _("Header size too big");break;
+    case CPIOERR_UNKNOWN_FILETYPE:      s = _("Unknown file type");break;
     }
 
     l = sizeof(msg) - strlen(msg) - 1;
     if (s != NULL) {
-	if (l > 0) strncat(msg, s, l);
-	l -= strlen(s);
+        if (l > 0) strncat(msg, s, l);
+        l -= strlen(s);
     }
     if (rc & CPIOERR_CHECK_ERRNO) {
-	s = _(" failed - ");
-	if (l > 0) strncat(msg, s, l);
-	l -= strlen(s);
-	if (l > 0) strncat(msg, strerror(myerrno), l);
+        s = _(" failed - ");
+        if (l > 0) strncat(msg, s, l);
+        l -= strlen(s);
+        if (l > 0) strncat(msg, strerror(myerrno), l);
     }
     return msg;
 }
 
 static int copyFile(struct ourfd * inFd, struct ourfd * outFd, 
-	     struct cpioHeader * chp, struct cpioCrcPhysicalHeader * pHdr) {
+             struct cpioHeader * chp, struct cpioCrcPhysicalHeader * pHdr) {
     char buf[8192];
     int amount;
     size_t size = chp->size;
@@ -730,9 +728,9 @@ static int copyFile(struct ourfd * inFd, struct ourfd * outFd,
     padoutfd(outFd, &outFd->pos, 4);
 
     while (size) {
-	amount = ourread(inFd, buf, size > sizeof(buf) ? sizeof(buf) : size);
-	gzip_write(outFd->fd, buf, amount);
-	size -= amount;
+        amount = ourread(inFd, buf, size > sizeof(buf) ? sizeof(buf) : size);
+        gzip_write(outFd->fd, buf, amount);
+        size -= amount;
     }
 
     outFd->pos += chp->size;
@@ -755,29 +753,29 @@ int myCpioFilterArchive(gzFile inStream, gzFile outStream, char ** patterns) {
     outFd.pos = 0;
 
     do {
-	if ((rc = getNextHeader(&inFd, &ch, &pHeader))) {
-	    logMessage( WARNING, _("error %d reading header: %s\n"), rc,
-		    myCpioStrerror(rc));
-	    return CPIOERR_BAD_HEADER;
-	}
+        if ((rc = getNextHeader(&inFd, &ch, &pHeader))) {
+            logMessage( WARNING, _("error %d reading header: %s\n"), rc,
+                    myCpioStrerror(rc));
+            return CPIOERR_BAD_HEADER;
+        }
 
-	if (!strcmp(ch.path, TRAILER)) {
-	    free(ch.path);
-	    break;
-	}
+        if (!strcmp(ch.path, TRAILER)) {
+            free(ch.path);
+            break;
+        }
 
-	for (aPattern = patterns; *aPattern; aPattern++)
-	    if (!fnmatch(*aPattern, ch.path, FNM_PATHNAME | FNM_PERIOD))
-		break;
+        for (aPattern = patterns; *aPattern; aPattern++)
+            if (!fnmatch(*aPattern, ch.path, FNM_PATHNAME | FNM_PERIOD))
+                break;
 
-	if (!*aPattern)
-	    eatBytes(&inFd, ch.size);
-	else
-	    copyFile(&inFd, &outFd, &ch, &pHeader);
+        if (!*aPattern)
+            eatBytes(&inFd, ch.size);
+        else
+            copyFile(&inFd, &outFd, &ch, &pHeader);
 
-	padinfd(&inFd, 4);
+        padinfd(&inFd, 4);
 
-	free(ch.path);
+        free(ch.path);
     } while (1 && !rc);
 
     memset(&pHeader, '0', sizeof(pHeader));
@@ -790,10 +788,10 @@ int myCpioFilterArchive(gzFile inStream, gzFile outStream, char ** patterns) {
     outFd.pos += PHYS_HDR_SIZE + 11;
 
     if ((rc = padoutfd(&outFd, &outFd.pos, 4)))
-	return rc;
+        return rc;
 
     if ((rc = padoutfd(&outFd, &outFd.pos, 512)))
-	return rc;
+        return rc;
 
     return 0;
 }
-- 
1.7.1.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux