]>
git.saurik.com Git - apt-legacy.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>
27 class CDROMMethod
: public pkgAcqMethod
30 ::Configuration Database
;
35 virtual bool Fetch(FetchItem
*Itm
);
36 string
GetID(string Name
);
44 // CDROMMethod::CDROMethod - Constructor /*{{{*/
45 // ---------------------------------------------------------------------
47 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
|
48 SendConfig
| NeedsCleanup
|
50 DatabaseLoaded(false),
55 // CDROMMethod::Exit - Unmount the disc if necessary /*{{{*/
56 // ---------------------------------------------------------------------
58 void CDROMMethod::Exit()
64 // CDROMMethod::GetID - Search the database for a matching string /*{{{*/
65 // ---------------------------------------------------------------------
67 string
CDROMMethod::GetID(string Name
)
70 const Configuration::Item
*Top
= Database
.Tree("CD");
76 if (Top
->Value
== Name
)
84 // CDROMMethod::Fetch - Fetch a file /*{{{*/
85 // ---------------------------------------------------------------------
87 bool CDROMMethod::Fetch(FetchItem
*Itm
)
90 string File
= Get
.Path
;
93 bool Debug
= _config
->FindB("Debug::Acquire::cdrom",false);
95 /* All IMS queries are returned as a hit, CDROMs are readonly so
96 time stamps never change */
97 if (Itm
->LastModified
!= 0)
99 Res
.LastModified
= Itm
->LastModified
;
101 Res
.Filename
= Itm
->DestFile
;
107 if (DatabaseLoaded
== false)
110 string DFile
= _config
->FindFile("Dir::State::cdroms");
111 if (FileExists(DFile
) == true)
113 if (ReadConfigFile(Database
,DFile
) == false)
114 return _error
->Error(_("Unable to read the cdrom database %s"),
117 DatabaseLoaded
= true;
120 // All non IMS queries for package files fail.
121 if (Itm
->IndexFile
== true || GetID(Get
.Host
).empty() == true)
123 Fail(_("Please use apt-cdrom to make this CD-ROM recognized by APT."
124 " apt-get update cannot be used to add new CD-ROMs"));
128 // We already have a CD inserted, but it is the wrong one
129 if (CurrentID
.empty() == false && Database
.Find("CD::" + CurrentID
) != Get
.Host
)
131 Fail(_("Wrong CD-ROM"),true);
135 CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
137 CDROM
= SafeGetCWD() + '/' + CDROM
;
139 while (CurrentID
.empty() == true)
142 Mounted
= MountCdrom(CDROM
);
143 for (unsigned int Version
= 2; Version
!= 0; Version
--)
145 if (IdentCdrom(CDROM
,NewID
,Version
) == false)
149 clog
<< "ID " << Version
<< " " << NewID
<< endl
;
152 if (Database
.Find("CD::" + NewID
) == Get
.Host
)
162 // I suppose this should prompt somehow?
163 if (UnmountCdrom(CDROM
) == false)
164 return _error
->Error(_("Unable to unmount the CD-ROM in %s, it may still be in use."),
166 if (MediaFail(Get
.Host
,CDROM
) == false)
169 return _error
->Error(_("Disk not found."));
174 Res
.Filename
= CDROM
+ File
;
176 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
177 return _error
->Error(_("File not found"));
179 if (NewID
.empty() == false)
181 Res
.LastModified
= Buf
.st_mtime
;
182 Res
.Size
= Buf
.st_size
;
185 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
186 Hash
.AddFD(Fd
.Fd(), Fd
.Size());
187 Res
.TakeHashes(Hash
);
200 setlocale(LC_ALL
, "");