]>
git.saurik.com Git - apt.git/blob - methods/cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.19 2002/11/22 07:26:10 doogie 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>
25 class CDROMMethod
: public pkgAcqMethod
28 ::Configuration Database
;
33 virtual bool Fetch(FetchItem
*Itm
);
34 string
GetID(string Name
);
42 // CDROMMethod::CDROMethod - Constructor /*{{{*/
43 // ---------------------------------------------------------------------
45 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
|
46 SendConfig
| NeedsCleanup
|
48 DatabaseLoaded(false),
53 // CDROMMethod::Exit - Unmount the disc if necessary /*{{{*/
54 // ---------------------------------------------------------------------
56 void CDROMMethod::Exit()
62 // CDROMMethod::GetID - Search the database for a matching string /*{{{*/
63 // ---------------------------------------------------------------------
65 string
CDROMMethod::GetID(string Name
)
68 const Configuration::Item
*Top
= Database
.Tree("CD");
74 if (Top
->Value
== Name
)
82 // CDROMMethod::Fetch - Fetch a file /*{{{*/
83 // ---------------------------------------------------------------------
85 bool CDROMMethod::Fetch(FetchItem
*Itm
)
88 string File
= Get
.Path
;
91 bool Debug
= _config
->FindB("Debug::Acquire::cdrom",false);
93 /* All IMS queries are returned as a hit, CDROMs are readonly so
94 time stamps never change */
95 if (Itm
->LastModified
!= 0)
97 Res
.LastModified
= Itm
->LastModified
;
105 if (DatabaseLoaded
== false)
108 string DFile
= _config
->FindFile("Dir::State::cdroms");
109 if (FileExists(DFile
) == true)
111 if (ReadConfigFile(Database
,DFile
) == false)
112 return _error
->Error("Unable to read the cdrom database %s",
115 DatabaseLoaded
= true;
118 // All non IMS queries for package files fail.
119 if (Itm
->IndexFile
== true || GetID(Get
.Host
).empty() == true)
121 Fail("Please use apt-cdrom to make this CD recognized by APT."
122 " apt-get update cannot be used to add new CDs");
126 // We already have a CD inserted, but it is the wrong one
127 if (CurrentID
.empty() == false && Database
.Find("CD::" + CurrentID
) != Get
.Host
)
129 Fail("Wrong CD",true);
133 CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
135 CDROM
= SafeGetCWD() + '/' + CDROM
;
137 while (CurrentID
.empty() == true)
140 Mounted
= MountCdrom(CDROM
);
141 for (unsigned int Version
= 2; Version
!= 0; Version
--)
143 if (IdentCdrom(CDROM
,NewID
,Version
) == false)
147 clog
<< "ID " << Version
<< " " << NewID
<< endl
;
150 if (Database
.Find("CD::" + NewID
) == Get
.Host
)
160 // I suppose this should prompt somehow?
161 if (UnmountCdrom(CDROM
) == false)
162 return _error
->Error("Unable to unmount the CD-ROM in %s, it may still be in use.",
164 if (MediaFail(Get
.Host
,CDROM
) == false)
167 Fail("Wrong CD",true);
173 Res
.Filename
= CDROM
+ File
;
175 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
176 return _error
->Error("File not found");
178 if (NewID
.empty() == false)
180 Res
.LastModified
= Buf
.st_mtime
;
181 Res
.Size
= Buf
.st_size
;