]>
git.saurik.com Git - apt.git/blob - methods/cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.16 1999/10/18 00:37:36 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
),
43 DatabaseLoaded(false),
48 // CDROMMethod::Exit - Unmount the disc if necessary /*{{{*/
49 // ---------------------------------------------------------------------
51 void CDROMMethod::Exit()
57 // CDROMMethod::GetID - Search the database for a matching string /*{{{*/
58 // ---------------------------------------------------------------------
60 string
CDROMMethod::GetID(string Name
)
63 const Configuration::Item
*Top
= Database
.Tree("CD");
69 if (Top
->Value
== Name
)
77 // CDROMMethod::Fetch - Fetch a file /*{{{*/
78 // ---------------------------------------------------------------------
80 bool CDROMMethod::Fetch(FetchItem
*Itm
)
83 string File
= Get
.Path
;
86 bool Debug
= _config
->FindB("Debug::Acquire::cdrom",false);
88 /* All IMS queries are returned as a hit, CDROMs are readonly so
89 time stamps never change */
90 if (Itm
->LastModified
!= 0)
92 Res
.LastModified
= Itm
->LastModified
;
100 if (DatabaseLoaded
== false)
103 string DFile
= _config
->FindFile("Dir::State::cdroms");
104 if (FileExists(DFile
) == true)
106 if (ReadConfigFile(Database
,DFile
) == false)
107 return _error
->Error("Unable to read the cdrom database %s",
110 DatabaseLoaded
= true;
113 // All non IMS queries for package files fail.
114 if (Itm
->IndexFile
== true || GetID(Get
.Host
).empty() == true)
116 Fail("Please use apt-cdrom to make this CD recognized by APT."
117 " apt-get update cannot be used to add new CDs");
121 // We already have a CD inserted, but it is the wrong one
122 if (CurrentID
.empty() == false && Database
.Find("CD::" + CurrentID
) != Get
.Host
)
124 Fail("Wrong CD",true);
128 CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
130 CDROM
= SafeGetCWD() + '/' + CDROM
;
132 while (CurrentID
.empty() == true)
135 for (unsigned int Version
= 2; Version
!= 0; Version
--)
137 if (IdentCdrom(CDROM
,NewID
,Version
) == false)
141 clog
<< "ID " << Version
<< " " << NewID
<< endl
;
144 if (Database
.Find("CD::" + NewID
) == Get
.Host
)
154 // I suppose this should prompt somehow?
155 if (UnmountCdrom(CDROM
) == false)
156 return _error
->Error("Unable to unmount the CD-ROM in %s, it may still be in use.",
158 if (MediaFail(Get
.Host
,CDROM
) == false)
161 Fail("Wrong CD",true);
170 Res
.Filename
= CDROM
+ File
;
172 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
173 return _error
->Error("File not found");
175 if (NewID
.empty() == false)
177 Res
.LastModified
= Buf
.st_mtime
;
179 Res
.Size
= Buf
.st_size
;