X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/e42eb508e01f4de6def088fe941344d3ca733fa5..dd18f4babe1549727ba93eb8100befecff6ad635:/methods/cdrom.cc diff --git a/methods/cdrom.cc b/methods/cdrom.cc index a44465766..a2045e729 100644 --- a/methods/cdrom.cc +++ b/methods/cdrom.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: cdrom.cc,v 1.9 1999/05/23 05:45:13 jgg Exp $ +// $Id: cdrom.cc,v 1.18 2001/05/22 04:01:41 jgg Exp $ /* ###################################################################### CDROM URI method for APT @@ -16,16 +16,23 @@ #include #include + +#include /*}}}*/ +using namespace std; + class CDROMMethod : public pkgAcqMethod { - Configuration Database; bool DatabaseLoaded; + ::Configuration Database; string CurrentID; + string CDROM; + bool Mounted; virtual bool Fetch(FetchItem *Itm); string GetID(string Name); + virtual void Exit(); public: @@ -35,11 +42,23 @@ class CDROMMethod : public pkgAcqMethod // CDROMMethod::CDROMethod - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly | - SendConfig), DatabaseLoaded(false) +CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly | + SendConfig | NeedsCleanup | + Removable), + DatabaseLoaded(false), + Mounted(false) { }; /*}}}*/ +// CDROMMethod::Exit - Unmount the disc if necessary /*{{{*/ +// --------------------------------------------------------------------- +/* */ +void CDROMMethod::Exit() +{ + if (Mounted == true) + UnmountCdrom(CDROM); +} + /*}}}*/ // CDROMMethod::GetID - Search the database for a matching string /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -68,13 +87,16 @@ bool CDROMMethod::Fetch(FetchItem *Itm) URI Get = Itm->Uri; string File = Get.Path; FetchResult Res; - + + bool Debug = _config->FindB("Debug::Acquire::cdrom",false); + /* All IMS queries are returned as a hit, CDROMs are readonly so time stamps never change */ if (Itm->LastModified != 0) { Res.LastModified = Itm->LastModified; Res.IMSHit = true; + Res.Filename = File; URIDone(Res); return true; } @@ -108,19 +130,32 @@ bool CDROMMethod::Fetch(FetchItem *Itm) return true; } - string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/"); + CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/"); if (CDROM[0] == '.') CDROM= SafeGetCWD() + '/' + CDROM; string NewID; - while (1) + while (CurrentID.empty() == true) { - if (IdentCdrom(CDROM,NewID) == false) - return false; - - // A hit - if (Database.Find("CD::" + NewID) == Get.Host) - break; + bool Hit = false; + for (unsigned int Version = 2; Version != 0; Version--) + { + if (IdentCdrom(CDROM,NewID,Version) == false) + return false; + + if (Debug == true) + clog << "ID " << Version << " " << NewID << endl; + + // A hit + if (Database.Find("CD::" + NewID) == Get.Host) + { + Hit = true; + break; + } + } + if (Hit == true) + break; + // I suppose this should prompt somehow? if (UnmountCdrom(CDROM) == false) return _error->Error("Unable to unmount the CD-ROM in %s, it may still be in use.", @@ -133,6 +168,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm) } MountCdrom(CDROM); + Mounted = true; } // Found a CD @@ -141,9 +177,9 @@ bool CDROMMethod::Fetch(FetchItem *Itm) if (stat(Res.Filename.c_str(),&Buf) != 0) return _error->Error("File not found"); - CurrentID = NewID; + if (NewID.empty() == false) + CurrentID = NewID; Res.LastModified = Buf.st_mtime; - Res.IMSHit = true; Res.Size = Buf.st_size; URIDone(Res); return true;