1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.2 1998/12/04 22:56:55 jgg Exp $
4 /* ######################################################################
6 CDROM URI method for APT
8 ##################################################################### */
10 // Include Files /*{{{*/
11 #include <apt-pkg/acquire-method.h>
12 #include <apt-pkg/cdromutl.h>
13 #include <apt-pkg/error.h>
14 #include <apt-pkg/configuration.h>
15 #include <apt-pkg/fileutl.h>
21 class CDROMMethod
: public pkgAcqMethod
23 Configuration Database
;
26 virtual bool Fetch(FetchItem
*Itm
);
27 string
GetID(string Name
);
34 // CDROMMethod::CDROMethod - Constructor /*{{{*/
35 // ---------------------------------------------------------------------
37 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
)
40 string DFile
= _config
->FindFile("Dir::State::cdroms");
41 if (FileExists(DFile
) == true)
43 if (ReadConfigFile(Database
,DFile
) == false)
45 _error
->Error("Unable to read the cdrom database %s",
52 // CDROMMethod::GetID - Get the ID hash for /*{{{*/
53 // ---------------------------------------------------------------------
54 /* We search the configuration space for the name and then return the ID
55 tag associated with it. */
56 string
CDROMMethod::GetID(string Name
)
58 const Configuration::Item
*Top
= Database
.Tree(0);
61 if (Top
->Value
== Name
)
70 // CDROMMethod::Fetch - Fetch a file /*{{{*/
71 // ---------------------------------------------------------------------
73 bool CDROMMethod::Fetch(FetchItem
*Itm
)
76 string File
= Get
.Path
;
79 /* All IMS queries are returned as a hit, CDROMs are readonly so
80 time stamps never change */
81 if (Itm
->LastModified
!= 0)
83 Res
.LastModified
= Itm
->LastModified
;
89 string ID
= GetID(Get
.Host
);
91 // All non IMS queries for package files fail.
92 if (Itm
->IndexFile
== true || ID
.empty() == false)
94 Fail("Please use apt-cdrom to make this CD recognized by APT."
95 " apt-get update cannot be used to add new CDs");
99 // We already have a CD inserted, but it is the wrong one
100 if (CurrentID
.empty() == false && ID
!= CurrentID
)
102 Fail("Wrong CD",true);
106 string CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
110 if (IdentCdrom(CDROM
,NewID
) == false)
118 if (MediaFail(Get
.Host
,CDROM
) == false)
130 Res
.Filename
= CDROM
+ File
;
131 if (FileExists(Res
.Filename
) == false)
132 return _error
->Error("File not found");
135 Res
.LastModified
= Itm
->LastModified
;
141 return _error
->Error("CDROM not found");