]>
git.saurik.com Git - apt-legacy.git/blob - methods/cdrom.cc
2 #include <mach-o/nlist.h>
5 // -*- mode: cpp; mode: fold -*-
7 // $Id: cdrom.cc,v 1.20.2.1 2004/01/16 18:58:50 mdz Exp $
8 /* ######################################################################
10 CDROM URI method for APT
12 ##################################################################### */
14 // Include Files /*{{{*/
15 #include <apt-pkg/acquire-method.h>
16 #include <apt-pkg/cdromutl.h>
17 #include <apt-pkg/error.h>
18 #include <apt-pkg/configuration.h>
19 #include <apt-pkg/fileutl.h>
20 #include <apt-pkg/hashes.h>
31 class CDROMMethod
: public pkgAcqMethod
34 ::Configuration Database
;
39 virtual bool Fetch(FetchItem
*Itm
);
40 string
GetID(string Name
);
48 // CDROMMethod::CDROMethod - Constructor /*{{{*/
49 // ---------------------------------------------------------------------
51 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
|
52 SendConfig
| NeedsCleanup
|
54 DatabaseLoaded(false),
59 // CDROMMethod::Exit - Unmount the disc if necessary /*{{{*/
60 // ---------------------------------------------------------------------
62 void CDROMMethod::Exit()
68 // CDROMMethod::GetID - Search the database for a matching string /*{{{*/
69 // ---------------------------------------------------------------------
71 string
CDROMMethod::GetID(string Name
)
74 const Configuration::Item
*Top
= Database
.Tree("CD");
80 if (Top
->Value
== Name
)
88 // CDROMMethod::Fetch - Fetch a file /*{{{*/
89 // ---------------------------------------------------------------------
91 bool CDROMMethod::Fetch(FetchItem
*Itm
)
94 string File
= Get
.Path
;
97 bool Debug
= _config
->FindB("Debug::Acquire::cdrom",false);
99 /* All IMS queries are returned as a hit, CDROMs are readonly so
100 time stamps never change */
101 if (Itm
->LastModified
!= 0)
103 Res
.LastModified
= Itm
->LastModified
;
105 Res
.Filename
= Itm
->DestFile
;
111 if (DatabaseLoaded
== false)
114 string DFile
= _config
->FindFile("Dir::State::cdroms");
115 if (FileExists(DFile
) == true)
117 if (ReadConfigFile(Database
,DFile
) == false)
118 return _error
->Error(_("Unable to read the cdrom database %s"),
121 DatabaseLoaded
= true;
124 // All non IMS queries for package files fail.
125 if (Itm
->IndexFile
== true || GetID(Get
.Host
).empty() == true)
127 Fail(_("Please use apt-cdrom to make this CD-ROM recognized by APT."
128 " apt-get update cannot be used to add new CD-ROMs"));
132 // We already have a CD inserted, but it is the wrong one
133 if (CurrentID
.empty() == false && Database
.Find("CD::" + CurrentID
) != Get
.Host
)
135 Fail(_("Wrong CD-ROM"),true);
139 CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
141 CDROM
= SafeGetCWD() + '/' + CDROM
;
143 while (CurrentID
.empty() == true)
146 Mounted
= 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 (UnmountCdrom(CDROM
) == false)
168 return _error
->Error(_("Unable to unmount the CD-ROM in %s, it may still be in use."),
170 if (MediaFail(Get
.Host
,CDROM
) == false)
173 return _error
->Error(_("Disk not found."));
178 Res
.Filename
= CDROM
+ File
;
180 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
181 return _error
->Error(_("File not found"));
183 if (NewID
.empty() == false)
185 Res
.LastModified
= Buf
.st_mtime
;
186 Res
.Size
= Buf
.st_size
;
189 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
190 Hash
.AddFD(Fd
.Fd(), Fd
.Size());
191 Res
.TakeHashes(Hash
);
201 memset(nl
, 0, sizeof(nl
));
202 nl
[0].n_un
.n_name
= (char *) "_useMDNSResponder";
203 nlist("/usr/lib/libc.dylib", nl
);
204 if (nl
[0].n_type
!= N_UNDF
)
205 *(int *) nl
[0].n_value
= 0;
207 setlocale(LC_ALL
, "");