]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debsystem.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debsystem.cc,v 1.2 2001/02/20 07:03:17 jgg Exp $
4 /* ######################################################################
6 System - Abstraction for running on different systems.
8 Basic general structure..
10 ##################################################################### */
12 // Include Files /*{{{*/
14 #pragma implementation "apt-pkg/debsystem.h"
17 #include <apt-pkg/debsystem.h>
18 #include <apt-pkg/debversion.h>
19 #include <apt-pkg/debindexfile.h>
20 #include <apt-pkg/dpkgpm.h>
21 #include <apt-pkg/configuration.h>
22 #include <apt-pkg/error.h>
23 #include <apt-pkg/fileutl.h>
25 #include <sys/types.h>
33 // System::debSystem - Constructor /*{{{*/
34 // ---------------------------------------------------------------------
36 debSystem::debSystem()
41 Label
= "Debian dpkg interface";
45 // System::Lock - Get the lock /*{{{*/
46 // ---------------------------------------------------------------------
47 /* This mirrors the operations dpkg does when it starts up. Note the
48 checking of the updates directory. */
49 bool debSystem::Lock()
51 // Disable file locking
52 if (_config
->FindB("Debug::NoLocking",false) == true || LockCount
> 1)
58 // Create the lockfile
59 string AdminDir
= flNotFile(_config
->Find("Dir::State::status"));
60 LockFD
= GetLock(AdminDir
+ "lock");
63 if (errno
== EACCES
|| errno
== EAGAIN
)
64 return _error
->Error("Unable to lock the administration directory (%s), "
65 "is another process using it?",AdminDir
.c_str());
67 return _error
->Error("Unable to lock the administration directory (%s), "
68 "are you root?",AdminDir
.c_str());
71 // See if we need to abort with a dirty journal
72 if (CheckUpdates() == true)
76 return _error
->Error("dpkg was interrupted, you must manually "
77 "run 'dpkg --configure -a' to correct the problem. ");
85 // System::UnLock - Drop a lock /*{{{*/
86 // ---------------------------------------------------------------------
88 bool debSystem::UnLock(bool NoErrors
)
90 if (LockCount
== 0 && NoErrors
== true)
94 return _error
->Error("Not locked");
104 // System::CheckUpdates - Check if the updates dir is dirty /*{{{*/
105 // ---------------------------------------------------------------------
106 /* This does a check of the updates directory (dpkg journal) to see if it has
107 any entries in it. */
108 bool debSystem::CheckUpdates()
110 // Check for updates.. (dirty)
111 string File
= flNotFile(_config
->Find("Dir::State::status")) + "updates/";
112 DIR *DirP
= opendir(File
.c_str());
116 /* We ignore any files that are not all digits, this skips .,.. and
117 some tmp files dpkg will leave behind.. */
118 bool Damaged
= false;
119 for (struct dirent
*Ent
= readdir(DirP
); Ent
!= 0; Ent
= readdir(DirP
))
122 for (unsigned int I
= 0; Ent
->d_name
[I
] != 0; I
++)
124 // Check if its not a digit..
125 if (isdigit(Ent
->d_name
[I
]) == 0)
139 // System::CreatePM - Create the underlying package manager /*{{{*/
140 // ---------------------------------------------------------------------
142 pkgPackageManager
*debSystem::CreatePM(pkgDepCache
*Cache
) const
144 return new pkgDPkgPM(Cache
);
147 // System::Initialize - Setup the configuration space.. /*{{{*/
148 // ---------------------------------------------------------------------
149 /* These are the Debian specific configuration variables.. */
150 bool debSystem::Initialize(Configuration
&Cnf
)
152 /* These really should be jammed into a generic 'Local Database' engine
153 which is yet to be determined. The functions in pkgcachegen should
154 be the only users of these */
155 Cnf
.CndSet("Dir::State::userstatus","status.user"); // Defunct
156 Cnf
.CndSet("Dir::State::status","/var/lib/dpkg/status");
157 Cnf
.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
162 // System::ArchiveSupported - Is a file format supported /*{{{*/
163 // ---------------------------------------------------------------------
164 /* The standard name for a deb is 'deb'.. There are no seperate versions
165 of .deb to worry about.. */
166 bool debSystem::ArchiveSupported(const char *Type
)
168 if (strcmp(Type
,"deb") == 0)
173 // System::Score - Determine how 'Debiany' this sys is.. /*{{{*/
174 // ---------------------------------------------------------------------
175 /* We check some files that are sure tell signs of this being a Debian
177 signed debSystem::Score(Configuration
const &Cnf
)
180 if (FileExists(Cnf
.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
182 if (FileExists(Cnf
.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
184 if (FileExists("/etc/debian_version") == true)
189 // System::AddStatusFiles - Register the status files /*{{{*/
190 // ---------------------------------------------------------------------
192 bool debSystem::AddStatusFiles(vector
<pkgIndexFile
*> &List
)
194 List
.push_back(new debStatusIndex(_config
->FindFile("Dir::State::status")));