Use Fstrerror on ufdio throughut.

rpm.c: add --rmspec to usage output.
build/files.c: use ufdio to permit '%files -f <url>' (untested).
build/pack.c: use ufdio in readRPM(), writeRPM(), and addFileToTag().
build/parsePreamble.c: use ufdio in readIcon().
lib/ftp.c: httpOpen() now takes FD_t ctrl arg to uncouple from u->ctrl.
lib/install.c: usr rpmGenPath() to identify first found url in file path concat.
lib/install.c: permit url's in files[i].relativePath.
lib/macro.c: use ufdio, diddle macros for tmacro standalone build.
lib/macro.c: Create rpmGenPath().
lib/macro.c: diddle macro files path to permit url's.
lib/rpmchecksig.c: use Fopen on fdio.
lib/rpmio.c: replace copyData() with ufdCopy().
lib/rpmio.c: replace httpGetFile() with ufdGetFile().
lib/rpmio.c: add ufdWrite().
lib/rpmio.c: permit 2 simultaneous persistent malloc/open HTTP/1.1 connections.
lib/rpmio.c: Add Lstat(), Stat(), and Access().
lib/rpmio.c: assume paths in syscall stubs are loopback (WRONG).
lib/url.c: add urlPath().

CVS patchset: 3422
CVS date: 1999/11/12 17:20:49
This commit is contained in:
jbj 1999-11-12 17:20:49 +00:00
parent e0b1d0be36
commit 8ce88756fd
21 changed files with 648 additions and 413 deletions

View File

@ -87,6 +87,7 @@ int doScript(Spec spec, int what, const char *name, StringBuf sb, int test)
#ifdef HAVE_FCHMOD
(void)fchmod(Fileno(fd), 0600); /* XXX fubar on ufdio */
#endif
/* XXX FIXME: build/build.c Fdopen assertion failure, makeTempFile uses fdio */
xfd = Fdopen(fd, "w.fdio");
strcpy(buf, _preScriptEnvironment);

View File

@ -1161,7 +1161,6 @@ static int processPackageFiles(Spec spec, Package pkg,
char *s, **files, **fp;
const char *fileName;
char buf[BUFSIZ];
FILE *f;
AttrRec specialDocAttrRec;
char *specialDoc = NULL;
@ -1171,20 +1170,22 @@ static int processPackageFiles(Spec spec, Package pkg,
if (pkg->fileFile) {
const char *ffn;
FD_t fd;
/* XXX FIXME: add %{_buildsubdir} */
ffn = rpmGetPath("%{_builddir}/",
(spec->buildSubdir ? spec->buildSubdir : "") ,
"/", pkg->fileFile, NULL);
f = fopen(ffn, "r");
fd = Fopen(ffn, "r.ufdio");
xfree(ffn);
if (f == NULL) {
if (fd == NULL || Ferror(fd)) {
rpmError(RPMERR_BADFILENAME,
_("Could not open %%files file: %s"), pkg->fileFile);
_("Could not open %%files file %s: %s"),
pkg->fileFile, Fstrerror(fd));
return RPMERR_BADFILENAME;
}
while (fgets(buf, sizeof(buf), f)) {
while (fgets(buf, sizeof(buf), fpio->ffileno(fd))) {
handleComments(buf);
if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
rpmError(RPMERR_BADSPEC, _("line: %s"), buf);
@ -1192,7 +1193,7 @@ static int processPackageFiles(Spec spec, Package pkg,
}
appendStringBuf(pkg->fileList, buf);
}
fclose(f);
Fclose(fd);
}
/* Init the file list structure */
@ -1506,7 +1507,7 @@ int processSourceFiles(Spec spec)
case URL_IS_DASH: /* stdin */
case URL_IS_FTP: /* ftp://... */
case URL_IS_HTTP: /* http://... */
continue; /* XXX just skip for now */
continue; /* XXX WRONG WRONG WRONG */
}
flp->diskName = xstrdup(s);

View File

@ -10,7 +10,7 @@
#define RPM_MAJOR_NUMBER 3
static int processScriptFiles(Spec spec, Package pkg);
static StringBuf addFileToTagAux(Spec spec, char *file, StringBuf sb);
static StringBuf addFileToTagAux(Spec spec, const char *file, StringBuf sb);
static int addFileToTag(Spec spec, char *file, Header h, int tag);
static int addFileToArrayTag(Spec spec, char *file, Header h, int tag);
@ -179,8 +179,8 @@ int readRPM(const char *fileName, Spec *specp, struct rpmlead *lead, Header *sig
int rc;
if (fileName != NULL) {
fdi = Fopen(fileName, "r.fdio");
if (Ferror(fdi)) {
fdi = Fopen(fileName, "r.ufdio");
if (fdi == NULL || Ferror(fdi)) {
rpmError(RPMERR_BADMAGIC, _("readRPM: open %s: %s\n"), fileName,
Fstrerror(fdi));
return RPMERR_BADMAGIC;
@ -307,9 +307,10 @@ int writeRPM(Header h, const char *fileName, int type,
}
/* Open the output file */
fd = Fopen(fileName, "w.fdio");
if (Ferror(fd)) {
rpmError(RPMERR_CREATE, _("Could not open %s: %s\n"), fileName, Fstrerror(fd));
fd = Fopen(fileName, "w.ufdio");
if (fd == NULL || Ferror(fd)) {
rpmError(RPMERR_CREATE, _("Could not open %s: %s\n"),
fileName, Fstrerror(fd));
unlink(sigtarget);
xfree(sigtarget);
return RPMERR_CREATE;
@ -370,11 +371,20 @@ int writeRPM(Header h, const char *fileName, int type,
rpmFreeSignature(sig);
/* Append the header and archive */
ifd = Fopen(sigtarget, "r.fdio");
ifd = Fopen(sigtarget, "r.ufdio");
if (ifd == NULL || Ferror(ifd)) {
rpmError(RPMERR_READERROR, _("Unable to open sigtarget %s: %s"),
sigtarget, Fstrerror(ifd));
Fclose(fd);
Unlink(sigtarget);
xfree(sigtarget);
Unlink(fileName);
return RPMERR_READERROR;
}
while ((count = Fread(buf, sizeof(buf[0]), sizeof(buf), ifd)) > 0) {
if (count == -1) {
rpmError(RPMERR_READERROR, _("Unable to read sigtarget: %s"),
Fstrerror(ifd));
rpmError(RPMERR_READERROR, _("Unable to read sigtarget %s: %s"),
sigtarget, Fstrerror(ifd));
Fclose(ifd);
Fclose(fd);
unlink(sigtarget);
@ -383,8 +393,8 @@ int writeRPM(Header h, const char *fileName, int type,
return RPMERR_READERROR;
}
if (Fwrite(buf, sizeof(buf[0]), count, fd) < 0) {
rpmError(RPMERR_NOSPACE, _("Unable to write package: %s"),
Fstrerror(fd));
rpmError(RPMERR_NOSPACE, _("Unable to write package %s: %s"),
fileName, Fstrerror(fd));
Fclose(ifd);
Fclose(fd);
unlink(sigtarget);
@ -446,29 +456,37 @@ static int cpio_copy(FD_t fdo, CSA_t *csa)
return 0;
}
static StringBuf addFileToTagAux(Spec spec, char *file, StringBuf sb)
static StringBuf addFileToTagAux(Spec spec, const char *file, StringBuf sb)
{
char buf[BUFSIZ];
FILE *f;
const char *fn = buf;
FD_t fd;
strcpy(buf, "%{_builddir}/");
expandMacros(spec, spec->macros, buf, sizeof(buf));
strcat(buf, spec->buildSubdir);
strcat(buf, "/");
strcat(buf, file);
#ifdef DYING
strcpy(fn, "%{_builddir}/");
expandMacros(spec, spec->macros, fn, sizeof(fn));
strcat(fn, spec->buildSubdir);
strcat(fn, "/");
strcat(fn, file);
#else
fn = rpmGetPath("%{_builddir}/", spec->buildSubdir, "/", file, NULL);
#endif
if ((f = fopen(buf, "r")) == NULL) {
fd = Fopen(fn, "r.ufdio");
if (fn != buf) xfree(fn);
if (fd == NULL || Ferror(fd)) {
freeStringBuf(sb);
return NULL;
}
while (fgets(buf, sizeof(buf), f)) {
while (fgets(buf, sizeof(buf), fpio->ffileno(fd))) {
/* XXX display fn in error msg */
if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
rpmError(RPMERR_BADSPEC, _("line: %s"), buf);
return NULL;
}
appendStringBuf(sb, buf);
}
fclose(f);
Fclose(fd);
return sb;
}

View File

@ -231,12 +231,13 @@ static int readIcon(Header h, const char *file)
char *icon;
struct stat statbuf;
FD_t fd;
int rc;
int rc = 0;
int nb;
/* XXX use rpmGenPath(rootdir, "%{_sourcedir}/", file) for icon path. */
fn = rpmGetPath("%{_sourcedir}/", file, NULL);
if (stat(fn, &statbuf)) {
if (Stat(fn, &statbuf)) {
rpmError(RPMERR_BADSPEC, _("Unable to stat icon: %s"), fn);
rc = RPMERR_BADSPEC;
goto exit;
@ -244,16 +245,23 @@ static int readIcon(Header h, const char *file)
icon = xmalloc(statbuf.st_size);
*icon = '\0';
fd = Fopen(fn, "r.fdio");
/* XXX Fstrerror */
/* XXX Ferror check */
nb = Fread(icon, sizeof(char), statbuf.st_size, fd);
Fclose(fd);
if (nb != statbuf.st_size) {
rpmError(RPMERR_BADSPEC, _("Unable to read icon: %s"), fn);
fd = Fopen(fn, "r.ufdio");
if (fd == NULL || Ferror(fd)) {
rpmError(RPMERR_BADSPEC, _("Unable to open icon %s: %s"),
fn, Fstrerror(fd));
rc = RPMERR_BADSPEC;
goto exit;
}
nb = Fread(icon, sizeof(char), statbuf.st_size, fd);
if (nb != statbuf.st_size) {
rpmError(RPMERR_BADSPEC, _("Unable to read icon %s: %s"),
fn, Fstrerror(fd));
rc = RPMERR_BADSPEC;
}
Fclose(fd);
if (rc)
goto exit;
if (! strncmp(icon, "GIF", sizeof("GIF")-1)) {
headerAddEntry(h, RPMTAG_GIF, RPM_BIN_TYPE, icon, statbuf.st_size);
@ -264,8 +272,7 @@ static int readIcon(Header h, const char *file)
rc = RPMERR_BADSPEC;
goto exit;
}
free(icon);
rc = 0;
xfree(icon);
exit:
FREE(fn);
@ -387,7 +394,9 @@ static int handlePreambleTag(Spec spec, Package pkg, int tag, char *macro,
case RPMTAG_BUILDROOT:
SINGLE_TOKEN_ONLY;
if (spec->buildRoot == NULL) {
/* XXX use rpmGenPath(rootdir, "%{buildroot}/", file) for buildroot path. */
const char *buildroot = rpmGetPath("%{buildroot}", NULL);
/* XXX FIXME make sure that buildroot has path, add urlbuildroot. */
if (buildroot && *buildroot != '%') {
spec->buildRoot = xstrdup(cleanFileName(buildroot));
macro = NULL;

View File

@ -1,6 +1,7 @@
#include "system.h"
#include "rpmbuild.h"
#include <rpmbuild.h>
#include <rpmurl.h>
/* These have to be global to make up for stupid compilers */
static int leaveDirs, skipDefaultAction;
@ -21,7 +22,7 @@ static int checkOwners(const char *file)
{
struct stat sb;
if (lstat(file, &sb)) {
if (Lstat(file, &sb)) {
rpmError(RPMERR_BADSPEC, _("Bad source: %s: %s"), file, strerror(errno));
return RPMERR_BADSPEC;
}
@ -36,11 +37,12 @@ static int checkOwners(const char *file)
/*@observer@*/ static char *doPatch(Spec spec, int c, int strip, const char *db,
int reverse, int removeEmpties)
{
const char *fn = NULL;
const char *fn, *urlfn;
static char buf[BUFSIZ];
char args[BUFSIZ];
struct Source *sp;
int compressed = 0;
int urltype;
for (sp = spec->sources; sp != NULL; sp = sp->next) {
if ((sp->flags & RPMBUILD_ISPATCH) && (sp->num == c)) {
@ -52,7 +54,7 @@ static int checkOwners(const char *file)
return NULL;
}
fn = rpmGetPath("%{_sourcedir}/", sp->source, NULL);
fn = urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL);
args[0] = '\0';
if (db) {
@ -70,43 +72,58 @@ static int checkOwners(const char *file)
}
/* XXX On non-build parse's, file cannot be stat'd or read */
if (!spec->force && (isCompressed(fn, &compressed) || checkOwners(fn))) {
xfree(fn);
if (!spec->force && (isCompressed(urlfn, &compressed) || checkOwners(urlfn))) {
xfree(urlfn);
return NULL;
}
urltype = urlPath(urlfn, &fn);
switch (urltype) {
case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
case URL_IS_PATH:
case URL_IS_UNKNOWN:
break;
case URL_IS_DASH:
xfree(urlfn);
return NULL;
/*@notreached@*/ break;
}
if (compressed) {
const char *zipper = rpmGetPath(
(compressed == COMPRESSED_BZIP2 ? "%{_bzip2bin}" : "%{_gzipbin}"),
NULL);
sprintf(buf,
"echo \"Patch #%d:\"\n"
"echo \"Patch #%d (%s):\"\n"
"%s -d < %s | patch -p%d %s -s\n"
"STATUS=$?\n"
"if [ $STATUS -ne 0 ]; then\n"
" exit $STATUS\n"
"fi",
c,
c, basename(fn),
zipper,
fn, strip, args);
xfree(zipper);
} else {
sprintf(buf,
"echo \"Patch #%d:\"\n"
"patch -p%d %s -s < %s", c, strip, args, fn);
"echo \"Patch #%d (%s):\"\n"
"patch -p%d %s -s < %s", c, basename(fn), strip, args, fn);
}
xfree(fn);
xfree(urlfn);
return buf;
}
/*@observer@*/ static const char *doUntar(Spec spec, int c, int quietly)
{
const char *fn;
const char *fn, *urlfn;
static char buf[BUFSIZ];
char *taropts;
struct Source *sp;
int compressed = 0;
int urltype;
for (sp = spec->sources; sp != NULL; sp = sp->next) {
if ((sp->flags & RPMBUILD_ISSOURCE) && (sp->num == c)) {
@ -118,7 +135,7 @@ static int checkOwners(const char *file)
return NULL;
}
fn = rpmGetPath("%{_sourcedir}/", sp->source, NULL);
fn = urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL);
taropts = ((rpmIsVerbose() && !quietly) ? "-xvvf" : "-xf");
@ -130,9 +147,9 @@ static int checkOwners(const char *file)
if (sp->flags & RPMTAG_NOSOURCE && autofetchnosource) {
struct stat st;
int rc;
if (lstat(fn, &st) != 0 && errno == ENOENT &&
if (Lstat(urlfn, &st) != 0 && errno == ENOENT &&
urlIsUrl(sp->fullSource) != URL_IS_UNKNOWN) {
if ((rc = urlGetFile(sp->fullSource, fn)) != 0) {
if ((rc = urlGetFile(sp->fullSource, urlfn)) != 0) {
rpmError(RPMERR_BADFILENAME, _("Couldn't download nosource %s: %s"),
sp->fullSource, ftpStrerror(rc));
return NULL;
@ -142,11 +159,24 @@ static int checkOwners(const char *file)
#endif
/* XXX On non-build parse's, file cannot be stat'd or read */
if (!spec->force && (isCompressed(fn, &compressed) || checkOwners(fn))) {
xfree(fn);
if (!spec->force && (isCompressed(urlfn, &compressed) || checkOwners(urlfn))) {
xfree(urlfn);
return NULL;
}
urltype = urlPath(urlfn, &fn);
switch (urltype) {
case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
case URL_IS_PATH:
case URL_IS_UNKNOWN:
break;
case URL_IS_DASH:
xfree(urlfn);
return NULL;
/*@notreached@*/ break;
}
if (compressed) {
const char *zipper = rpmGetPath(
(compressed == COMPRESSED_BZIP2 ? "%{_bzip2bin}" : "%{_gzipbin}"),
@ -164,7 +194,7 @@ static int checkOwners(const char *file)
sprintf(buf, "tar %s %s", taropts, fn);
}
xfree(fn);
xfree(urlfn);
return buf;
}

View File

@ -23,23 +23,11 @@ unsigned int dbiIndexRecordFileNumber(dbiIndexSet set, int recno) {
return set.recs[recno].fileNumber;
}
dbiIndex * dbiOpenIndex(const char * filename, int flags, int perms, DBTYPE type) {
dbiIndex * dbiOpenIndex(const char * urlfn, int flags, int perms, DBTYPE type) {
dbiIndex * dbi;
const char * filename;
int urltype = urlPath(urlfn, &filename);
switch (urlIsURL(filename)) {
case URL_IS_PATH:
filename += sizeof("file://") - 1;
filename = strchr(filename, '/');
/*@fallthrough@*/
case URL_IS_UNKNOWN:
break;
case URL_IS_DASH:
case URL_IS_FTP:
case URL_IS_HTTP:
default:
return NULL;
/*@notreached@*/ break;
}
dbi = xmalloc(sizeof(*dbi));
dbi->db = dbopen(filename, flags, perms, type, NULL);
if (!dbi->db) {

View File

@ -344,7 +344,7 @@ errxit:
return rc;
}
int httpOpen(urlinfo u, const char *httpcmd)
int httpOpen(urlinfo u, FD_t ctrl, const char *httpcmd)
{
const char *host;
const char *path;
@ -355,7 +355,7 @@ int httpOpen(urlinfo u, const char *httpcmd)
int retrying = 0;
URLSANE(u);
assert(u->ctrl != NULL);
assert(ctrl != NULL);
if (((host = (u->proxyh ? u->proxyh : u->host)) == NULL))
return FTPERR_BAD_HOSTNAME;
@ -364,16 +364,16 @@ int httpOpen(urlinfo u, const char *httpcmd)
path = (u->proxyh || u->proxyp > 0) ? u->url : u->path;
reopen:
if (fdio->fileno(u->ctrl) >= 0 && fdWritable(u->ctrl, 0) < 1)
fdio->close(u->ctrl);
if (fdio->fileno(ctrl) >= 0 && fdWritable(ctrl, 0) < 1)
fdio->close(ctrl);
if (fdio->fileno(u->ctrl) < 0) {
if (fdio->fileno(ctrl) < 0) {
rc = tcpConnect(host, port);
fdSetFdno(u->ctrl, (rc >= 0 ? rc : -1));
fdSetFdno(ctrl, (rc >= 0 ? rc : -1));
if (rc < 0)
goto errxit;
u->ctrl = fdLink(u->ctrl, "open ctrl (httpOpen)");
ctrl = fdLink(ctrl, "open ctrl (httpOpen)");
}
len = sizeof("\
@ -397,7 +397,7 @@ Accept: text/plain\r\n\
DBG(0, (stderr, "-> %s", req));
if (fdio->write(u->ctrl, req, len) != len) {
if (fdio->write(ctrl, req, len) != len) {
rc = FTPERR_SERVER_IO_ERROR;
goto errxit;
}
@ -415,8 +415,10 @@ fprintf(stderr, "*** httpOpen: rc %d ec %d\n", rc, ec);
/*@fallthrough@*/
default:
if (!retrying) { /* not HTTP_OK */
if (_ftp_debug)
fprintf(stderr, "*** httpOpen ctrl %p reopening ...\n", ctrl);
retrying = 1;
fdio->close(u->ctrl);
fdio->close(ctrl);
goto reopen;
}
rc = FTPERR_FILE_NOT_FOUND;
@ -425,12 +427,12 @@ fprintf(stderr, "*** httpOpen: rc %d ec %d\n", rc, ec);
}
}
u->ctrl = fdLink(u->ctrl, "open data (httpOpen)");
return fdio->fileno(u->ctrl);
ctrl = fdLink(ctrl, "open data (httpOpen)");
return fdio->fileno(ctrl);
errxit:
if (fdio->fileno(u->ctrl) >= 0)
fdio->close(u->ctrl);
if (fdio->fileno(ctrl) >= 0)
fdio->close(ctrl);
return rc;
}
@ -494,17 +496,17 @@ errxit:
return rc;
}
int ftpFileDone(urlinfo u, FD_t fd)
int ftpFileDone(urlinfo u, FD_t data)
{
int rc = 0;
int ftpFileDoneNeeded;
URLSANE(u);
ftpFileDoneNeeded = fdGetFtpFileDoneNeeded(fd);
ftpFileDoneNeeded = fdGetFtpFileDoneNeeded(data);
assert(ftpFileDoneNeeded);
if (ftpFileDoneNeeded) {
fdSetFtpFileDoneNeeded(fd, 0);
fdSetFtpFileDoneNeeded(data, 0);
u->ctrl = fdFree(u->ctrl, "open data (ftpFileDone)");
u->ctrl = fdFree(u->ctrl, "grab data (ftpFileDone)");
rc = ftpCheckResponse(u, NULL);
@ -512,7 +514,7 @@ int ftpFileDone(urlinfo u, FD_t fd)
return rc;
}
int ftpFileDesc(urlinfo u, const char *cmd, FD_t fd)
int ftpFileDesc(urlinfo u, const char *cmd, FD_t data)
{
struct sockaddr_in dataAddress;
int cmdlen;
@ -532,7 +534,7 @@ int ftpFileDesc(urlinfo u, const char *cmd, FD_t fd)
* XXX transfer complete message (if ftpFileDone() was not
* XXX called to clear that message). Detect that condition now.
*/
ftpFileDoneNeeded = fdGetFtpFileDoneNeeded(fd);
ftpFileDoneNeeded = fdGetFtpFileDoneNeeded(data);
assert(ftpFileDoneNeeded == 0);
/*
@ -608,39 +610,39 @@ int ftpFileDesc(urlinfo u, const char *cmd, FD_t fd)
}
rc = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
fdSetFdno(fd, (rc >= 0 ? rc : -1));
fdSetFdno(data, (rc >= 0 ? rc : -1));
if (rc < 0) {
rc = FTPERR_FAILED_CONNECT;
goto errxit;
}
fd = fdLink(fd, "open data (ftpFileDesc)");
data = fdLink(data, "open data (ftpFileDesc)");
/* XXX setsockopt SO_LINGER */
/* XXX setsockopt SO_KEEPALIVE */
/* XXX setsockopt SO_TOS IPTOS_THROUGHPUT */
while (connect(fdio->fileno(fd), (struct sockaddr *) &dataAddress,
while (connect(fdio->fileno(data), (struct sockaddr *) &dataAddress,
sizeof(dataAddress)) < 0) {
if (errno == EINTR)
continue;
fdio->close(fd);
fdio->close(data);
rc = FTPERR_FAILED_DATA_CONNECT;
goto errxit;
}
DBG(0, (stderr, "-> %s", cmd));
if (fdio->write(u->ctrl, cmd, cmdlen) != cmdlen) {
fdio->close(fd);
fdio->close(data);
rc = FTPERR_SERVER_IO_ERROR;
goto errxit;
}
if ((rc = ftpCheckResponse(u, NULL))) {
fdio->close(fd);
fdio->close(data);
goto errxit;
}
fdSetFtpFileDoneNeeded(fd, 1);
fdSetFtpFileDoneNeeded(data, 1);
u->ctrl = fdLink(u->ctrl, "grab data (ftpFileDesc)");
u->ctrl = fdLink(u->ctrl, "open data (ftpFileDesc)");
return 0;

View File

@ -1,12 +1,13 @@
#include "system.h"
#include <rpmlib.h>
#include <rpmmacro.h>
#include <rpmurl.h>
#include "cpio.h"
#include "install.h"
#include "misc.h"
#include "rpmdb.h"
#include <rpmmacro.h>
struct callbackInfo {
unsigned long archiveSize;
@ -302,6 +303,7 @@ static int installArchive(FD_t fd, struct fileInfo * files,
const char * failedFile = NULL;
struct callbackInfo info;
FD_t cfd;
int urltype;
if (!files) {
/* install all files */
@ -326,7 +328,11 @@ static int installArchive(FD_t fd, struct fileInfo * files,
if (!files[i].install) continue;
map[mappedFiles].archivePath = files[i].cpioPath;
#ifdef DYING
map[mappedFiles].fsPath = files[i].relativePath;
#else
urltype = urlPath(files[i].relativePath, &map[mappedFiles].fsPath);
#endif
map[mappedFiles].finalMode = files[i].mode;
map[mappedFiles].finalUid = files[i].uid;
map[mappedFiles].finalGid = files[i].gid;
@ -398,12 +404,12 @@ static int installSources(Header h, const char * rootdir, FD_t fd,
rpmMessage(RPMMESS_DEBUG, _("installing a source package\n"));
realSourceDir = rpmGetPath(rootdir, "/%{_sourcedir}", NULL);
if (stat(realSourceDir, &st) < 0) {
realSourceDir = rpmGenPath(rootdir, "%{_sourcedir}", "");
if ((rc = Stat(realSourceDir, &st)) < 0) {
switch (errno) {
case ENOENT:
/* XXX this will only create last component of directory path */
if (mkdir(realSourceDir, 0755) == 0)
if (Mkdir(realSourceDir, 0755) == 0)
break;
/*@fallthrough@*/
default:
@ -414,15 +420,15 @@ static int installSources(Header h, const char * rootdir, FD_t fd,
/*@notreached@*/ break;
}
}
if (access(realSourceDir, W_OK)) {
if ((rc = Access(realSourceDir, W_OK))) {
rpmError(RPMERR_CREATE, _("cannot write to %s"), realSourceDir);
rc = 2;
goto exit;
}
rpmMessage(RPMMESS_DEBUG, _("sources in: %s\n"), realSourceDir);
realSpecDir = rpmGetPath(rootdir, "/%{_specdir}", NULL);
if (stat(realSpecDir, &st) < 0) {
realSpecDir = rpmGenPath(rootdir, "%{_specdir}", "");
if ((rc = Stat(realSpecDir, &st)) < 0) {
switch (errno) {
case ENOENT:
/* XXX this will only create last component of directory path */
@ -436,7 +442,7 @@ static int installSources(Header h, const char * rootdir, FD_t fd,
/*@notreached@*/ break;
}
}
if (access(realSpecDir, W_OK)) {
if ((rc = Access(realSpecDir, W_OK))) {
rpmError(RPMERR_CREATE, _("cannot write to %s"), realSpecDir);
rc = 2;
goto exit;
@ -523,13 +529,15 @@ static int installSources(Header h, const char * rootdir, FD_t fd,
xfree(specFile);
rpmMessage(RPMMESS_DEBUG,
if (strcmp(instSpecFile, correctSpecFile)) {
rpmMessage(RPMMESS_DEBUG,
_("renaming %s to %s\n"), instSpecFile, correctSpecFile);
if (rename(instSpecFile, correctSpecFile)) {
rpmError(RPMERR_RENAME, _("rename of %s to %s failed: %s"),
instSpecFile, correctSpecFile, strerror(errno));
rc = 2;
goto exit;
if ((rc = Rename(instSpecFile, correctSpecFile))) {
rpmError(RPMERR_RENAME, _("rename of %s to %s failed: %s"),
instSpecFile, correctSpecFile, strerror(errno));
rc = 2;
goto exit;
}
}
if (specFilePtr)

View File

@ -23,16 +23,24 @@
#define RPMERR_BADSPEC stderr
#undef _
#define _(x) x
#define vmefail() (exit(1), NULL)
#define xfree(_p) free((void *)_p)
typedef int FD_t;
#define Ferror(_x) (_x)
#define fdOpen open
#define Fread(_b, _s, _n, _fd) read(_fd, _b, _s)
#define Fclose(_fd) close(_fd)
#define urlPath(_xr, _r) *(_r) = (_xr)
typedef FILE * FD_t;
#define Fopen(_path, _fmode) fopen(_path, "_r");
#define Ferror ferror
#define Fstrerror(_fd) strerror(errno)
#define Fread fread
#define Fclose fclose
#else
#include <rpmlib.h>
#include <rpmio.h>
#define fdOpen fdio->open
#include <rpmurl.h>
#endif
#include <rpmmacro.h>
@ -185,7 +193,7 @@ findEntry(MacroContext *mc, const char *name, size_t namelen)
/* fgets analogue that reads \ continuations. Last newline always trimmed. */
static char *
rdcl(char *buf, size_t size, FILE *fp, int escapes)
rdcl(char *buf, size_t size, FD_t fd, int escapes)
{
char *q = buf;
size_t nb = 0;
@ -193,7 +201,7 @@ rdcl(char *buf, size_t size, FILE *fp, int escapes)
*q = '\0';
do {
if (fgets(q, size, fp) == NULL) /* read next line */
if (fgets(q, size, fpio->ffileno(fd)) == NULL) /* read next line */
break;
nb = strlen(q);
nread += nb;
@ -1266,10 +1274,15 @@ initMacros(MacroContext *mc, const char *macrofiles)
mc = &globalMacroContext;
for (mfile = m = xstrdup(macrofiles); *mfile; mfile = me) {
FILE *fp;
FD_t fd;
char buf[BUFSIZ];
if ((me = strchr(mfile, ':')) != NULL)
for (me = mfile; (me = strchr(me, ':')) != NULL; me++) {
if (!(me[1] == '/' && me[2] == '/'))
break;
}
if (me && *me == ':')
*me++ = '\0';
else
me = mfile + strlen(mfile);
@ -1287,13 +1300,14 @@ initMacros(MacroContext *mc, const char *macrofiles)
strncat(buf, mfile, sizeof(buf) - strlen(buf));
buf[sizeof(buf)-1] = '\0';
if ((fp=fopen(buf, "r")) == NULL)
fd = Fopen(buf, "r.ufdio");
if (fd == NULL || Ferror(fd))
continue;
/* XXX Assume new fangled macro expansion */
max_macro_depth = 16;
while(rdcl(buf, sizeof(buf), fp, 1) != NULL) {
while(rdcl(buf, sizeof(buf), fd, 1) != NULL) {
char c, *n;
n = buf;
@ -1304,7 +1318,7 @@ initMacros(MacroContext *mc, const char *macrofiles)
n++; /* skip % */
(void)rpmDefineMacro(NULL, n, RMIL_MACROFILES);
}
fclose(fp);
Fclose(fd);
}
if (m)
free(m);
@ -1338,29 +1352,35 @@ int isCompressed(const char *file, int *compressed)
{
FD_t fd;
ssize_t nb;
int rderrno;
int rc = -1;
unsigned char magic[4];
*compressed = COMPRESSED_NOT;
#ifdef DYING
fd = fdOpen(file, O_RDONLY, 0);
if (Ferror(fd)) {
#else
fd = Fopen(file, "r.ufdio");
#endif
if (fd == NULL || Ferror(fd)) {
/* XXX Fstrerror */
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(errno));
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, Fstrerror(fd));
return 1;
}
nb = Fread(magic, sizeof(char), sizeof(magic), fd);
rderrno = errno;
Fclose(fd);
if (nb < 0) {
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(rderrno));
return 1;
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, Fstrerror(fd));
rc = 1;
} else if (nb < sizeof(magic)) {
rpmError(RPMERR_BADSPEC, _("File %s is smaller than %d bytes"),
file, sizeof(magic));
return 0;
rc = 0;
}
Fclose(fd);
if (rc >= 0)
return rc;
rc = 0;
if (((magic[0] == 0037) && (magic[1] == 0213)) || /* gzip */
((magic[0] == 0037) && (magic[1] == 0236)) || /* old gzip */
@ -1375,7 +1395,7 @@ int isCompressed(const char *file, int *compressed)
*compressed = COMPRESSED_BZIP2;
}
return 0;
return rc;
}
/* =============================================================== */
@ -1473,6 +1493,50 @@ rpmGetPath(const char *path, ...)
return xstrdup(buf);
}
/* Merge 3 args into path, any or all of which may be a url. */
const char * rpmGenPath(const char * urlroot, const char * urlmdir,
const char *urlfile)
{
const char * xroot = rpmGetPath(urlroot, NULL), * root = xroot;
const char * xmdir = rpmGetPath(urlmdir, NULL), * mdir = xmdir;
const char * xfile = rpmGetPath(urlfile, NULL), * file = xfile;
const char * result;
const char * url = NULL;
int nurl = 0;
(void) urlPath(xroot, &root);
if (url == NULL && *root != '\0') {
url = xroot;
nurl = root - xroot;
}
(void) urlPath(xmdir, &mdir);
if (url == NULL && *mdir != '\0') {
url = xmdir;
nurl = mdir - xmdir;
}
(void) urlPath(xfile, &file);
if (url == NULL && *file != '\0') {
url = xfile;
nurl = file - xfile;
}
if (url && nurl > 0) {
char *t = strncpy(alloca(nurl+1), url, nurl);
t[nurl] = '\0';
url = t;
} else
url = "";
result = rpmGetPath(url, root, mdir, file, NULL);
xfree(xroot);
xfree(xmdir);
xfree(xfile);
return result;
}
/* =============================================================== */
#if defined(DEBUG_MACROS)

View File

@ -48,16 +48,17 @@ void freeSplitString(char ** list) {
free(list);
}
int rpmfileexists(const char * filespec) {
int rpmfileexists(const char * urlfn) {
const char *fn;
int urltype = urlPath(urlfn, &fn);
struct stat buf;
switch (urlIsURL(filespec)) {
switch (urltype) {
case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
case URL_IS_PATH:
filespec += sizeof("file://") - 1;
filespec = strchr(filespec, '/');
/*@fallthrough@*/
case URL_IS_UNKNOWN:
if (Stat(filespec, &buf)) {
if (Stat(fn, &buf)) {
switch(errno) {
case ENOENT:
case EINVAL:
@ -65,9 +66,7 @@ int rpmfileexists(const char * filespec) {
}
}
break;
case URL_IS_FTP:
case URL_IS_DASH:
case URL_IS_HTTP:
default:
return 0;
break;
@ -403,11 +402,12 @@ int makeTempFile(const char * prefix, const char ** fnptr, FD_t * fdptr) {
return 1;
/*@notreached@*/
}
#ifdef DYING
fd = fdio->open(tfn, O_CREAT | O_RDWR | O_EXCL, 0700);
/* XXX FIXME: build/build.c Fdopen assertion failure, makeTempFile uses fdio */
#ifndef NOTYET
fd = fdio->open(tfn, (O_CREAT|O_RDWR|O_EXCL), 0700);
#else
fd = Fopen(tfn, "w+x.ufdio");
fprintf(stderr, "*** mktemp %s fd %p: %s\n", tfnbuf, fd, strerror(errno));
#endif
} while ((fd == NULL || Ferror(fd)) && errno == EEXIST);

View File

@ -26,13 +26,8 @@ static int manageFile(FD_t *fdp, const char **fnp, int flags, int rc)
/* open a file and set *fdp */
if (*fdp == NULL && fnp && *fnp) {
#ifdef DYING
mode_t mode = (flags & O_CREAT) ? 0644 : 0;
fd = fdio->open(*fnp, flags, mode);
#else
fd = Fopen(*fnp, ((flags & O_RDONLY) ? "r.fdio" : "w.fdio"));
#endif
if (Ferror(fd)) {
fd = Fopen(*fnp, ((flags & O_RDONLY) ? "r.ufdio" : "w.ufdio"));
if (fd == NULL || Ferror(fd)) {
fprintf(stderr, _("%s: open failed: %s\n"), *fnp,
Fstrerror(fd));
return 1;

View File

@ -164,6 +164,8 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
}
}
/* XXX undefined %{name}/%{version}/%{release} here */
/* XXX %{_tmpdir} does not exist */
rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
myrc = urlGetFile(*filename, tfn);
if (myrc < 0) {

View File

@ -13,23 +13,30 @@ typedef /*@observer@*/ struct FDIO_s * FDIO_t;
extern "C" {
#endif
typedef /*@null@*/ FD_t fdio_ref_function_t ( /*@only@*/ void * cookie, const char *msg, const char *file, unsigned line);
typedef /*@null@*/ FD_t fdio_deref_function_t ( /*@only@*/ FD_t fd, const char *msg, const char *file, unsigned line);
typedef /*@null@*/ FD_t fdio_ref_function_t ( /*@only@*/ void * cookie,
const char * msg, const char * file, unsigned line);
typedef /*@null@*/ FD_t fdio_deref_function_t ( /*@only@*/ FD_t fd,
const char * msg, const char * file, unsigned line);
typedef /*@null@*/ FD_t fdio_new_function_t (FDIO_t iop, const char *msg, const char *file, unsigned line);
typedef /*@null@*/ FD_t fdio_new_function_t (FDIO_t iop, const char * msg,
const char * file, unsigned line);
typedef int fdio_fileno_function_t (void * cookie);
typedef FD_t fdio_open_function_t (const char *path, int flags, mode_t mode);
typedef FD_t fdio_fopen_function_t (const char *path, const char *fmode);
typedef FD_t fdio_open_function_t (const char * path, int flags, mode_t mode);
typedef FD_t fdio_fopen_function_t (const char * path, const char * fmode);
typedef void * fdio_ffileno_function_t (FD_t fd);
typedef int fdio_fflush_function_t (FD_t fd);
typedef int fdio_mkdir_function_t (const char *path, mode_t mode);
typedef int fdio_chdir_function_t (const char *path);
typedef int fdio_rmdir_function_t (const char *path);
typedef int fdio_rename_function_t (const char *oldpath, const char *newpath);
typedef int fdio_unlink_function_t (const char *path);
typedef int fdio_mkdir_function_t (const char * path, mode_t mode);
typedef int fdio_chdir_function_t (const char * path);
typedef int fdio_rmdir_function_t (const char * path);
typedef int fdio_rename_function_t (const char * oldpath, const char * newpath);
typedef int fdio_unlink_function_t (const char * path);
typedef int fdio_stat_function_t (const char * path, struct stat * st);
typedef int fdio_lstat_function_t (const char * path, struct stat * st);
typedef int fdio_access_function_t (const char * path, int amode);
struct FDIO_s {
cookie_read_function_t *read;
@ -76,6 +83,10 @@ int Rename (const char * oldpath, const char * newpath);
int Chroot (const char * path);
int Unlink (const char * path);
int Stat (const char * path, struct stat * st);
int Lstat (const char * path, struct stat * st);
int Access (const char * path, int amode);
/*@observer@*/ extern FDIO_t gzdio;
void fdSetFdno(FD_t fd, int fdno);
@ -120,8 +131,7 @@ extern /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode);
/*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd);
/*@observer@*/ const char * urlStrerror(const char * url);
int httpGetFile( /*@killref@*/ FD_t sfd, FD_t tfd);
int ftpGetFile( /*@killref@*/ FD_t sfd, FD_t tfd, const char * ftpcmd);
int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd);
const char *const ftpStrerror(int errorNumber);
#if 0

View File

@ -53,6 +53,7 @@ int isCompressed (const char *file, int *compressed);
char * rpmExpand (const char *arg, ...);
const char *rpmGetPath (const char *path, ...);
const char *rpmGenPath (const char *root, const char *mdir, const char *file);
int rpmExpandNumeric (const char *arg);
#ifdef __cplusplus

View File

@ -592,7 +592,7 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * filename)
int fdno = Fileno(fd);
size_t nb;
fstat(fdno, &sb);
nb = (sb.st_size > 0 ? sb.st_size : 8*BUFSIZ);
nb = (sb.st_size > 0 ? sb.st_size : (8*BUFSIZ - 2));
next = alloca(nb + 2);
next[0] = '\0';
rc = Fread(next, sizeof(*next), nb, fd);
@ -612,15 +612,19 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * filename)
linenum++;
s = se = next;
/* Find end-of-line. */
while (*se && *se != '\n') se++;
if (*se) *se++ = '\0';
next = se;
/* Trim leading spaces */
while (*s && isspace(*s)) s++;
/* we used to allow comments to begin anywhere, but not anymore */
/* We used to allow comments to begin anywhere, but not anymore. */
if (*s == '#' || *s == '\0') continue;
/* Find end-of-keyword. */
se = (char *)s;
while (*se && !isspace(*se) && *se != ':') se++;
@ -630,11 +634,11 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * filename)
}
if (*se != ':') {
rpmError(RPMERR_RPMRC, _("missing ':' at %s:%d"),
filename, linenum);
rpmError(RPMERR_RPMRC, _("missing ':' (found 0x%02x) at %s:%d"),
(0xff & *se), filename, linenum);
return 1;
}
*se++ = '\0';
*se++ = '\0'; /* terminate keyword or option, point to value */
while (*se && isspace(*se)) se++;
/* Find keyword in table */

View File

@ -66,10 +66,10 @@ extern "C" {
int ftpCheckResponse(urlinfo u, /*@out@*/ char ** str);
int ftpCommand(urlinfo u, ...);
int httpOpen(urlinfo u, const char * httpcmd);
int httpOpen(urlinfo u, FD_t ctrl, const char * httpcmd);
int ftpOpen(urlinfo u);
int ftpFileDone(urlinfo u, FD_t fd);
int ftpFileDesc(urlinfo u, const char * cmd, FD_t fd);
int ftpFileDone(urlinfo u, FD_t data);
int ftpFileDesc(urlinfo u, const char * cmd, FD_t data);
urlinfo urlLink(urlinfo u, const char * msg);
urlinfo XurlLink(urlinfo u, const char * msg, const char * file, unsigned line);
@ -86,6 +86,7 @@ urlinfo XurlFree( /*@killref@*/ urlinfo u, const char * msg, const char * file,
void urlFreeCache(void);
urltype urlIsURL(const char * url);
int urlPath(const char * url, /*@out@*/ const char ** pathp);
int urlSplit(const char * url, /*@out@*/ urlinfo * u);
int urlGetFile(const char * url, const char * dest);

View File

@ -172,7 +172,6 @@ static void urlFind(urlinfo *uret, int mustAsk)
uCache = xmalloc(sizeof(*uCache));
}
uCache[i] = urlLink(u, "uCache (miss)");
u->ctrl = fdNew(fdio, "persist ctrl");
u->bufAlloced = URL_IOBUF_SIZE;
u->buf = xcalloc(u->bufAlloced, sizeof(char));
u = urlFree(u, "urlSplit (urlFind miss)");
@ -280,19 +279,48 @@ static struct urlstring {
{ NULL, URL_IS_UNKNOWN }
};
urltype urlIsURL(const char * url)
{
urltype urlIsURL(const char * url) {
struct urlstring *us;
for (us = urlstrings; us->leadin != NULL; us++) {
if (strncmp(url, us->leadin, strlen(us->leadin)))
continue;
return us->ret;
if (url && *url) {
for (us = urlstrings; us->leadin != NULL; us++) {
if (strncmp(url, us->leadin, strlen(us->leadin)))
continue;
return us->ret;
}
}
return URL_IS_UNKNOWN;
}
int urlPath(const char * url, const char ** pathp)
{
const char *path = url;
int urltype = urlIsURL(url);
switch (urltype) {
case URL_IS_FTP:
path += sizeof("ftp://") - 1;
path = strchr(path, '/');
break;
case URL_IS_HTTP:
case URL_IS_PATH:
path += sizeof("file://") - 1;
path = strchr(path, '/');
break;
case URL_IS_UNKNOWN:
break;
case URL_IS_DASH:
path = "";
break;
}
if (path == NULL)
path = "/";
if (pathp)
*pathp = path;
return urltype;
}
/*
* Split URL into components. The URL can look like
* service://user:password@host:port/path
@ -433,25 +461,16 @@ fprintf(stderr, "*** urlGetFile sfd %p %s tfd %p %s\n", sfd, url, tfd, dest);
switch (urlIsURL(url)) {
case URL_IS_FTP:
#ifdef DYING
if ((rc = ftpGetFile(sfd, tfd, "RETR"))) {
unlink(dest);
/* XXX FIXME: sfd possibly closed by copyData */
/*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ;
}
/* XXX Fclose(sfd) done by copyData */
break;
#endif
case URL_IS_HTTP:
case URL_IS_PATH:
case URL_IS_DASH:
case URL_IS_UNKNOWN:
if ((rc = httpGetFile(sfd, tfd))) {
unlink(dest);
if ((rc = ufdGetFile(sfd, tfd))) {
Unlink(dest);
/* XXX FIXME: sfd possibly closed by copyData */
/*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ;
}
/* XXX Fclose(sfd) done by copyData */
/* XXX Fclose(sfd) done by ufdCopy */
break;
default:
rc = FTPERR_UNKNOWN;

File diff suppressed because it is too large Load Diff

2
rpm.c
View File

@ -247,7 +247,7 @@ static void printUsage(void) {
puts(_(" rpm {-b|t}[plciba] [-v] [--short-circuit] [--clean] [--rcfile <file>]"));
puts(_(" [--sign] [--nobuild] [--timecheck <s>] ]"));
puts(_(" [--target=platform1[,platform2...]]"));
puts(_(" [--rmsource] specfile"));
puts(_(" [--rmsource] [--rmspec] specfile"));
puts(_(" rpm {--rmsource} [--rcfile <file>] [-v] specfile"));
puts(_(" rpm {--rebuild} [--rcfile <file>] [-v] source1.rpm ... sourceN.rpm"));
puts(_(" rpm {--recompile} [--rcfile <file>] [-v] source1.rpm ... sourceN.rpm"));

View File

@ -23,16 +23,24 @@
#define RPMERR_BADSPEC stderr
#undef _
#define _(x) x
#define vmefail() (exit(1), NULL)
#define xfree(_p) free((void *)_p)
typedef int FD_t;
#define Ferror(_x) (_x)
#define fdOpen open
#define Fread(_b, _s, _n, _fd) read(_fd, _b, _s)
#define Fclose(_fd) close(_fd)
#define urlPath(_xr, _r) *(_r) = (_xr)
typedef FILE * FD_t;
#define Fopen(_path, _fmode) fopen(_path, "_r");
#define Ferror ferror
#define Fstrerror(_fd) strerror(errno)
#define Fread fread
#define Fclose fclose
#else
#include <rpmlib.h>
#include <rpmio.h>
#define fdOpen fdio->open
#include <rpmurl.h>
#endif
#include <rpmmacro.h>
@ -185,7 +193,7 @@ findEntry(MacroContext *mc, const char *name, size_t namelen)
/* fgets analogue that reads \ continuations. Last newline always trimmed. */
static char *
rdcl(char *buf, size_t size, FILE *fp, int escapes)
rdcl(char *buf, size_t size, FD_t fd, int escapes)
{
char *q = buf;
size_t nb = 0;
@ -193,7 +201,7 @@ rdcl(char *buf, size_t size, FILE *fp, int escapes)
*q = '\0';
do {
if (fgets(q, size, fp) == NULL) /* read next line */
if (fgets(q, size, fpio->ffileno(fd)) == NULL) /* read next line */
break;
nb = strlen(q);
nread += nb;
@ -1266,10 +1274,15 @@ initMacros(MacroContext *mc, const char *macrofiles)
mc = &globalMacroContext;
for (mfile = m = xstrdup(macrofiles); *mfile; mfile = me) {
FILE *fp;
FD_t fd;
char buf[BUFSIZ];
if ((me = strchr(mfile, ':')) != NULL)
for (me = mfile; (me = strchr(me, ':')) != NULL; me++) {
if (!(me[1] == '/' && me[2] == '/'))
break;
}
if (me && *me == ':')
*me++ = '\0';
else
me = mfile + strlen(mfile);
@ -1287,13 +1300,14 @@ initMacros(MacroContext *mc, const char *macrofiles)
strncat(buf, mfile, sizeof(buf) - strlen(buf));
buf[sizeof(buf)-1] = '\0';
if ((fp=fopen(buf, "r")) == NULL)
fd = Fopen(buf, "r.ufdio");
if (fd == NULL || Ferror(fd))
continue;
/* XXX Assume new fangled macro expansion */
max_macro_depth = 16;
while(rdcl(buf, sizeof(buf), fp, 1) != NULL) {
while(rdcl(buf, sizeof(buf), fd, 1) != NULL) {
char c, *n;
n = buf;
@ -1304,7 +1318,7 @@ initMacros(MacroContext *mc, const char *macrofiles)
n++; /* skip % */
(void)rpmDefineMacro(NULL, n, RMIL_MACROFILES);
}
fclose(fp);
Fclose(fd);
}
if (m)
free(m);
@ -1338,29 +1352,35 @@ int isCompressed(const char *file, int *compressed)
{
FD_t fd;
ssize_t nb;
int rderrno;
int rc = -1;
unsigned char magic[4];
*compressed = COMPRESSED_NOT;
#ifdef DYING
fd = fdOpen(file, O_RDONLY, 0);
if (Ferror(fd)) {
#else
fd = Fopen(file, "r.ufdio");
#endif
if (fd == NULL || Ferror(fd)) {
/* XXX Fstrerror */
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(errno));
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, Fstrerror(fd));
return 1;
}
nb = Fread(magic, sizeof(char), sizeof(magic), fd);
rderrno = errno;
Fclose(fd);
if (nb < 0) {
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(rderrno));
return 1;
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, Fstrerror(fd));
rc = 1;
} else if (nb < sizeof(magic)) {
rpmError(RPMERR_BADSPEC, _("File %s is smaller than %d bytes"),
file, sizeof(magic));
return 0;
rc = 0;
}
Fclose(fd);
if (rc >= 0)
return rc;
rc = 0;
if (((magic[0] == 0037) && (magic[1] == 0213)) || /* gzip */
((magic[0] == 0037) && (magic[1] == 0236)) || /* old gzip */
@ -1375,7 +1395,7 @@ int isCompressed(const char *file, int *compressed)
*compressed = COMPRESSED_BZIP2;
}
return 0;
return rc;
}
/* =============================================================== */
@ -1473,6 +1493,50 @@ rpmGetPath(const char *path, ...)
return xstrdup(buf);
}
/* Merge 3 args into path, any or all of which may be a url. */
const char * rpmGenPath(const char * urlroot, const char * urlmdir,
const char *urlfile)
{
const char * xroot = rpmGetPath(urlroot, NULL), * root = xroot;
const char * xmdir = rpmGetPath(urlmdir, NULL), * mdir = xmdir;
const char * xfile = rpmGetPath(urlfile, NULL), * file = xfile;
const char * result;
const char * url = NULL;
int nurl = 0;
(void) urlPath(xroot, &root);
if (url == NULL && *root != '\0') {
url = xroot;
nurl = root - xroot;
}
(void) urlPath(xmdir, &mdir);
if (url == NULL && *mdir != '\0') {
url = xmdir;
nurl = mdir - xmdir;
}
(void) urlPath(xfile, &file);
if (url == NULL && *file != '\0') {
url = xfile;
nurl = file - xfile;
}
if (url && nurl > 0) {
char *t = strncpy(alloca(nurl+1), url, nurl);
t[nurl] = '\0';
url = t;
} else
url = "";
result = rpmGetPath(url, root, mdir, file, NULL);
xfree(xroot);
xfree(xmdir);
xfree(xfile);
return result;
}
/* =============================================================== */
#if defined(DEBUG_MACROS)

View File

@ -53,6 +53,7 @@ int isCompressed (const char *file, int *compressed);
char * rpmExpand (const char *arg, ...);
const char *rpmGetPath (const char *path, ...);
const char *rpmGenPath (const char *root, const char *mdir, const char *file);
int rpmExpandNumeric (const char *arg);
#ifdef __cplusplus