]>
git.saurik.com Git - apt.git/blob - methods/cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.9 1999/05/23 05:45:13 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
23 Configuration Database
;
27 virtual bool Fetch(FetchItem
*Itm
);
28 string
GetID(string Name
);
35 // CDROMMethod::CDROMethod - Constructor /*{{{*/
36 // ---------------------------------------------------------------------
38 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
|
39 SendConfig
), DatabaseLoaded(false)
43 // CDROMMethod::GetID - Search the database for a matching string /*{{{*/
44 // ---------------------------------------------------------------------
46 string
CDROMMethod::GetID(string Name
)
49 const Configuration::Item
*Top
= Database
.Tree("CD");
55 if (Top
->Value
== Name
)
63 // CDROMMethod::Fetch - Fetch a file /*{{{*/
64 // ---------------------------------------------------------------------
66 bool CDROMMethod::Fetch(FetchItem
*Itm
)
69 string File
= Get
.Path
;
72 /* All IMS queries are returned as a hit, CDROMs are readonly so
73 time stamps never change */
74 if (Itm
->LastModified
!= 0)
76 Res
.LastModified
= Itm
->LastModified
;
83 if (DatabaseLoaded
== false)
86 string DFile
= _config
->FindFile("Dir::State::cdroms");
87 if (FileExists(DFile
) == true)
89 if (ReadConfigFile(Database
,DFile
) == false)
90 return _error
->Error("Unable to read the cdrom database %s",
93 DatabaseLoaded
= true;
96 // All non IMS queries for package files fail.
97 if (Itm
->IndexFile
== true || GetID(Get
.Host
).empty() == true)
99 Fail("Please use apt-cdrom to make this CD recognized by APT."
100 " apt-get update cannot be used to add new CDs");
104 // We already have a CD inserted, but it is the wrong one
105 if (CurrentID
.empty() == false && Database
.Find("CD::" + CurrentID
) != Get
.Host
)
107 Fail("Wrong CD",true);
111 string CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
113 CDROM
= SafeGetCWD() + '/' + CDROM
;
117 if (IdentCdrom(CDROM
,NewID
) == false)
121 if (Database
.Find("CD::" + NewID
) == Get
.Host
)
124 // I suppose this should prompt somehow?
125 if (UnmountCdrom(CDROM
) == false)
126 return _error
->Error("Unable to unmount the CD-ROM in %s, it may still be in use.",
128 if (MediaFail(Get
.Host
,CDROM
) == false)
131 Fail("Wrong CD",true);
139 Res
.Filename
= CDROM
+ File
;
141 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
142 return _error
->Error("File not found");
145 Res
.LastModified
= Buf
.st_mtime
;
147 Res
.Size
= Buf
.st_size
;