Explorar el Código

* apt-pkg/cacheset.cc:
- add PackageContainerInterface::FromGroup to support
architecture specifications with wildcards on the commandline

David Kalnischkies hace 14 años
padre
commit
2f0d4029bf
Se han modificado 3 ficheros con 54 adiciones y 4 borrados
  1. 50 4
      apt-pkg/cacheset.cc
  2. 1 0
      apt-pkg/cacheset.h
  3. 3 0
      debian/changelog

+ 50 - 4
apt-pkg/cacheset.cc

@@ -182,15 +182,61 @@ pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache,
 	return Pkg;
 	return Pkg;
 }
 }
 									/*}}}*/
 									/*}}}*/
+// FromGroup - Returns the package defined  by this string		/*{{{*/
+bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache,
+			std::string pkg, CacheSetHelper &helper) {
+	if (unlikely(Cache.GetPkgCache() == 0))
+		return false;
+
+	size_t const archfound = pkg.find_last_of(':');
+	std::string arch;
+	if (archfound != std::string::npos) {
+		arch = pkg.substr(archfound+1);
+		pkg.erase(archfound);
+	}
+
+	pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg);
+	if (Grp.end() == false) {
+		if (arch.empty() == true) {
+			pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg();
+			if (Pkg.end() == false)
+			{
+			   pci->insert(Pkg);
+			   return true;
+			}
+		} else {
+			bool found = false;
+			// for 'linux-any' return the first package matching, for 'linux-*' return all matches
+			bool const isGlobal = arch.find('*') != std::string::npos;
+			APT::CacheFilter::PackageArchitectureMatchesSpecification pams(arch);
+			for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) {
+				if (pams(Pkg) == false)
+					continue;
+				pci->insert(Pkg);
+				found = true;
+				if (isGlobal == false)
+					break;
+			}
+			if (found == true)
+				return true;
+		}
+	}
+
+	pkgCache::PkgIterator Pkg = helper.canNotFindPkgName(Cache, pkg);
+	if (Pkg.end() == true)
+	   return false;
+
+	pci->insert(Pkg);
+	return true;
+}
+									/*}}}*/
 // FromString - Return all packages matching a specific string		/*{{{*/
 // FromString - Return all packages matching a specific string		/*{{{*/
 bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) {
 bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) {
 	bool found = true;
 	bool found = true;
 	_error->PushToStack();
 	_error->PushToStack();
 
 
-	pkgCache::PkgIterator Pkg = FromName(Cache, str, helper);
-	if (Pkg.end() == false)
-		pci->insert(Pkg);
-	else if (FromTask(pci, Cache, str, helper) == false &&
+	if (FromGroup(pci, Cache, str, helper) == false &&
+		 FromTask(pci, Cache, str, helper) == false &&
 		 FromRegEx(pci, Cache, str, helper) == false)
 		 FromRegEx(pci, Cache, str, helper) == false)
 	{
 	{
 		helper.canNotFindPackage(pci, Cache, str);
 		helper.canNotFindPackage(pci, Cache, str);

+ 1 - 0
apt-pkg/cacheset.h

@@ -139,6 +139,7 @@ public:
 	static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
 	static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
 	static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
 	static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
 	static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
 	static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
+	static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
 	static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
 	static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
 	static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper);
 	static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper);
 
 

+ 3 - 0
debian/changelog

@@ -7,6 +7,9 @@ apt (0.9.6.1) UNRELEASED; urgency=low
     - use PackageArchitectureMatchesSpecification filter
     - use PackageArchitectureMatchesSpecification filter
   * apt-pkg/cachefilter.cc:
   * apt-pkg/cachefilter.cc:
     - add PackageArchitectureMatchesSpecification (Closes: #672603)
     - add PackageArchitectureMatchesSpecification (Closes: #672603)
+  * apt-pkg/cacheset.cc:
+    - add PackageContainerInterface::FromGroup to support
+      architecture specifications with wildcards on the commandline
 
 
  -- David Kalnischkies <kalnischkies@gmail.com>  Thu, 14 Jun 2012 15:45:13 +0200
  -- David Kalnischkies <kalnischkies@gmail.com>  Thu, 14 Jun 2012 15:45:13 +0200