// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: cdrom.cc,v 1.1 1998/12/03 07:29:21 jgg Exp $
+// $Id: cdrom.cc,v 1.7 1998/12/22 08:20:55 jgg Exp $
/* ######################################################################
CDROM URI method for APT
class CDROMMethod : public pkgAcqMethod
{
Configuration Database;
+ bool DatabaseLoaded;
string CurrentID;
virtual bool Fetch(FetchItem *Itm);
// CDROMMethod::CDROMethod - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly)
+CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly |
+ SendConfig), DatabaseLoaded(false)
{
- // Read the database
- string DFile = _config->FindFile("Dir::State::cdroms");
- if (FileExists(DFile) == true)
- {
- if (ReadConfigFile(Database,DFile) == false)
- {
- _error->Error("Unable to read the cdrom database %s",
- DFile.c_str());
- Fail();
- }
- }
};
/*}}}*/
// CDROMMethod::GetID - Get the ID hash for /*{{{*/
tag associated with it. */
string CDROMMethod::GetID(string Name)
{
- const Configuration::Item *Top = Database.Tree(0);
+ if (DatabaseLoaded == false)
+ {
+ // Read the database
+ string DFile = _config->FindFile("Dir::State::cdroms");
+ if (FileExists(DFile) == true)
+ {
+ if (ReadConfigFile(Database,DFile) == false)
+ {
+ _error->Error("Unable to read the cdrom database %s",
+ DFile.c_str());
+ return string();
+ }
+ }
+ DatabaseLoaded = true;
+ }
+
+ const Configuration::Item *Top = Database.Tree("CD");
+ if (Top != 0)
+ Top = Top->Child;
+
for (; Top != 0;)
{
if (Top->Value == Name)
}
string ID = GetID(Get.Host);
+ if (_error->PendingError() == true)
+ return false;
// All non IMS queries for package files fail.
- if (Itm->IndexFile == true || ID.empty() == false)
+ if (Itm->IndexFile == true || ID.empty() == true)
{
Fail("Please use apt-cdrom to make this CD recognized by APT."
" apt-get update cannot be used to add new CDs");
}
string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
+ if (CDROM[0] == '.')
+ CDROM= SafeGetCWD() + '/' + CDROM;
string NewID;
while (1)
{
break;
UnmountCdrom(CDROM);
- MediaFail(Get.Host,CDROM);
+ if (MediaFail(Get.Host,CDROM) == false)
+ {
+ CurrentID = "FAIL";
+ Fail("Wrong CD",true);
+ return true;
+ }
+
MountCdrom(CDROM);
}
if (NewID == ID)
{
Res.Filename = CDROM + File;
- if (FileExists(Res.Filename) == false)
+ struct stat Buf;
+ if (stat(Res.Filename.c_str(),&Buf) != 0)
return _error->Error("File not found");
CurrentID = ID;
- Res.LastModified = Itm->LastModified;
+ Res.LastModified = Buf.st_mtime;
Res.IMSHit = true;
+ Res.Size = Buf.st_size;
URIDone(Res);
return true;
}