Drop case insensitive comparisons in the config parsing.

These case insensitive comparisons didn't work in some locales, like tr_TR
where upper(i) != I. So a second case sensitive comparison had to be made
for each directive.
Only keeping case sensitive comparisons make the code cleaner and treat all
locales equally.

Ref: http://www.archlinux.org/pipermail/pacman-dev/2008-March/011445.html

Also fix pactests to use the correct case.

Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Chantry Xavier 2008-03-13 16:36:44 +01:00 committed by Dan McGee
parent dae3f9deef
commit b3e6cf652c
11 changed files with 32 additions and 40 deletions

View file

@ -40,6 +40,8 @@ Include = /etc/pacman.d/core
Server = file:///home/pkgs
--------
*NOTE*: Each directive must be in CamelCase. If the case isn't respected, the directive
won't be recognized. For example. noupgrade or NOUPGRADE will not work.
Options
-------

View file

@ -3,7 +3,7 @@ self.description = "Remove a package in HoldPkg"
p1 = pmpkg("dummy")
self.addpkg2db("local", p1)
self.option["holdpkg"] = ["dummy"]
self.option["HoldPkg"] = ["dummy"]
self.args = "-R %s" % p1.name

View file

@ -12,7 +12,7 @@ sp3.groups = ["grp"]
for p in sp1, sp2, sp3:
self.addpkg2db("sync", p);
self.option["ignorepkg"] = ["pkg2"]
self.option["IgnorePkg"] = ["pkg2"]
self.args = "-S grp"

View file

@ -12,7 +12,7 @@ lp2 = pmpkg("pkg2")
for p in lp1, lp2:
self.addpkg2db("local", p)
self.option["ignorepkg"] = ["pkg2"]
self.option["IgnorePkg"] = ["pkg2"]
self.args = "-Su"

View file

@ -9,7 +9,7 @@ lp = pmpkg("pkg1")
self.addpkg2db("local", lp)
self.option["ignorepkg"] = ["pkg1"]
self.option["IgnorePkg"] = ["pkg1"]
self.args = "-Su"

View file

@ -13,7 +13,7 @@ lp2 = pmpkg("pkg2")
for p in lp1, lp2:
self.addpkg2db("local", p)
self.option["ignoregroup"] = ["grp"]
self.option["IgnoreGroup"] = ["grp"]
self.args = "-Su"

View file

@ -8,7 +8,7 @@ p = pmpkg("dummy", "1.0-2")
p.files = ["etc/dummy.conf"]
self.addpkg(p)
self.option["noupgrade"] = ["etc/dummy.conf"]
self.option["NoUpgrade"] = ["etc/dummy.conf"]
self.args = "-U %s" % p.filename()

View file

@ -5,7 +5,7 @@ p.files = ["bin/dummy",
"usr/man/man1/dummy.1"]
self.addpkg(p)
self.option["noextract"] = ["usr/man/man1/dummy.1"]
self.option["NoExtract"] = ["usr/man/man1/dummy.1"]
self.args = "-U %s" % p.filename()

View file

@ -3,7 +3,7 @@ self.description = "Quick check for using XferCommand"
# this setting forces us to download packages
self.cachepkgs = False
#wget doesn't support file:// urls. curl does
self.option['xfercommand'] = ['/usr/bin/curl %u > %o']
self.option['XferCommand'] = ['/usr/bin/curl %u > %o']
numpkgs = 10
pkgnames = []

View file

@ -181,7 +181,7 @@ def mkcfgfile(filename, root, option, db):
# Repositories
data.extend(["[%s]\n" \
"server = file://%s\n" \
"Server = file://%s\n" \
% (value.treename, \
os.path.join(root, SYNCREPO, value.treename)) \
for key, value in db.iteritems() if key != "local"])

View file

@ -604,7 +604,7 @@ static int _parseconfig(const char *file, const char *givensection,
}
} else {
/* directive */
char *key, *upperkey;
char *key;
/* strsep modifies the 'line' string: 'key \0 ptr' */
key = line;
ptr = line;
@ -617,11 +617,7 @@ static int _parseconfig(const char *file, const char *givensection,
file, linenum);
return(1);
}
/* For each directive, compare to the uppercase and camelcase string.
* This prevents issues with certain locales where characters don't
* follow the toupper() rules we may expect, e.g. tr_TR where i != I.
*/
upperkey = strtoupper(strdup(key));
/* For each directive, compare to the camelcase string. */
if(section == NULL) {
pm_printf(PM_LOG_ERROR, _("config file %s, line %d: All directives must belong to a section.\n"),
file, linenum);
@ -629,25 +625,25 @@ static int _parseconfig(const char *file, const char *givensection,
}
if(ptr == NULL && strcmp(section, "options") == 0) {
/* directives without settings, all in [options] */
if(strcmp(key, "NoPassiveFTP") == 0 || strcmp(upperkey, "NOPASSIVEFTP") == 0) {
if(strcmp(key, "NoPassiveFTP") == 0) {
alpm_option_set_nopassiveftp(1);
pm_printf(PM_LOG_DEBUG, "config: nopassiveftp\n");
} else if(strcmp(key, "UseSyslog") == 0 || strcmp(upperkey, "USESYSLOG") == 0) {
} else if(strcmp(key, "UseSyslog") == 0) {
alpm_option_set_usesyslog(1);
pm_printf(PM_LOG_DEBUG, "config: usesyslog\n");
} else if(strcmp(key, "ILoveCandy") == 0 || strcmp(upperkey, "ILOVECANDY") == 0) {
} else if(strcmp(key, "ILoveCandy") == 0) {
config->chomp = 1;
pm_printf(PM_LOG_DEBUG, "config: chomp\n");
} else if(strcmp(key, "UseColor") == 0 || strcmp(upperkey, "USECOLOR") == 0) {
} else if(strcmp(key, "UseColor") == 0) {
config->usecolor = 1;
pm_printf(PM_LOG_DEBUG, "config: usecolor\n");
} else if(strcmp(key, "ShowSize") == 0 || strcmp(upperkey, "SHOWSIZE") == 0) {
} else if(strcmp(key, "ShowSize") == 0) {
config->showsize = 1;
pm_printf(PM_LOG_DEBUG, "config: showsize\n");
} else if(strcmp(key, "UseDelta") == 0 || strcmp(upperkey, "USEDELTA") == 0) {
} else if(strcmp(key, "UseDelta") == 0) {
alpm_option_set_usedelta(1);
pm_printf(PM_LOG_DEBUG, "config: usedelta\n");
} else if(strcmp(key, "TotalDownload") == 0 || strcmp(upperkey, "TOTALDOWNLOAD") == 0) {
} else if(strcmp(key, "TotalDownload") == 0) {
config->totaldownload = 1;
pm_printf(PM_LOG_DEBUG, "config: totaldownload\n");
} else {
@ -657,51 +653,46 @@ static int _parseconfig(const char *file, const char *givensection,
}
} else {
/* directives with settings */
if(strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0) {
if(strcmp(key, "Include") == 0) {
pm_printf(PM_LOG_DEBUG, "config: including %s\n", ptr);
_parseconfig(ptr, section, db);
/* Ignore include failures... assume non-critical */
} else if(strcmp(section, "options") == 0) {
if(strcmp(key, "NoUpgrade") == 0
|| strcmp(upperkey, "NOUPGRADE") == 0) {
if(strcmp(key, "NoUpgrade") == 0) {
setrepeatingoption(ptr, "NoUpgrade", alpm_option_add_noupgrade);
} else if(strcmp(key, "NoExtract") == 0
|| strcmp(upperkey, "NOEXTRACT") == 0) {
} else if(strcmp(key, "NoExtract") == 0) {
setrepeatingoption(ptr, "NoExtract", alpm_option_add_noextract);
} else if(strcmp(key, "IgnorePkg") == 0
|| strcmp(upperkey, "IGNOREPKG") == 0) {
} else if(strcmp(key, "IgnorePkg") == 0) {
setrepeatingoption(ptr, "IgnorePkg", alpm_option_add_ignorepkg);
} else if(strcmp(key, "IgnoreGroup") == 0
|| strcmp(upperkey, "IGNOREGROUP") == 0) {
} else if(strcmp(key, "IgnoreGroup") == 0) {
setrepeatingoption(ptr, "IgnoreGroup", alpm_option_add_ignoregrp);
} else if(strcmp(key, "HoldPkg") == 0
|| strcmp(upperkey, "HOLDPKG") == 0) {
} else if(strcmp(key, "HoldPkg") == 0) {
setrepeatingoption(ptr, "HoldPkg", alpm_option_add_holdpkg);
} else if(strcmp(key, "DBPath") == 0 || strcmp(upperkey, "DBPATH") == 0) {
} else if(strcmp(key, "DBPath") == 0) {
/* don't overwrite a path specified on the command line */
if(!config->dbpath) {
config->dbpath = strdup(ptr);
pm_printf(PM_LOG_DEBUG, "config: dbpath: %s\n", ptr);
}
} else if(strcmp(key, "CacheDir") == 0 || strcmp(upperkey, "CACHEDIR") == 0) {
} else if(strcmp(key, "CacheDir") == 0) {
if(alpm_option_add_cachedir(ptr) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
ptr, alpm_strerrorlast());
return(1);
}
pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", ptr);
} else if(strcmp(key, "RootDir") == 0 || strcmp(upperkey, "ROOTDIR") == 0) {
} else if(strcmp(key, "RootDir") == 0) {
/* don't overwrite a path specified on the command line */
if(!config->rootdir) {
config->rootdir = strdup(ptr);
pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", ptr);
}
} else if (strcmp(key, "LogFile") == 0 || strcmp(upperkey, "LOGFILE") == 0) {
} else if (strcmp(key, "LogFile") == 0) {
if(!config->logfile) {
config->logfile = strdup(ptr);
pm_printf(PM_LOG_DEBUG, "config: logfile: %s\n", ptr);
}
} else if (strcmp(key, "XferCommand") == 0 || strcmp(upperkey, "XFERCOMMAND") == 0) {
} else if (strcmp(key, "XferCommand") == 0) {
alpm_option_set_xfercommand(ptr);
pm_printf(PM_LOG_DEBUG, "config: xfercommand: %s\n", ptr);
} else {
@ -709,7 +700,7 @@ static int _parseconfig(const char *file, const char *givensection,
file, linenum, key);
return(1);
}
} else if(strcmp(key, "Server") == 0 || strcmp(upperkey, "SERVER") == 0) {
} else if(strcmp(key, "Server") == 0) {
/* let's attempt a replacement for the current repo */
char *server = strreplace(ptr, "$repo", section);
@ -725,7 +716,6 @@ static int _parseconfig(const char *file, const char *givensection,
return(1);
}
}
free(upperkey);
}
}
fclose(fp);