Browse Source

cherrypick from my apt/experimental branch

* apt-pkg/deb/debmetaindex.cc:
  - none is a separator, not a language: no need for Index (Closes: #624218)
* apt-pkg/aptconfiguration.cc:
  - do not builtin languages only if none is forced (Closes: #643787)
David Kalnischkies 14 years ago
parent
commit
d073d7db69

+ 4 - 2
apt-pkg/aptconfiguration.cc

@@ -140,7 +140,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 		for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) {
 		for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) {
 			string const name = Ent->d_name;
 			string const name = Ent->d_name;
 			size_t const foundDash = name.rfind("-");
 			size_t const foundDash = name.rfind("-");
-			size_t const foundUnderscore = name.rfind("_");
+			size_t const foundUnderscore = name.rfind("_", foundDash);
 			if (foundDash == string::npos || foundUnderscore == string::npos ||
 			if (foundDash == string::npos || foundUnderscore == string::npos ||
 			    foundDash <= foundUnderscore ||
 			    foundDash <= foundUnderscore ||
 			    name.substr(foundUnderscore+1, foundDash-(foundUnderscore+1)) != "Translation")
 			    name.substr(foundUnderscore+1, foundDash-(foundUnderscore+1)) != "Translation")
@@ -151,7 +151,7 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 			// Skip unusual files, like backups or that alike
 			// Skip unusual files, like backups or that alike
 			string::const_iterator s = c.begin();
 			string::const_iterator s = c.begin();
 			for (;s != c.end(); ++s) {
 			for (;s != c.end(); ++s) {
-				if (isalpha(*s) == 0)
+				if (isalpha(*s) == 0 && *s != '_')
 					break;
 					break;
 			}
 			}
 			if (s != c.end())
 			if (s != c.end())
@@ -232,6 +232,8 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
 			codes = environment;
 			codes = environment;
 		} else if (forceLang != "none")
 		} else if (forceLang != "none")
 			codes.push_back(forceLang);
 			codes.push_back(forceLang);
+		else //if (forceLang == "none")
+			builtin.clear();
 		allCodes = codes;
 		allCodes = codes;
 		for (std::vector<string>::const_iterator b = builtin.begin();
 		for (std::vector<string>::const_iterator b = builtin.begin();
 		     b != builtin.end(); ++b)
 		     b != builtin.end(); ++b)

+ 6 - 2
apt-pkg/deb/debmetaindex.cc

@@ -9,6 +9,7 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/error.h>
 
 
 #include <set>
 #include <set>
+#include <algorithm>
 
 
 using namespace std;
 using namespace std;
 
 
@@ -195,7 +196,11 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
 		}
 		}
 	}
 	}
 
 
-	std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
+	std::vector<std::string> lang = APT::Configuration::getLanguages(true);
+	std::vector<std::string>::iterator lend = std::remove(lang.begin(), lang.end(), "none");
+	if (lend != lang.end())
+		lang.erase(lend);
+
 	if (lang.empty() == true)
 	if (lang.empty() == true)
 		return IndexTargets;
 		return IndexTargets;
 
 
@@ -207,7 +212,6 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
 		     s != sections.end(); ++s) {
 		     s != sections.end(); ++s) {
 			for (std::vector<std::string>::const_iterator l = lang.begin();
 			for (std::vector<std::string>::const_iterator l = lang.begin();
 			     l != lang.end(); ++l) {
 			     l != lang.end(); ++l) {
-				if (*l == "none") continue;
 				IndexTarget * Target = new OptionalIndexTarget();
 				IndexTarget * Target = new OptionalIndexTarget();
 				Target->ShortDesc = "Translation-" + *l;
 				Target->ShortDesc = "Translation-" + *l;
 				Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s);
 				Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s);

+ 4 - 0
debian/changelog

@@ -17,6 +17,10 @@ apt (0.8.15.9) UNRELEASED; urgency=low
     - silently ignore *.orig and *.save files by default
     - silently ignore *.orig and *.save files by default
   * apt-pkg/policy.cc:
   * apt-pkg/policy.cc:
     - accept generic release pin expressions again in -t (Closes: #644166)
     - accept generic release pin expressions again in -t (Closes: #644166)
+  * apt-pkg/deb/debmetaindex.cc:
+    - none is a separator, not a language: no need for Index (Closes: #624218)
+  * apt-pkg/aptconfiguration.cc:
+    - do not builtin languages only if none is forced (Closes: #643787)
 
 
  -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 03 Oct 2011 23:35:40 +0200
  -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 03 Oct 2011 23:35:40 +0200
 
 

+ 87 - 0
test/integration/test-bug-624218-Translation-file-handling

@@ -0,0 +1,87 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386'
+
+buildsimplenativepackage 'coolstuff' 'all' '1.0' 'unstable'
+
+setupaptarchive
+
+changetowebserver
+
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'No download of non-existent locals' 'with Index'
+LC_ALL="" aptget update -o Acquire::Languages=en | grep -q -e 'Translation-[^e][^n] ' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of existent locals' 'with Index'
+LC_ALL="" aptget update | grep -q -e 'Translation-en ' && msgpass || msgfail
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of en in LC_ALL=C' 'with Index'
+LC_ALL=C aptget update | grep -q -e 'Translation-en ' && msgpass || msgfail
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of en as forced language' 'with Index'
+aptget update -o Acquire::Languages=en | grep -q -e 'Translation-en ' && msgpass || msgfail
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of nothing else in forced language' 'with Index'
+aptget update -o Acquire::Languages=en | grep -q -e 'Translation-[^e][^n] ' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download no Translation- if forced language is non-existent' 'with Index'
+aptget update -o Acquire::Languages=ast_DE | grep -q -e 'Translation-' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of nothing if none is forced' 'with Index'
+aptget update -o Acquire::Languages=none | grep -q -e 'Translation' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists
+
+sed -i '/i18n\/Index$/ d' $(find aptarchive -name 'Release')
+signreleasefiles
+
+# we have to try as not every archive includes the i18n Index in the Release file - if it has one at all
+msgtest 'Download no Translation- if forced language is non-existent' 'with not-announced Index'
+aptget update -o Acquire::Languages=ast_DE | grep -q -e 'Translation-' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists
+
+find aptarchive -name 'Index' -delete
+
+msgtest 'Download of en as forced language' 'without Index'
+aptget update -o Acquire::Languages=en | grep -q -e 'Translation-en ' && msgpass || msgfail
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of nothing else in forced language' 'without Index'
+aptget update -o Acquire::Languages=en | grep -q -e 'Translation-[^e][^n] ' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of ast_DE as forced language' 'without Index'
+aptget update -o Acquire::Languages=ast_DE | grep -q -e 'Translation-ast_DE$' && msgpass || msgfail
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of nothing else in forced language' 'without Index'
+aptget update -o Acquire::Languages=ast_DE | grep -q -e 'Translation-[^a][^s]' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists
+
+msgtest 'Download of nothing if none is forced' 'without Index'
+aptget update -o Acquire::Languages=none | grep -q -e 'Translation' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists
+
+mkdir -p rootdir/var/lib/apt/lists
+touch rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_i18n_Translation-ast_DE
+
+msgtest 'Download of builtin files' 'without Index'
+aptget update | grep -q -e 'Translation-ast_DE' && msgpass || msgfail
+rm -rf rootdir/var/lib/apt/lists
+
+mkdir -p rootdir/var/lib/apt/lists
+touch rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_i18n_Translation-ast_DE
+
+msgtest 'Download of nothing (even builtin) if none is forced' 'without Index'
+aptget update -o Acquire::Languages=none | grep -q -e 'Translation' && msgfail || msgpass
+rm -rf rootdir/var/lib/apt/lists

+ 15 - 0
test/libapt/assert.h

@@ -54,6 +54,21 @@ void assertEqualsOr2(int const &expect1, int const &expect2, unsigned int const
 }
 }
 
 
 
 
+#define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
+
+template < typename X, typename Y >
+void OutputAssertEqualOr3(X expect1, X expect2, X expect3, char const* compare, Y get, unsigned long const &line) {
+	std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« or »" << expect3 << "« " << compare << " »" << get << "« at line " << line << std::endl;
+}
+
+template < typename X, typename Y >
+void assertEqualsOr3(X expect1, X expect2, X expect3, Y get, unsigned long const &line) {
+	if (expect1 == get || expect2 == get || expect3 == get)
+		return;
+	OutputAssertEqualOr3(expect1, expect2, expect3, "==", get, line);
+}
+
+
 // simple helper to quickly output a vectors
 // simple helper to quickly output a vectors
 template < typename X >
 template < typename X >
 void dumpVector(X vec) {
 void dumpVector(X vec) {

+ 9 - 3
test/libapt/getlanguages_test.cc

@@ -126,13 +126,19 @@ int main(int argc,char *argv[])
 
 
 	_config->Set("Dir::State::lists", argv[1]);
 	_config->Set("Dir::State::lists", argv[1]);
 	vec = APT::Configuration::getLanguages(true, false, env);
 	vec = APT::Configuration::getLanguages(true, false, env);
-	equals(vec.size(), 6);
+	equals(vec.size(), 7);
 	equals(vec[0], "de_DE");
 	equals(vec[0], "de_DE");
 	equals(vec[1], "de");
 	equals(vec[1], "de");
 	equals(vec[2], "en");
 	equals(vec[2], "en");
 	equals(vec[3], "none");
 	equals(vec[3], "none");
-	equalsOr2(vec[4], "pt", "tr");
-	equalsOr2(vec[5], "tr", "pt");
+	equalsOr3(vec[4], "pt", "tr", "ast_DE");
+	equalsOr3(vec[5], "tr", "pt", "ast_DE");
+	equalsOr3(vec[6], "tr", "pt", "ast_DE");
+
+	_config->Set("Acquire::Languages", "none");
+	vec = APT::Configuration::getLanguages(true, false, env);
+	equals(vec.size(), 0);
+	_config->Set("Acquire::Languages", "");
 
 
 	_config->Set("Dir::State::lists", "/non-existing-dir");
 	_config->Set("Dir::State::lists", "/non-existing-dir");
 	_config->Set("Acquire::Languages::1", "none");
 	_config->Set("Acquire::Languages::1", "none");

+ 2 - 1
test/libapt/run-tests

@@ -64,7 +64,8 @@ do
 		touch "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tr" \
 		touch "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tr" \
 			"${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-pt" \
 			"${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-pt" \
 			"${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-se~" \
 			"${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-se~" \
-			"${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-st.bak"
+			"${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-st.bak" \
+			"${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-ast_DE"
 	elif [ $name = "CompareVersion${EXT}" ]; then
 	elif [ $name = "CompareVersion${EXT}" ]; then
 		tmppath="${DIR}/versions.lst"
 		tmppath="${DIR}/versions.lst"
 	fi
 	fi