]>
git.saurik.com Git - apt.git/blob - methods/cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.3 1998/12/05 01:45:21 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
|
41 string DFile
= _config
->FindFile("Dir::State::cdroms");
42 if (FileExists(DFile
) == true)
44 if (ReadConfigFile(Database
,DFile
) == false)
46 _error
->Error("Unable to read the cdrom database %s",
53 // CDROMMethod::GetID - Get the ID hash for /*{{{*/
54 // ---------------------------------------------------------------------
55 /* We search the configuration space for the name and then return the ID
56 tag associated with it. */
57 string
CDROMMethod::GetID(string Name
)
59 const Configuration::Item
*Top
= Database
.Tree(0);
62 if (Top
->Value
== Name
)
71 // CDROMMethod::Fetch - Fetch a file /*{{{*/
72 // ---------------------------------------------------------------------
74 bool CDROMMethod::Fetch(FetchItem
*Itm
)
77 string File
= Get
.Path
;
80 /* All IMS queries are returned as a hit, CDROMs are readonly so
81 time stamps never change */
82 if (Itm
->LastModified
!= 0)
84 Res
.LastModified
= Itm
->LastModified
;
90 string ID
= GetID(Get
.Host
);
92 // All non IMS queries for package files fail.
93 if (Itm
->IndexFile
== true || ID
.empty() == false)
95 Fail("Please use apt-cdrom to make this CD recognized by APT."
96 " apt-get update cannot be used to add new CDs");
100 // We already have a CD inserted, but it is the wrong one
101 if (CurrentID
.empty() == false && ID
!= CurrentID
)
103 Fail("Wrong CD",true);
107 string CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
109 CDROM
= SafeGetCWD() + '/' + CDROM
;
113 if (IdentCdrom(CDROM
,NewID
) == false)
121 if (MediaFail(Get
.Host
,CDROM
) == false)
124 Fail("Wrong CD",true);
134 Res
.Filename
= CDROM
+ File
;
135 if (FileExists(Res
.Filename
) == false)
136 return _error
->Error("File not found");
139 Res
.LastModified
= Itm
->LastModified
;
145 return _error
->Error("CDROM not found");