]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debsystem.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debsystem.cc,v 1.3 2001/04/29 05:13:51 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::~debSystem - Destructor /*{{{*/
46 // ---------------------------------------------------------------------
48 debSystem::~debSystem()
53 // System::Lock - Get the lock /*{{{*/
54 // ---------------------------------------------------------------------
55 /* This mirrors the operations dpkg does when it starts up. Note the
56 checking of the updates directory. */
57 bool debSystem::Lock()
59 // Disable file locking
60 if (_config
->FindB("Debug::NoLocking",false) == true || LockCount
> 1)
66 // Create the lockfile
67 string AdminDir
= flNotFile(_config
->Find("Dir::State::status"));
68 LockFD
= GetLock(AdminDir
+ "lock");
71 if (errno
== EACCES
|| errno
== EAGAIN
)
72 return _error
->Error("Unable to lock the administration directory (%s), "
73 "is another process using it?",AdminDir
.c_str());
75 return _error
->Error("Unable to lock the administration directory (%s), "
76 "are you root?",AdminDir
.c_str());
79 // See if we need to abort with a dirty journal
80 if (CheckUpdates() == true)
84 return _error
->Error("dpkg was interrupted, you must manually "
85 "run 'dpkg --configure -a' to correct the problem. ");
93 // System::UnLock - Drop a lock /*{{{*/
94 // ---------------------------------------------------------------------
96 bool debSystem::UnLock(bool NoErrors
)
98 if (LockCount
== 0 && NoErrors
== true)
102 return _error
->Error("Not locked");
103 if (--LockCount
== 0)
112 // System::CheckUpdates - Check if the updates dir is dirty /*{{{*/
113 // ---------------------------------------------------------------------
114 /* This does a check of the updates directory (dpkg journal) to see if it has
115 any entries in it. */
116 bool debSystem::CheckUpdates()
118 // Check for updates.. (dirty)
119 string File
= flNotFile(_config
->Find("Dir::State::status")) + "updates/";
120 DIR *DirP
= opendir(File
.c_str());
124 /* We ignore any files that are not all digits, this skips .,.. and
125 some tmp files dpkg will leave behind.. */
126 bool Damaged
= false;
127 for (struct dirent
*Ent
= readdir(DirP
); Ent
!= 0; Ent
= readdir(DirP
))
130 for (unsigned int I
= 0; Ent
->d_name
[I
] != 0; I
++)
132 // Check if its not a digit..
133 if (isdigit(Ent
->d_name
[I
]) == 0)
147 // System::CreatePM - Create the underlying package manager /*{{{*/
148 // ---------------------------------------------------------------------
150 pkgPackageManager
*debSystem::CreatePM(pkgDepCache
*Cache
) const
152 return new pkgDPkgPM(Cache
);
155 // System::Initialize - Setup the configuration space.. /*{{{*/
156 // ---------------------------------------------------------------------
157 /* These are the Debian specific configuration variables.. */
158 bool debSystem::Initialize(Configuration
&Cnf
)
160 /* These really should be jammed into a generic 'Local Database' engine
161 which is yet to be determined. The functions in pkgcachegen should
162 be the only users of these */
163 Cnf
.CndSet("Dir::State::userstatus","status.user"); // Defunct
164 Cnf
.CndSet("Dir::State::status","/var/lib/dpkg/status");
165 Cnf
.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
170 // System::ArchiveSupported - Is a file format supported /*{{{*/
171 // ---------------------------------------------------------------------
172 /* The standard name for a deb is 'deb'.. There are no seperate versions
173 of .deb to worry about.. */
174 bool debSystem::ArchiveSupported(const char *Type
)
176 if (strcmp(Type
,"deb") == 0)
181 // System::Score - Determine how 'Debiany' this sys is.. /*{{{*/
182 // ---------------------------------------------------------------------
183 /* We check some files that are sure tell signs of this being a Debian
185 signed debSystem::Score(Configuration
const &Cnf
)
188 if (FileExists(Cnf
.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
190 if (FileExists(Cnf
.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
192 if (FileExists("/etc/debian_version") == true)
197 // System::AddStatusFiles - Register the status files /*{{{*/
198 // ---------------------------------------------------------------------
200 bool debSystem::AddStatusFiles(vector
<pkgIndexFile
*> &List
)
203 StatusFile
= new debStatusIndex(_config
->FindFile("Dir::State::status"));
204 List
.push_back(StatusFile
);
208 // System::FindIndex - Get an index file for status files /*{{{*/
209 // ---------------------------------------------------------------------
211 bool debSystem::FindIndex(pkgCache::PkgFileIterator File
,
212 pkgIndexFile
*&Found
) const
216 if (StatusFile
->FindInCache(*File
.Cache()) == File
)