]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debsystem.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debsystem.cc,v 1.4 2004/01/26 17:01:53 mdz 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()
42 Label
= "Debian dpkg interface";
46 // System::~debSystem - Destructor /*{{{*/
47 // ---------------------------------------------------------------------
49 debSystem::~debSystem()
54 // System::Lock - Get the lock /*{{{*/
55 // ---------------------------------------------------------------------
56 /* This mirrors the operations dpkg does when it starts up. Note the
57 checking of the updates directory. */
58 bool debSystem::Lock()
60 // Disable file locking
61 if (_config
->FindB("Debug::NoLocking",false) == true || LockCount
> 1)
67 // Create the lockfile
68 string AdminDir
= flNotFile(_config
->Find("Dir::State::status"));
69 LockFD
= GetLock(AdminDir
+ "lock");
72 if (errno
== EACCES
|| errno
== EAGAIN
)
73 return _error
->Error("Unable to lock the administration directory (%s), "
74 "is another process using it?",AdminDir
.c_str());
76 return _error
->Error("Unable to lock the administration directory (%s), "
77 "are you root?",AdminDir
.c_str());
80 // See if we need to abort with a dirty journal
81 if (CheckUpdates() == true)
85 return _error
->Error("dpkg was interrupted, you must manually "
86 "run 'dpkg --configure -a' to correct the problem. ");
94 // System::UnLock - Drop a lock /*{{{*/
95 // ---------------------------------------------------------------------
97 bool debSystem::UnLock(bool NoErrors
)
99 if (LockCount
== 0 && NoErrors
== true)
103 return _error
->Error("Not locked");
104 if (--LockCount
== 0)
113 // System::CheckUpdates - Check if the updates dir is dirty /*{{{*/
114 // ---------------------------------------------------------------------
115 /* This does a check of the updates directory (dpkg journal) to see if it has
116 any entries in it. */
117 bool debSystem::CheckUpdates()
119 // Check for updates.. (dirty)
120 string File
= flNotFile(_config
->Find("Dir::State::status")) + "updates/";
121 DIR *DirP
= opendir(File
.c_str());
125 /* We ignore any files that are not all digits, this skips .,.. and
126 some tmp files dpkg will leave behind.. */
127 bool Damaged
= false;
128 for (struct dirent
*Ent
= readdir(DirP
); Ent
!= 0; Ent
= readdir(DirP
))
131 for (unsigned int I
= 0; Ent
->d_name
[I
] != 0; I
++)
133 // Check if its not a digit..
134 if (isdigit(Ent
->d_name
[I
]) == 0)
148 // System::CreatePM - Create the underlying package manager /*{{{*/
149 // ---------------------------------------------------------------------
151 pkgPackageManager
*debSystem::CreatePM(pkgDepCache
*Cache
) const
153 return new pkgDPkgPM(Cache
);
156 // System::Initialize - Setup the configuration space.. /*{{{*/
157 // ---------------------------------------------------------------------
158 /* These are the Debian specific configuration variables.. */
159 bool debSystem::Initialize(Configuration
&Cnf
)
161 /* These really should be jammed into a generic 'Local Database' engine
162 which is yet to be determined. The functions in pkgcachegen should
163 be the only users of these */
164 Cnf
.CndSet("Dir::State::userstatus","status.user"); // Defunct
165 Cnf
.CndSet("Dir::State::status","/var/lib/dpkg/status");
166 Cnf
.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
171 // System::ArchiveSupported - Is a file format supported /*{{{*/
172 // ---------------------------------------------------------------------
173 /* The standard name for a deb is 'deb'.. There are no seperate versions
174 of .deb to worry about.. */
175 bool debSystem::ArchiveSupported(const char *Type
)
177 if (strcmp(Type
,"deb") == 0)
182 // System::Score - Determine how 'Debiany' this sys is.. /*{{{*/
183 // ---------------------------------------------------------------------
184 /* We check some files that are sure tell signs of this being a Debian
186 signed debSystem::Score(Configuration
const &Cnf
)
189 if (FileExists(Cnf
.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
191 if (FileExists(Cnf
.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
193 if (FileExists("/etc/debian_version") == true)
198 // System::AddStatusFiles - Register the status files /*{{{*/
199 // ---------------------------------------------------------------------
201 bool debSystem::AddStatusFiles(vector
<pkgIndexFile
*> &List
)
204 StatusFile
= new debStatusIndex(_config
->FindFile("Dir::State::status"));
205 List
.push_back(StatusFile
);
209 // System::FindIndex - Get an index file for status files /*{{{*/
210 // ---------------------------------------------------------------------
212 bool debSystem::FindIndex(pkgCache::PkgFileIterator File
,
213 pkgIndexFile
*&Found
) const
217 if (StatusFile
->FindInCache(*File
.Cache()) == File
)