Skip to content

Commit

Permalink
expand ~/, +b/ and +c/ in config filenames, allow absolute filenames …
Browse files Browse the repository at this point in the history
…in include files
  • Loading branch information
Bernhard R. Link committed Mar 26, 2012
1 parent bf43c8c commit f8ea846
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 50 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2012-03-26
* allow absolute filenames in !include directives, and
expand filenames starting with "~/" "+b/" "+c/" in those
and export hooks, filter lists, log scripts, override filenames,
and uploaders filenames.

2012-03-25
* changelogs.example can now also place changelogs in places
where apt-get changelog looks for "third party site" changelogs.
Expand Down
42 changes: 38 additions & 4 deletions configparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,41 @@ static inline retvalue finishchunk(configfinishfunction finishfunc, void *privda
return r;
}

static retvalue configfile_parse_single(const char *filename, bool ignoreunknown, configinitfunction initfunc, configfinishfunction finishfunc, const char *chunkname, const struct configfield *fields, size_t fieldcount, void *privdata, int depth, void **last_p, struct strlist *filenames) {
char *configfile_expandname(const char *filename, char *fndup) {
const char *fromdir;
char *n;

assert (fndup == NULL || fndup == filename);

if (filename[0] == '/' || (filename[0] == '.' && filename[1] == '/'))
return fndup?fndup:strdup(filename);
if (filename[0] == '~' && filename[1] == '/') {
n = calc_dirconcat(getenv("HOME"), filename + 2);
free(fndup);
return n;
}
if (filename[0] != '+' || filename[1] == '\0' || filename[2] != '/') {
n = calc_dirconcat(global.confdir, filename);
free(fndup);
return n;
}
if (filename[1] == 'b') {
fromdir = global.basedir;
} else if (filename[1] == 'o') {
fromdir = global.outdir;
} else if (filename[1] == 'c') {
fromdir = global.confdir;
} else {
fprintf(stderr, "Warning: strange filename '%s'!\n",
filename);
return fndup?fndup:strdup(filename);
}
n = calc_dirconcat(fromdir, filename + 3);
free(fndup);
return n;
}

static retvalue configfile_parse_single(const char *filename, /*@only@*//*@null@*/char *fndup, bool ignoreunknown, configinitfunction initfunc, configfinishfunction finishfunc, const char *chunkname, const struct configfield *fields, size_t fieldcount, void *privdata, int depth, void **last_p, struct strlist *filenames) {
bool found[fieldcount];
void *this = NULL;
char key[100];
Expand All @@ -144,7 +178,7 @@ static retvalue configfile_parse_single(const char *filename, bool ignoreunknown
retvalue result, r;
bool afterinclude = false;

iter.filename = calc_conffile(filename);
iter.filename = configfile_expandname(filename, fndup);
if (FAILEDTOALLOC(iter.filename))
return RET_ERROR_OOM;
if (strlist_in(filenames, iter.filename)) {
Expand Down Expand Up @@ -259,13 +293,13 @@ static retvalue configfile_parse_single(const char *filename, bool ignoreunknown
break;
}
r = configfile_parse_single(filetoinclude,
filetoinclude,
ignoreunknown,
initfunc, finishfunc,
chunkname,
fields, fieldcount,
privdata, depth + 1,
last_p, filenames);
free(filetoinclude);
if (RET_WAS_ERROR(r)) {
result = r;
break;
Expand Down Expand Up @@ -422,7 +456,7 @@ retvalue configfile_parse(const char *filename, bool ignoreunknown, configinitfu

strlist_init(&filenames);

r = configfile_parse_single(filename, ignoreunknown,
r = configfile_parse_single(filename, NULL, ignoreunknown,
initfunc, finishfunc,
chunkname, fields, fieldcount, privdata,
0, &last, &filenames);
Expand Down
1 change: 1 addition & 0 deletions configparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,5 @@ static retvalue configparser_ ## sname ## _set_ ## field(UNUSED(void *dummy), UN
#define CFfileSETPROC CFvalueSETPROC
#define config_getfileinline config_getwordinline

char *configfile_expandname(const char *, /*@only@*//*@null@*/char *);
#endif /* REPREPRO_CONFIGPARSER_H */
7 changes: 1 addition & 6 deletions exports.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,8 @@ retvalue exportmode_set(struct exportmode *mode, struct configiterator *iter) {
word);
free(word);
return RET_ERROR;
} else if (word[0] == '/') {
r = strlist_add(&mode->hooks, word);
if (RET_WAS_ERROR(r))
return r;
} else {
char *fullfilename = calc_conffile(word);
free(word);
char *fullfilename = configfile_expandname(word, word);
if (FAILEDTOALLOC(fullfilename))
return RET_ERROR_OOM;
r = strlist_add(&mode->hooks, fullfilename);
Expand Down
34 changes: 14 additions & 20 deletions filterlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,13 @@ static inline retvalue filterlistfile_getl(const char *filename, size_t len, str
free(p);
return RET_ERROR_OOM;
}
if (p->filename[0] != '/') {
char *fullfilename = calc_conffile(p->filename);
if (FAILEDTOALLOC(fullfilename))
r = RET_ERROR_OOM;
else {
r = filterlistfile_read(p, fullfilename);
free(fullfilename);
}
} else
r = filterlistfile_read(p, p->filename);
char *fullfilename = configfile_expandname(p->filename, NULL);
if (FAILEDTOALLOC(fullfilename))
r = RET_ERROR_OOM;
else {
r = filterlistfile_read(p, fullfilename);
free(fullfilename);
}

if (RET_IS_OK(r)) {
p->next = listfiles;
Expand Down Expand Up @@ -288,16 +285,13 @@ static inline retvalue filterlistfile_get(/*@only@*/char *filename, /*@out@*/str
free(p);
return RET_ERROR_OOM;
}
if (p->filename[0] != '/') {
char *fullfilename = calc_conffile(p->filename);
if (FAILEDTOALLOC(fullfilename))
r = RET_ERROR_OOM;
else {
r = filterlistfile_read(p, fullfilename);
free(fullfilename);
}
} else
r = filterlistfile_read(p, p->filename);
char *fullfilename = configfile_expandname(p->filename, NULL);
if (FAILEDTOALLOC(fullfilename))
r = RET_ERROR_OOM;
else {
r = filterlistfile_read(p, fullfilename);
free(fullfilename);
}

if (RET_IS_OK(r)) {
p->next = listfiles;
Expand Down
7 changes: 1 addition & 6 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,7 @@ static retvalue notificator_parse(struct notificator *n, struct configiterator *
free(script);
return RET_ERROR;
}
if (script[0] == '/')
n->scriptname = script;
else {
n->scriptname = calc_conffile(script);
free(script);
}
n->scriptname = configfile_expandname(script, script);
if (FAILEDTOALLOC(n->scriptname))
return RET_ERROR_OOM;
return RET_OK;
Expand Down
1 change: 0 additions & 1 deletion names.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ char *calc_addsuffix(const char *, const char *);
char *calc_dirconcat(const char *, const char *);
char *calc_dirconcat3(const char *, const char *, const char *);

#define calc_conffile(name) calc_dirconcat(global.confdir, name)
char *calc_changes_basename(const char *, const char *, const struct strlist *);
char *calc_trackreferee(const char *, const char *, const char *);
#define calc_snapshotbasedir(codename, name) mprintf("%s/%s/snapshots/%s", global.distdir, codename, name)
Expand Down
14 changes: 6 additions & 8 deletions override.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "names.h"
#include "globmatch.h"
#include "override.h"
#include "configparser.h"

struct overridedata {
struct strlist fields;
Expand Down Expand Up @@ -235,14 +236,11 @@ retvalue override_read(const char *filename, struct overridefile **info, bool so
*info = NULL;
return RET_OK;
}
if (filename[0] != '/') {
char *fn = calc_conffile(filename);
if (FAILEDTOALLOC(fn))
return RET_ERROR_OOM;
file = fopen(fn, "r");
free(fn);
} else
file = fopen(filename, "r");
char *fn = configfile_expandname(filename, NULL);
if (FAILEDTOALLOC(fn))
return RET_ERROR_OOM;
file = fopen(fn, "r");
free(fn);

if (file == NULL) {
int e = errno;
Expand Down
7 changes: 2 additions & 5 deletions uploaderslist.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "signature.h"
#include "globmatch.h"
#include "uploaderslist.h"
#include "configparser.h"
#include "ignore.h"

struct upload_condition {
Expand Down Expand Up @@ -1355,11 +1356,7 @@ static retvalue openfiletobeparsed(struct filebeingparsed *includedby, const cha
if (FAILEDTOALLOC(fbp))
return RET_ERROR_OOM;

if (filename[0] != '/') {
fbp->filename = calc_conffile(filename);
} else {
fbp->filename = strdup(filename);
}
fbp->filename = configfile_expandname(filename, NULL);
if (FAILEDTOALLOC(fbp->filename)) {
free(fbp);
return RET_ERROR_OOM;
Expand Down

0 comments on commit f8ea846

Please sign in to comment.