More dead code elimination, use data from rpmfi instead

- We have the symlink target in rpmfi already, no need to re-read
  it from the disk. Also all the fiddling with st_size is unnecessary
  here, its done on the archive side as necessary
This commit is contained in:
Panu Matilainen 2013-11-04 16:47:17 +02:00
parent 760abcf0b4
commit 8c36e96f98
1 changed files with 5 additions and 24 deletions

View File

@ -550,33 +550,14 @@ static int fsmReadLink(const char *path,
static int writeFile(FSM_t fsm, int writeData, int ix)
{
FD_t rfd = NULL;
struct stat * st = &fsm->sb;
struct stat * ost = &fsm->osb;
char * symbuf = NULL;
rpmfi fi = fsm->fi;
int rc = 0;
st->st_size = (writeData ? ost->st_size : 0);
if (S_ISDIR(st->st_mode)) {
st->st_size = 0;
} else if (S_ISLNK(st->st_mode)) {
/*
* While linux puts the size of a symlink in the st_size field,
* I don't think that's a specified standard.
*/
size_t linklen;
rc = fsmReadLink(fsm->path, fsm->buf, fsm->bufsize, &linklen);
if (rc) goto exit;
st->st_size = linklen;
rstrcat(&symbuf, fsm->buf); /* XXX save readlink return. */
}
rc = rpmfiArchiveWriteHeader(fi);
if (rc) goto exit;
if (writeData && S_ISREG(st->st_mode)) {
if (writeData && S_ISREG(rpmfiFMode(fi))) {
rfd = Fopen(fsm->path, "r.ufdio");
if (Ferror(rfd)) {
rc = CPIOERR_OPEN_FAILED;
@ -585,9 +566,10 @@ static int writeFile(FSM_t fsm, int writeData, int ix)
rc = rpmfiArchiveWriteFile(fi, rfd);
} else if (writeData && S_ISLNK(st->st_mode)) {
size_t len = strlen(symbuf);
if (rpmfiArchiveWrite(fi, symbuf, len) != len) {
} else if (writeData && S_ISLNK(rpmfiFMode(fi))) {
const char *lnk = rpmfiFLink(fi);
size_t len = strlen(lnk);
if (rpmfiArchiveWrite(fi, lnk, len) != len) {
rc = CPIOERR_WRITE_FAILED;
goto exit;
}
@ -600,7 +582,6 @@ exit:
Fclose(rfd);
errno = myerrno;
}
free(symbuf);
return rc;
}