]>
git.saurik.com Git - apt.git/blob - methods/cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.17 2000/01/17 07:11:49 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
;
29 virtual bool Fetch(FetchItem
*Itm
);
30 string
GetID(string Name
);
38 // CDROMMethod::CDROMethod - Constructor /*{{{*/
39 // ---------------------------------------------------------------------
41 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
|
42 SendConfig
| NeedsCleanup
|
44 DatabaseLoaded(false),
49 // CDROMMethod::Exit - Unmount the disc if necessary /*{{{*/
50 // ---------------------------------------------------------------------
52 void CDROMMethod::Exit()
58 // CDROMMethod::GetID - Search the database for a matching string /*{{{*/
59 // ---------------------------------------------------------------------
61 string
CDROMMethod::GetID(string Name
)
64 const Configuration::Item
*Top
= Database
.Tree("CD");
70 if (Top
->Value
== Name
)
78 // CDROMMethod::Fetch - Fetch a file /*{{{*/
79 // ---------------------------------------------------------------------
81 bool CDROMMethod::Fetch(FetchItem
*Itm
)
84 string File
= Get
.Path
;
87 bool Debug
= _config
->FindB("Debug::Acquire::cdrom",false);
89 /* All IMS queries are returned as a hit, CDROMs are readonly so
90 time stamps never change */
91 if (Itm
->LastModified
!= 0)
93 Res
.LastModified
= Itm
->LastModified
;
101 if (DatabaseLoaded
== false)
104 string DFile
= _config
->FindFile("Dir::State::cdroms");
105 if (FileExists(DFile
) == true)
107 if (ReadConfigFile(Database
,DFile
) == false)
108 return _error
->Error("Unable to read the cdrom database %s",
111 DatabaseLoaded
= true;
114 // All non IMS queries for package files fail.
115 if (Itm
->IndexFile
== true || GetID(Get
.Host
).empty() == true)
117 Fail("Please use apt-cdrom to make this CD recognized by APT."
118 " apt-get update cannot be used to add new CDs");
122 // We already have a CD inserted, but it is the wrong one
123 if (CurrentID
.empty() == false && Database
.Find("CD::" + CurrentID
) != Get
.Host
)
125 Fail("Wrong CD",true);
129 CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
131 CDROM
= SafeGetCWD() + '/' + CDROM
;
133 while (CurrentID
.empty() == true)
136 for (unsigned int Version
= 2; Version
!= 0; Version
--)
138 if (IdentCdrom(CDROM
,NewID
,Version
) == false)
142 clog
<< "ID " << Version
<< " " << NewID
<< endl
;
145 if (Database
.Find("CD::" + NewID
) == Get
.Host
)
155 // I suppose this should prompt somehow?
156 if (UnmountCdrom(CDROM
) == false)
157 return _error
->Error("Unable to unmount the CD-ROM in %s, it may still be in use.",
159 if (MediaFail(Get
.Host
,CDROM
) == false)
162 Fail("Wrong CD",true);
171 Res
.Filename
= CDROM
+ File
;
173 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
174 return _error
->Error("File not found");
176 if (NewID
.empty() == false)
178 Res
.LastModified
= Buf
.st_mtime
;
179 Res
.Size
= Buf
.st_size
;