From: ewt Date: Wed, 16 Jul 1997 01:56:14 +0000 (+0000) Subject: Don't bother creating devices/symlinks which already exist X-Git-Tag: rpm-4.4-release~3992 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f8dd5dd2f90b4dea934737de4d76e3e0a222303;p=platform%2Fupstream%2Frpm.git Don't bother creating devices/symlinks which already exist CVS patchset: 1743 CVS date: 1997/07/16 01:56:14 --- diff --git a/CHANGES b/CHANGES index 8cc8eb8..8b67b19 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,8 @@ are present - check symlink() return for < 0, not != 0 (Bob Tanner) - uses chroot() for installs --root option + - archive expansion doesn't create new devices or symlinks when + the proper files already exist 2.4.1 -> 2.4.2: - completely rewrote queryformat code diff --git a/lib/cpio.c b/lib/cpio.c index c9025e4..0d7ae1e 100644 --- a/lib/cpio.c +++ b/lib/cpio.c @@ -199,7 +199,7 @@ static int setInfo(struct cpioHeader * hdr) { if (!S_ISLNK(hdr->mode)) { - if (!getuid() && !rc && chown(hdr->path, hdr->uid, hdr->gid)) + if (!getuid() && chown(hdr->path, hdr->uid, hdr->gid)) rc = CPIO_CHOWN_FAILED; if (!rc && chmod(hdr->path, hdr->mode & 07777)) rc = CPIO_CHMOD_FAILED; @@ -308,12 +308,9 @@ static int expandRegular(struct ourfd * fd, struct cpioHeader * hdr, } static int expandSymlink(struct ourfd * fd, struct cpioHeader * hdr) { - char buf[2048]; + char buf[2048], buf2[2048]; struct stat sb; - - if (!lstat(hdr->path, &sb)) - if (unlink(hdr->path)) - return CPIO_UNLINK_FAILED; + int len; if ((hdr->size + 1)> sizeof(buf)) return CPIO_INTERNAL; @@ -323,6 +320,19 @@ static int expandSymlink(struct ourfd * fd, struct cpioHeader * hdr) { 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 CPIO_UNLINK_FAILED; + } + if (symlink(buf, hdr->path) < 0) return CPIO_SYMLINK_FAILED; @@ -348,9 +358,13 @@ static int expandFifo(struct ourfd * fd, struct cpioHeader * hdr) { static int expandDevice(struct ourfd * fd, struct cpioHeader * hdr) { struct stat sb; - if (!lstat(hdr->path, &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 CPIO_UNLINK_FAILED; + } if (mknod(hdr->path, hdr->mode & (~0777), hdr->rdev)) return CPIO_MKNOD_FAILED;