* apt-pkg/cdrom.cc:
[ntk/apt.git] / apt-pkg / cdrom.cc
index d9ecdf4..699f66f 100644 (file)
@@ -277,6 +277,7 @@ bool pkgCdrom::DropBinaryArch(vector<string> &List)
 /* Here we go and stat every file that we found and strip dup inodes. */
 bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
 {
+   bool couldFindAllFiles = true;
    // Get a list of all the inodes
    ino_t *Inodes = new ino_t[List.size()];
    for (unsigned int I = 0; I != List.size(); ++I)
@@ -297,21 +298,22 @@ bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
       }
 
       if (found == false)
-         _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), Name);
+      {
+        _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), Name);
+        couldFindAllFiles = false;
+        Inodes[I] = 0;
+      }
    }
 
-   if (_error->PendingError() == true) {
-      delete[] Inodes;
-      return false;
-   }
-   
    // Look for dups
    for (unsigned int I = 0; I != List.size(); I++)
    {
+      if (Inodes[I] == 0)
+        continue;
       for (unsigned int J = I+1; J < List.size(); J++)
       {
         // No match
-        if (Inodes[J] != Inodes[I])
+        if (Inodes[J] == 0 || Inodes[J] != Inodes[I])
            continue;
         
         // We score the two paths.. and erase one
@@ -337,7 +339,7 @@ bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
         List.erase(List.begin()+I);
    }
    
-   return true;
+   return couldFindAllFiles;
 }
                                                                        /*}}}*/
 // ReduceSourceList - Takes the path list and reduces it               /*{{{*/
@@ -407,28 +409,12 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf)
    
    /* Write out all of the configuration directives by walking the
       configuration tree */
-   const Configuration::Item *Top = Cnf.Tree(0);
-   for (; Top != 0;)
-   {
-      // Print the config entry
-      if (Top->Value.empty() == false)
-        Out <<  Top->FullTag() + " \"" << Top->Value << "\";" << endl;
-      
-      if (Top->Child != 0)
-      {
-        Top = Top->Child;
-        continue;
-      }
-      
-      while (Top != 0 && Top->Next == 0)
-        Top = Top->Parent;
-      if (Top != 0)
-        Top = Top->Next;
-   }   
+   Cnf.Dump(Out, NULL, "%f \"%v\";\n", false);
 
    Out.close();
-   
-   link(DFile.c_str(),string(DFile + '~').c_str());
+
+   if (FileExists(DFile) == true)
+      rename(DFile.c_str(), string(DFile + '~').c_str());
    if (rename(NewFile.c_str(),DFile.c_str()) != 0)
       return _error->Errno("rename","Failed to rename %s.new to %s",
                           DFile.c_str(),DFile.c_str());
@@ -695,7 +681,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log)                                     /*{{{*/
       return false;
    }
 
-   chdir(StartDir.c_str());
+   if (chdir(StartDir.c_str()) != 0)
+      return _error->Errno("chdir","Unable to change to %s", StartDir.c_str());
 
    if (_config->FindB("Debug::aptcdrom",false) == true)
    {
@@ -716,8 +703,13 @@ bool pkgCdrom::Add(pkgCdromStatus *log)                                    /*{{{*/
    DropBinaryArch(List);
    DropRepeats(List,"Packages");
    DropRepeats(SourceList,"Sources");
+   // FIXME: We ignore stat() errors here as we usually have only one of those in use
+   // This has little potencial to drop 'valid' stat() errors as we know that one of these
+   // files need to exist, but it would be better if we would check it here
+   _error->PushToStack();
    DropRepeats(SigList,"Release.gpg");
    DropRepeats(SigList,"InRelease");
+   _error->RevertToStack();
    DropRepeats(TransList,"");
    if(log != NULL) {
       msg.str("");