]>
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");
176 // System::ArchiveSupported - Is a file format supported /*{{{*/
177 // ---------------------------------------------------------------------
178 /* The standard name for a deb is 'deb'.. There are no seperate versions
179 of .deb to worry about.. */
180 bool debSystem::ArchiveSupported(const char *Type
)
182 if (strcmp(Type
,"deb") == 0)
187 // System::Score - Determine how 'Debiany' this sys is.. /*{{{*/
188 // ---------------------------------------------------------------------
189 /* We check some files that are sure tell signs of this being a Debian
191 signed debSystem::Score(Configuration
const &Cnf
)
194 if (FileExists(Cnf
.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
196 if (FileExists(Cnf
.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
198 if (FileExists("/etc/debian_version") == true)
203 // System::AddStatusFiles - Register the status files /*{{{*/
204 // ---------------------------------------------------------------------
206 bool debSystem::AddStatusFiles(vector
<pkgIndexFile
*> &List
)
209 StatusFile
= new debStatusIndex(_config
->FindFile("Dir::State::status"));
210 List
.push_back(StatusFile
);
214 // System::FindIndex - Get an index file for status files /*{{{*/
215 // ---------------------------------------------------------------------
217 bool debSystem::FindIndex(pkgCache::PkgFileIterator File
,
218 pkgIndexFile
*&Found
) const
222 if (StatusFile
->FindInCache(*File
.Cache()) == File
)