- if (List.size() == 0 && sList.size() == 0)
- return _error->Error("Unable to locate any package files, perhaps this is not a Debian Disc");
-
- // Check if the CD is in the database
- string Name;
- if (Database.Exists("CD::" + ID) == false ||
- _config->FindB("APT::CDROM::Rename",false) == true)
- {
- // Try to use the CDs label if at all possible
- if (InfoDir.empty() == false &&
- FileExists(InfoDir + "/info") == true)
- {
- ifstream F(string(InfoDir + "/info").c_str());
- if (!F == 0)
- getline(F,Name);
-
- if (Name.empty() == false)
- {
- // Escape special characters
- string::iterator J = Name.begin();
- for (; J != Name.end(); J++)
- if (*J == '"' || *J == ']' || *J == '[')
- *J = '_';
-
- cout << "Found label '" << Name << "'" << endl;
- Database.Set("CD::" + ID + "::Label",Name);
- }
- }
-
- if (_config->FindB("APT::CDROM::Rename",false) == true ||
- Name.empty() == true)
- {
- cout << "Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'";
- while (1)
- {
- Name = PromptLine("");
- if (Name.empty() == false &&
- Name.find('"') == string::npos &&
- Name.find('[') == string::npos &&
- Name.find(']') == string::npos)
- break;
- cout << "That is not a valid name, try again " << endl;
- }
- }
- }
- else
- Name = Database.Find("CD::" + ID);
-
- // Escape special characters
- string::iterator J = Name.begin();
- for (; J != Name.end(); J++)
- if (*J == '"' || *J == ']' || *J == '[')
- *J = '_';
-
- Database.Set("CD::" + ID,Name);
- cout << "This Disc is called:" << endl << " '" << Name << "'" << endl;
-
- // Copy the package files to the state directory
- PackageCopy Copy;
- SourceCopy SrcCopy;
- if (Copy.CopyPackages(CDROM,Name,List) == false ||
- SrcCopy.CopyPackages(CDROM,Name,sList) == false)
- return false;
-
- ReduceSourcelist(CDROM,List);
- ReduceSourcelist(CDROM,sList);
-
- // Write the database and sourcelist
- if (_config->FindB("APT::cdrom::NoAct",false) == false)
- {
- if (WriteDatabase(Database) == false)
- return false;
-
- cout << "Writing new source list" << endl;
- if (WriteSourceList(Name,List,false) == false ||
- WriteSourceList(Name,sList,true) == false)
- return false;
- }
-
- // Print the sourcelist entries
- cout << "Source List entries for this Disc are:" << endl;
- for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
- {
- string::size_type Space = (*I).find(' ');
- if (Space == string::npos)
- return _error->Error("Internal error");
-
- cout << "deb cdrom:[" << Name << "]/" << string(*I,0,Space) <<
- " " << string(*I,Space+1) << endl;
- }
-
- for (vector<string>::iterator I = sList.begin(); I != sList.end(); I++)
- {
- string::size_type Space = (*I).find(' ');
- if (Space == string::npos)
- return _error->Error("Internal error");
-
- cout << "deb-src cdrom:[" << Name << "]/" << string(*I,0,Space) <<
- " " << string(*I,Space+1) << endl;
- }
-
- cout << "Repeat this process for the rest of the CDs in your set." << endl;
-
- // Unmount and finish
- if (_config->FindB("APT::CDROM::NoMount",false) == false)
- UnmountCdrom(CDROM);
-
- return true;