]>
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 /*{{{*/
13 #include <apt-pkg/debsystem.h>
14 #include <apt-pkg/debversion.h>
15 #include <apt-pkg/debindexfile.h>
16 #include <apt-pkg/dpkgpm.h>
17 #include <apt-pkg/configuration.h>
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/fileutl.h>
22 #include <sys/types.h>
30 // System::debSystem - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
33 debSystem::debSystem()
39 Label
= "Debian dpkg interface";
43 // System::~debSystem - Destructor /*{{{*/
44 // ---------------------------------------------------------------------
46 debSystem::~debSystem()
51 // System::Lock - Get the lock /*{{{*/
52 // ---------------------------------------------------------------------
53 /* This mirrors the operations dpkg does when it starts up. Note the
54 checking of the updates directory. */
55 bool debSystem::Lock()
57 // Disable file locking
58 if (_config
->FindB("Debug::NoLocking",false) == true || LockCount
> 1)
64 // Create the lockfile
65 string AdminDir
= flNotFile(_config
->Find("Dir::State::status"));
66 LockFD
= GetLock(AdminDir
+ "lock");
69 if (errno
== EACCES
|| errno
== EAGAIN
)
70 return _error
->Error(_("Unable to lock the administration directory (%s), "
71 "is another process using it?"),AdminDir
.c_str());
73 return _error
->Error(_("Unable to lock the administration directory (%s), "
74 "are you root?"),AdminDir
.c_str());
77 // See if we need to abort with a dirty journal
78 if (CheckUpdates() == true)
82 return _error
->Error(_("dpkg was interrupted, you must manually "
83 "run 'dpkg --configure -a' to correct the problem. "));
91 // System::UnLock - Drop a lock /*{{{*/
92 // ---------------------------------------------------------------------
94 bool debSystem::UnLock(bool NoErrors
)
96 if (LockCount
== 0 && NoErrors
== true)
100 return _error
->Error(_("Not locked"));
101 if (--LockCount
== 0)
110 // System::CheckUpdates - Check if the updates dir is dirty /*{{{*/
111 // ---------------------------------------------------------------------
112 /* This does a check of the updates directory (dpkg journal) to see if it has
113 any entries in it. */
114 bool debSystem::CheckUpdates()
116 // Check for updates.. (dirty)
117 string File
= flNotFile(_config
->Find("Dir::State::status")) + "updates/";
118 DIR *DirP
= opendir(File
.c_str());
122 /* We ignore any files that are not all digits, this skips .,.. and
123 some tmp files dpkg will leave behind.. */
124 bool Damaged
= false;
125 for (struct dirent
*Ent
= readdir(DirP
); Ent
!= 0; Ent
= readdir(DirP
))
128 for (unsigned int I
= 0; Ent
->d_name
[I
] != 0; I
++)
130 // Check if its not a digit..
131 if (isdigit(Ent
->d_name
[I
]) == 0)
145 // System::CreatePM - Create the underlying package manager /*{{{*/
146 // ---------------------------------------------------------------------
148 pkgPackageManager
*debSystem::CreatePM(pkgDepCache
*Cache
) const
150 return new pkgDPkgPM(Cache
);
153 // System::Initialize - Setup the configuration space.. /*{{{*/
154 // ---------------------------------------------------------------------
155 /* These are the Debian specific configuration variables.. */
156 bool debSystem::Initialize(Configuration
&Cnf
)
158 /* These really should be jammed into a generic 'Local Database' engine
159 which is yet to be determined. The functions in pkgcachegen should
160 be the only users of these */
161 Cnf
.CndSet("Dir::State::userstatus","status.user"); // Defunct
162 Cnf
.CndSet("Dir::State::status","/var/lib/dpkg/status");
163 Cnf
.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
173 // System::ArchiveSupported - Is a file format supported /*{{{*/
174 // ---------------------------------------------------------------------
175 /* The standard name for a deb is 'deb'.. There are no seperate versions
176 of .deb to worry about.. */
177 bool debSystem::ArchiveSupported(const char *Type
)
179 if (strcmp(Type
,"deb") == 0)
184 // System::Score - Determine how 'Debiany' this sys is.. /*{{{*/
185 // ---------------------------------------------------------------------
186 /* We check some files that are sure tell signs of this being a Debian
188 signed debSystem::Score(Configuration
const &Cnf
)
191 if (FileExists(Cnf
.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
193 if (FileExists(Cnf
.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
195 if (FileExists("/etc/debian_version") == true)
200 // System::AddStatusFiles - Register the status files /*{{{*/
201 // ---------------------------------------------------------------------
203 bool debSystem::AddStatusFiles(vector
<pkgIndexFile
*> &List
)
206 StatusFile
= new debStatusIndex(_config
->FindFile("Dir::State::status"));
207 List
.push_back(StatusFile
);
211 // System::FindIndex - Get an index file for status files /*{{{*/
212 // ---------------------------------------------------------------------
214 bool debSystem::FindIndex(pkgCache::PkgFileIterator File
,
215 pkgIndexFile
*&Found
) const
219 if (StatusFile
->FindInCache(*File
.Cache()) == File
)