]>
git.saurik.com Git - apt.git/blob - methods/cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.20.2.1 2004/01/16 18:58:50 mdz 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>
16 #include <apt-pkg/hashes.h>
28 class CDROMMethod
: public pkgAcqMethod
31 ::Configuration Database
;
36 virtual bool Fetch(FetchItem
*Itm
);
37 string
GetID(string Name
);
45 // CDROMMethod::CDROMethod - Constructor /*{{{*/
46 // ---------------------------------------------------------------------
48 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
|
49 SendConfig
| NeedsCleanup
|
51 DatabaseLoaded(false),
58 // CDROMMethod::Exit - Unmount the disc if necessary /*{{{*/
59 // ---------------------------------------------------------------------
61 void CDROMMethod::Exit()
63 if (MountedByApt
== true)
67 // CDROMMethod::GetID - Search the database for a matching string /*{{{*/
68 // ---------------------------------------------------------------------
70 string
CDROMMethod::GetID(string Name
)
73 const Configuration::Item
*Top
= Database
.Tree("CD");
79 if (Top
->Value
== Name
)
87 // CDROMMethod::Fetch - Fetch a file /*{{{*/
88 // ---------------------------------------------------------------------
90 bool CDROMMethod::Fetch(FetchItem
*Itm
)
93 string File
= Get
.Path
;
96 bool Debug
= _config
->FindB("Debug::Acquire::cdrom",false);
98 /* All IMS queries are returned as a hit, CDROMs are readonly so
99 time stamps never change */
100 if (Itm
->LastModified
!= 0)
102 Res
.LastModified
= Itm
->LastModified
;
104 Res
.Filename
= Itm
->DestFile
;
110 if (DatabaseLoaded
== false)
113 string DFile
= _config
->FindFile("Dir::State::cdroms");
114 if (FileExists(DFile
) == true)
116 if (ReadConfigFile(Database
,DFile
) == false)
117 return _error
->Error(_("Unable to read the cdrom database %s"),
120 DatabaseLoaded
= true;
123 // All non IMS queries for package files fail.
124 if (Itm
->IndexFile
== true || GetID(Get
.Host
).empty() == true)
126 Fail(_("Please use apt-cdrom to make this CD-ROM recognized by APT."
127 " apt-get update cannot be used to add new CD-ROMs"));
131 // We already have a CD inserted, but it is the wrong one
132 if (CurrentID
.empty() == false && Database
.Find("CD::" + CurrentID
) != Get
.Host
)
134 Fail(_("Wrong CD-ROM"),true);
138 CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
140 CDROM
= SafeGetCWD() + '/' + CDROM
;
142 while (CurrentID
.empty() == true)
145 if(!IsMounted(CDROM
))
146 MountedByApt
= MountCdrom(CDROM
);
147 for (unsigned int Version
= 2; Version
!= 0; Version
--)
149 if (IdentCdrom(CDROM
,NewID
,Version
) == false)
153 clog
<< "ID " << Version
<< " " << NewID
<< endl
;
156 if (Database
.Find("CD::" + NewID
) == Get
.Host
)
166 // I suppose this should prompt somehow?
167 if (_config
->FindB("APT::CDROM::NoMount",false) == false &&
168 UnmountCdrom(CDROM
) == false)
169 return _error
->Error(_("Unable to unmount the CD-ROM in %s, it may still be in use."),
171 if (MediaFail(Get
.Host
,CDROM
) == false)
174 return _error
->Error(_("Disk not found."));
179 Res
.Filename
= CDROM
+ File
;
181 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
182 return _error
->Error(_("File not found"));
184 if (NewID
.empty() == false)
186 Res
.LastModified
= Buf
.st_mtime
;
187 Res
.Size
= Buf
.st_size
;
190 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
191 Hash
.AddFD(Fd
.Fd(), Fd
.Size());
192 Res
.TakeHashes(Hash
);
201 setlocale(LC_ALL
, "");