]>
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>
21 #include <sys/types.h>
29 // System::debSystem - Constructor /*{{{*/
30 // ---------------------------------------------------------------------
32 debSystem::debSystem()
38 Label
= "Debian dpkg interface";
42 // System::~debSystem - Destructor /*{{{*/
43 // ---------------------------------------------------------------------
45 debSystem::~debSystem()
50 // System::Lock - Get the lock /*{{{*/
51 // ---------------------------------------------------------------------
52 /* This mirrors the operations dpkg does when it starts up. Note the
53 checking of the updates directory. */
54 bool debSystem::Lock()
56 // Disable file locking
57 if (_config
->FindB("Debug::NoLocking",false) == true || LockCount
> 1)
63 // Create the lockfile
64 string AdminDir
= flNotFile(_config
->Find("Dir::State::status"));
65 LockFD
= GetLock(AdminDir
+ "lock");
68 if (errno
== EACCES
|| errno
== EAGAIN
)
69 return _error
->Error(_("Unable to lock the administration directory (%s), "
70 "is another process using it?"),AdminDir
.c_str());
72 return _error
->Error(_("Unable to lock the administration directory (%s), "
73 "are you root?"),AdminDir
.c_str());
76 // See if we need to abort with a dirty journal
77 if (CheckUpdates() == true)
81 return _error
->Error(_("dpkg was interrupted, you must manually "
82 "run 'sudo dpkg --configure -a' to correct the problem. "));
90 // System::UnLock - Drop a lock /*{{{*/
91 // ---------------------------------------------------------------------
93 bool debSystem::UnLock(bool NoErrors
)
95 if (LockCount
== 0 && NoErrors
== true)
99 return _error
->Error(_("Not locked"));
100 if (--LockCount
== 0)
109 // System::CheckUpdates - Check if the updates dir is dirty /*{{{*/
110 // ---------------------------------------------------------------------
111 /* This does a check of the updates directory (dpkg journal) to see if it has
112 any entries in it. */
113 bool debSystem::CheckUpdates()
115 // Check for updates.. (dirty)
116 string File
= flNotFile(_config
->Find("Dir::State::status")) + "updates/";
117 DIR *DirP
= opendir(File
.c_str());
121 /* We ignore any files that are not all digits, this skips .,.. and
122 some tmp files dpkg will leave behind.. */
123 bool Damaged
= false;
124 for (struct dirent
*Ent
= readdir(DirP
); Ent
!= 0; Ent
= readdir(DirP
))
127 for (unsigned int I
= 0; Ent
->d_name
[I
] != 0; I
++)
129 // Check if its not a digit..
130 if (isdigit(Ent
->d_name
[I
]) == 0)
144 // System::CreatePM - Create the underlying package manager /*{{{*/
145 // ---------------------------------------------------------------------
147 pkgPackageManager
*debSystem::CreatePM(pkgDepCache
*Cache
) const
149 return new pkgDPkgPM(Cache
);
152 // System::Initialize - Setup the configuration space.. /*{{{*/
153 // ---------------------------------------------------------------------
154 /* These are the Debian specific configuration variables.. */
155 bool debSystem::Initialize(Configuration
&Cnf
)
157 /* These really should be jammed into a generic 'Local Database' engine
158 which is yet to be determined. The functions in pkgcachegen should
159 be the only users of these */
160 Cnf
.CndSet("Dir::State::userstatus","status.user"); // Defunct
161 Cnf
.CndSet("Dir::State::status","/var/lib/dpkg/status");
162 Cnf
.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
172 // System::ArchiveSupported - Is a file format supported /*{{{*/
173 // ---------------------------------------------------------------------
174 /* The standard name for a deb is 'deb'.. There are no seperate versions
175 of .deb to worry about.. */
176 bool debSystem::ArchiveSupported(const char *Type
)
178 if (strcmp(Type
,"deb") == 0)
183 // System::Score - Determine how 'Debiany' this sys is.. /*{{{*/
184 // ---------------------------------------------------------------------
185 /* We check some files that are sure tell signs of this being a Debian
187 signed debSystem::Score(Configuration
const &Cnf
)
190 if (FileExists(Cnf
.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
192 if (FileExists(Cnf
.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
194 if (FileExists("/etc/debian_version") == true)
199 // System::AddStatusFiles - Register the status files /*{{{*/
200 // ---------------------------------------------------------------------
202 bool debSystem::AddStatusFiles(vector
<pkgIndexFile
*> &List
)
205 StatusFile
= new debStatusIndex(_config
->FindFile("Dir::State::status"));
206 List
.push_back(StatusFile
);
210 // System::FindIndex - Get an index file for status files /*{{{*/
211 // ---------------------------------------------------------------------
213 bool debSystem::FindIndex(pkgCache::PkgFileIterator File
,
214 pkgIndexFile
*&Found
) const
218 if (StatusFile
->FindInCache(*File
.Cache()) == File
)