]>
git.saurik.com Git - apt.git/blob - methods/cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.15 1999/10/02 04:14:54 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
24 ::Configuration Database
;
27 virtual bool Fetch(FetchItem
*Itm
);
28 string
GetID(string Name
);
35 // CDROMMethod::CDROMethod - Constructor /*{{{*/
36 // ---------------------------------------------------------------------
38 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
|
39 SendConfig
), DatabaseLoaded(false)
43 // CDROMMethod::GetID - Search the database for a matching string /*{{{*/
44 // ---------------------------------------------------------------------
46 string
CDROMMethod::GetID(string Name
)
49 const Configuration::Item
*Top
= Database
.Tree("CD");
55 if (Top
->Value
== Name
)
63 // CDROMMethod::Fetch - Fetch a file /*{{{*/
64 // ---------------------------------------------------------------------
66 bool CDROMMethod::Fetch(FetchItem
*Itm
)
69 string File
= Get
.Path
;
72 bool Debug
= _config
->FindB("Debug::Acquire::cdrom",false);
74 /* All IMS queries are returned as a hit, CDROMs are readonly so
75 time stamps never change */
76 if (Itm
->LastModified
!= 0)
78 Res
.LastModified
= Itm
->LastModified
;
86 if (DatabaseLoaded
== false)
89 string DFile
= _config
->FindFile("Dir::State::cdroms");
90 if (FileExists(DFile
) == true)
92 if (ReadConfigFile(Database
,DFile
) == false)
93 return _error
->Error("Unable to read the cdrom database %s",
96 DatabaseLoaded
= true;
99 // All non IMS queries for package files fail.
100 if (Itm
->IndexFile
== true || GetID(Get
.Host
).empty() == true)
102 Fail("Please use apt-cdrom to make this CD recognized by APT."
103 " apt-get update cannot be used to add new CDs");
107 // We already have a CD inserted, but it is the wrong one
108 if (CurrentID
.empty() == false && Database
.Find("CD::" + CurrentID
) != Get
.Host
)
110 Fail("Wrong CD",true);
114 string CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
116 CDROM
= SafeGetCWD() + '/' + CDROM
;
118 while (CurrentID
.empty() == true)
121 for (unsigned int Version
= 2; Version
!= 0; Version
--)
123 if (IdentCdrom(CDROM
,NewID
,Version
) == false)
127 clog
<< "ID " << Version
<< " " << NewID
<< endl
;
130 if (Database
.Find("CD::" + NewID
) == Get
.Host
)
140 // I suppose this should prompt somehow?
141 if (UnmountCdrom(CDROM
) == false)
142 return _error
->Error("Unable to unmount the CD-ROM in %s, it may still be in use.",
144 if (MediaFail(Get
.Host
,CDROM
) == false)
147 Fail("Wrong CD",true);
155 Res
.Filename
= CDROM
+ File
;
157 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
158 return _error
->Error("File not found");
160 if (NewID
.empty() == false)
162 Res
.LastModified
= Buf
.st_mtime
;
164 Res
.Size
= Buf
.st_size
;