]>
git.saurik.com Git - apt.git/blob - methods/cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cdrom.cc,v 1.8 1999/03/28 01:37:26 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 - Get the ID hash for /*{{{*/
44 // ---------------------------------------------------------------------
45 /* We search the configuration space for the name and then return the ID
46 tag associated with it. */
47 string
CDROMMethod::GetID(string Name
)
49 if (DatabaseLoaded
== false)
52 string DFile
= _config
->FindFile("Dir::State::cdroms");
53 if (FileExists(DFile
) == true)
55 if (ReadConfigFile(Database
,DFile
) == false)
57 _error
->Error("Unable to read the cdrom database %s",
62 DatabaseLoaded
= true;
65 const Configuration::Item
*Top
= Database
.Tree("CD");
71 if (Top
->Value
== Name
)
80 // CDROMMethod::Fetch - Fetch a file /*{{{*/
81 // ---------------------------------------------------------------------
83 bool CDROMMethod::Fetch(FetchItem
*Itm
)
86 string File
= Get
.Path
;
89 /* All IMS queries are returned as a hit, CDROMs are readonly so
90 time stamps never change */
91 if (Itm
->LastModified
!= 0)
93 Res
.LastModified
= Itm
->LastModified
;
99 string ID
= GetID(Get
.Host
);
100 if (_error
->PendingError() == true)
103 // All non IMS queries for package files fail.
104 if (Itm
->IndexFile
== true || ID
.empty() == true)
106 Fail("Please use apt-cdrom to make this CD recognized by APT."
107 " apt-get update cannot be used to add new CDs");
111 // We already have a CD inserted, but it is the wrong one
112 if (CurrentID
.empty() == false && ID
!= CurrentID
)
114 Fail("Wrong CD",true);
118 string CDROM
= _config
->FindDir("Acquire::cdrom::mount","/cdrom/");
120 CDROM
= SafeGetCWD() + '/' + CDROM
;
124 if (IdentCdrom(CDROM
,NewID
) == false)
131 // I suppose this should prompt somehow?
132 if (UnmountCdrom(CDROM
) == false)
133 return _error
->Error("Unable to unmount the CD-ROM in %s, it may still be in use.",
135 if (MediaFail(Get
.Host
,CDROM
) == false)
138 Fail("Wrong CD",true);
148 Res
.Filename
= CDROM
+ File
;
150 if (stat(Res
.Filename
.c_str(),&Buf
) != 0)
151 return _error
->Error("File not found");
154 Res
.LastModified
= Buf
.st_mtime
;
156 Res
.Size
= Buf
.st_size
;
161 return _error
->Error("CDROM not found");