]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
merge patch from Daniel Hartwig to Show a error message if {,dist-}upgrade is used...
[apt.git] / apt-pkg / contrib / configuration.cc
index ff80dfaf870f37b4913b8e08349add6b32ec6ef7..31cd9f8adc25efa0a4d6cf9a3bfd2f3a5105ee3b 100644 (file)
@@ -171,48 +171,60 @@ string Configuration::Find(const char *Name,const char *Default) const
 string Configuration::FindFile(const char *Name,const char *Default) const
 {
    const Item *RootItem = Lookup("RootDir");
-   std::string rootDir =  (RootItem == 0) ? "" : RootItem->Value;
-   if(rootDir.size() > 0 && rootDir[rootDir.size() - 1] != '/')
-     rootDir.push_back('/');
+   std::string result =  (RootItem == 0) ? "" : RootItem->Value;
+   if(result.empty() == false && result[result.size() - 1] != '/')
+     result.push_back('/');
 
    const Item *Itm = Lookup(Name);
    if (Itm == 0 || Itm->Value.empty() == true)
    {
-      if (Default == 0)
-        return rootDir;
-      else
-        return rootDir + Default;
+      if (Default != 0)
+        result.append(Default);
    }
-   
-   string val = Itm->Value;
-   while (Itm->Parent != 0)
+   else
    {
-      if (Itm->Parent->Value.empty() == true)
+      string val = Itm->Value;
+      while (Itm->Parent != 0)
       {
-        Itm = Itm->Parent;
-        continue;
-      }
+        if (Itm->Parent->Value.empty() == true)
+        {
+           Itm = Itm->Parent;
+           continue;
+        }
 
-      // Absolute
-      if (val.length() >= 1 && val[0] == '/')
-         break;
+        // Absolute
+        if (val.length() >= 1 && val[0] == '/')
+        {
+           if (val.compare(0, 9, "/dev/null") == 0)
+              val.erase(9);
+           break;
+        }
 
-      // ~/foo or ./foo 
-      if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/')
-        break;
-        
-      // ../foo 
-      if (val.length() >= 3 && val[0] == '.' && val[1] == '.' && val[2] == '/')
-        break;
-      
-      if (Itm->Parent->Value.end()[-1] != '/')
-        val.insert(0, "/");
+        // ~/foo or ./foo
+        if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/')
+           break;
+
+        // ../foo
+        if (val.length() >= 3 && val[0] == '.' && val[1] == '.' && val[2] == '/')
+           break;
+
+        if (Itm->Parent->Value.end()[-1] != '/')
+           val.insert(0, "/");
 
-      val.insert(0, Itm->Parent->Value);
-      Itm = Itm->Parent;
+        val.insert(0, Itm->Parent->Value);
+        Itm = Itm->Parent;
+      }
+      result.append(val);
    }
 
-   return rootDir + val;
+   // do some normalisation by removing // and /./ from the path
+   size_t found = string::npos;
+   while ((found = result.find("/./")) != string::npos)
+      result.replace(found, 3, "/");
+   while ((found = result.find("//")) != string::npos)
+      result.replace(found, 2, "/");
+
+   return result;
 }
                                                                        /*}}}*/
 // Configuration::FindDir - Find a directory name                      /*{{{*/
@@ -222,7 +234,12 @@ string Configuration::FindDir(const char *Name,const char *Default) const
 {
    string Res = FindFile(Name,Default);
    if (Res.end()[-1] != '/')
+   {
+      size_t const found = Res.rfind("/dev/null");
+      if (found != string::npos && found == Res.size() - 9)
+        return Res; // /dev/null returning
       return Res + '/';
+   }
    return Res;
 }
                                                                        /*}}}*/
@@ -403,6 +420,18 @@ void Configuration::Clear(string const &Name, string const &Value)
       }
    }
      
+}
+                                                                       /*}}}*/
+// Configuration::Clear - Clear everything                             /*{{{*/
+// ---------------------------------------------------------------------
+void Configuration::Clear()
+{
+   const Configuration::Item *Top = Tree(0);
+   while( Top != 0 )
+   {
+      Clear(Top->FullTag());
+      Top = Top->Next;
+   }
 }
                                                                        /*}}}*/
 // Configuration::Clear - Clear an entire tree                         /*{{{*/
@@ -941,7 +970,7 @@ Configuration::MatchAgainstConfig::MatchAgainstConfig(char const * Config)
         continue;
       }
    }
-   if (strings.size() == 0)
+   if (strings.empty() == true)
       patterns.push_back(NULL);
 }
                                                                        /*}}}*/