]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cacheset.cc
Allow passing a full path to apt-get install /foo/bar.deb
[apt.git] / apt-pkg / cacheset.cc
index 29281aab93569636a66cfb9d77f3e2058544cc1f..346bad3aaa3a587f0fc6b0202be534a4e8e76929 100644 (file)
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/cacheset.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/cacheset.h>
 #include <apt-pkg/error.h>
-#include <apt-pkg/strutl.h>
 #include <apt-pkg/versionmatch.h>
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/policy.h>
 #include <apt-pkg/versionmatch.h>
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/policy.h>
-
-#include <vector>
-
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/macros.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/fileutl.h>
+
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
 #include <regex.h>
 #include <regex.h>
+#include <list>
+#include <string>
+#include <vector>
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -204,12 +213,20 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci,
                }
 
                pci->insert(Pkg);
                }
 
                pci->insert(Pkg);
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+               helper.showFnmatchSelection(Pkg, pattern);
+#else
                helper.showRegExSelection(Pkg, pattern);
                helper.showRegExSelection(Pkg, pattern);
+#endif
                found = true;
        }
 
        if (found == false) {
                found = true;
        }
 
        if (found == false) {
-               helper.canNotFindRegEx(pci, Cache, pattern);
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+               helper.canNotFindFnmatch(pci, Cache, pattern);
+#else
+                helper.canNotFindRegEx(pci, Cache, pattern);
+#endif
                pci->setConstructor(UNKNOWN);
                return false;
        }
                pci->setConstructor(UNKNOWN);
                return false;
        }
@@ -304,7 +321,10 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci
 
        if (FromGroup(pci, Cache, str, helper) == false &&
                 FromTask(pci, Cache, str, helper) == false &&
 
        if (FromGroup(pci, Cache, str, helper) == false &&
                 FromTask(pci, Cache, str, helper) == false &&
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+                 // FIXME: hm, hm, regexp/fnmatch incompatible?
                 FromFnmatch(pci, Cache, str, helper) == false &&
                 FromFnmatch(pci, Cache, str, helper) == false &&
+#endif
                 FromRegEx(pci, Cache, str, helper) == false)
        {
                helper.canNotFindPackage(pci, Cache, str);
                 FromRegEx(pci, Cache, str, helper) == false)
        {
                helper.canNotFindPackage(pci, Cache, str);
@@ -373,6 +393,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
                                                        CacheSetHelper &helper) {
        Version select = NEWEST;
        std::string str = cmdline;
                                                        CacheSetHelper &helper) {
        Version select = NEWEST;
        std::string str = cmdline;
+       if (unlikely(str.empty() == true))
+               return false;
        bool modifierPresent = false;
        unsigned short fallback = modID;
        for (std::list<Modifier>::const_iterator mod = mods.begin();
        bool modifierPresent = false;
        unsigned short fallback = modID;
        for (std::list<Modifier>::const_iterator mod = mods.begin();
@@ -382,8 +404,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
                size_t const alength = strlen(mod->Alias);
                switch(mod->Pos) {
                case Modifier::POSTFIX:
                size_t const alength = strlen(mod->Alias);
                switch(mod->Pos) {
                case Modifier::POSTFIX:
-                       if (str.compare(str.length() - alength, alength,
-                                       mod->Alias, 0, alength) != 0)
+                       if (str.length() <= alength ||
+                             str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0)
                                continue;
                        str.erase(str.length() - alength);
                        modID = mod->ID;
                                continue;
                        str.erase(str.length() - alength);
                        modID = mod->ID;
@@ -424,6 +446,13 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
                                           pkgCacheFile &Cache, std::string pkg,
                                           Version const &fallback, CacheSetHelper &helper,
                                           bool const onlyFromName) {
                                           pkgCacheFile &Cache, std::string pkg,
                                           Version const &fallback, CacheSetHelper &helper,
                                           bool const onlyFromName) {
+        PackageSet pkgset;
+        if(FileExists(pkg))
+        {
+                PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper);
+                return VersionContainerInterface::FromPackage(vci, Cache, pkgset.begin(), fallback, helper);
+        }
+
        std::string ver;
        bool verIsRel = false;
        size_t const vertag = pkg.find_last_of("/=");
        std::string ver;
        bool verIsRel = false;
        size_t const vertag = pkg.find_last_of("/=");
@@ -432,7 +461,6 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
                verIsRel = (pkg[vertag] == '/');
                pkg.erase(vertag);
        }
                verIsRel = (pkg[vertag] == '/');
                pkg.erase(vertag);
        }
-       PackageSet pkgset;
        if (onlyFromName == false)
                PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper);
        else {
        if (onlyFromName == false)
                PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper);
        else {
@@ -578,37 +606,43 @@ pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
 }
                                                                        /*}}}*/
 // canNotFindTask - handle the case no package is found for a task     /*{{{*/
 }
                                                                        /*}}}*/
 // canNotFindTask - handle the case no package is found for a task     /*{{{*/
-void CacheSetHelper::canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
+void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find task '%s'"), pattern.c_str());
 }
                                                                        /*}}}*/
 // canNotFindRegEx - handle the case no package is found by a regex    /*{{{*/
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find task '%s'"), pattern.c_str());
 }
                                                                        /*}}}*/
 // canNotFindRegEx - handle the case no package is found by a regex    /*{{{*/
-void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
+void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
 }
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
 }
-                                                                       /*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+// canNotFindFnmatch - handle the case no package is found by a fnmatch        /*{{{*/
+   void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
+       if (ShowError == true)
+               _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
+}
+#endif                                                                 /*}}}*/
 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
-void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) {
+APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
 }
                                                                        /*}}}*/
 // canNotFindAllVer                                                    /*{{{*/
 }
                                                                        /*}}}*/
 // canNotFindAllVer                                                    /*{{{*/
-void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
                pkgCache::PkgIterator const &Pkg) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Can't select versions from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
 }
                                                                        /*}}}*/
 // canNotFindInstCandVer                                               /*{{{*/
                pkgCache::PkgIterator const &Pkg) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Can't select versions from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
 }
                                                                        /*}}}*/
 // canNotFindInstCandVer                                               /*{{{*/
-void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
                pkgCache::PkgIterator const &Pkg) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
 }
                                                                        /*}}}*/
 // canNotFindInstCandVer                                               /*{{{*/
                pkgCache::PkgIterator const &Pkg) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
 }
                                                                        /*}}}*/
 // canNotFindInstCandVer                                               /*{{{*/
-void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
                pkgCache::PkgIterator const &Pkg) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
                pkgCache::PkgIterator const &Pkg) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
@@ -639,20 +673,27 @@ pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache
 }
                                                                        /*}}}*/
 // showTaskSelection                                                   /*{{{*/
 }
                                                                        /*}}}*/
 // showTaskSelection                                                   /*{{{*/
-void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &pkg,
-                                      std::string const &pattern) {
+APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
+                                      std::string const &/*pattern*/) {
 }
                                                                        /*}}}*/
 // showRegExSelection                                                  /*{{{*/
 }
                                                                        /*}}}*/
 // showRegExSelection                                                  /*{{{*/
-void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &pkg,
-                                       std::string const &pattern) {
+APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/*pkg*/,
+                                       std::string const &/*pattern*/) {
+}
+                                                                       /*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+// showFnmatchSelection                                                        /*{{{*/
+APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/,
+                                         std::string const &/*pattern*/) {
 }
                                                                        /*}}}*/
 }
                                                                        /*}}}*/
+#endif
 // showSelectedVersion                                                 /*{{{*/
 // showSelectedVersion                                                 /*{{{*/
-void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &Pkg,
-                                        pkgCache::VerIterator const Ver,
-                                        std::string const &ver,
-                                        bool const verIsRel) {
+APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
+                                        pkgCache::VerIterator const /*Ver*/,
+                                        std::string const &/*ver*/,
+                                        bool const /*verIsRel*/) {
 }
                                                                        /*}}}*/
 }
 }
                                                                        /*}}}*/
 }