]>
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)
82 if (getenv("SUDO_USER") != NULL
)
83 cmd
= "sudo dpkg --configure -a";
85 cmd
= "dpkg --configure -a";
86 // TRANSLATORS: the %s contains the recovery command, usually
87 // dpkg --configure -a
88 return _error
->Error(_("dpkg was interrupted, you must manually "
89 "run '%s' to correct the problem. "), cmd
);
97 // System::UnLock - Drop a lock /*{{{*/
98 // ---------------------------------------------------------------------
100 bool debSystem::UnLock(bool NoErrors
)
102 if (LockCount
== 0 && NoErrors
== true)
106 return _error
->Error(_("Not locked"));
107 if (--LockCount
== 0)
116 // System::CheckUpdates - Check if the updates dir is dirty /*{{{*/
117 // ---------------------------------------------------------------------
118 /* This does a check of the updates directory (dpkg journal) to see if it has
119 any entries in it. */
120 bool debSystem::CheckUpdates()
122 // Check for updates.. (dirty)
123 string File
= flNotFile(_config
->Find("Dir::State::status")) + "updates/";
124 DIR *DirP
= opendir(File
.c_str());
128 /* We ignore any files that are not all digits, this skips .,.. and
129 some tmp files dpkg will leave behind.. */
130 bool Damaged
= false;
131 for (struct dirent
*Ent
= readdir(DirP
); Ent
!= 0; Ent
= readdir(DirP
))
134 for (unsigned int I
= 0; Ent
->d_name
[I
] != 0; I
++)
136 // Check if its not a digit..
137 if (isdigit(Ent
->d_name
[I
]) == 0)
151 // System::CreatePM - Create the underlying package manager /*{{{*/
152 // ---------------------------------------------------------------------
154 pkgPackageManager
*debSystem::CreatePM(pkgDepCache
*Cache
) const
156 return new pkgDPkgPM(Cache
);
159 // System::Initialize - Setup the configuration space.. /*{{{*/
160 // ---------------------------------------------------------------------
161 /* These are the Debian specific configuration variables.. */
162 bool debSystem::Initialize(Configuration
&Cnf
)
164 /* These really should be jammed into a generic 'Local Database' engine
165 which is yet to be determined. The functions in pkgcachegen should
166 be the only users of these */
167 Cnf
.CndSet("Dir::State::extended_states", Cnf
.FindDir("Dir::State").append("extended_states"));
168 Cnf
.CndSet("Dir::State::status","/var/lib/dpkg/status");
169 Cnf
.CndSet("Dir::Bin::dpkg","/usr/bin/dpkg");
179 // System::ArchiveSupported - Is a file format supported /*{{{*/
180 // ---------------------------------------------------------------------
181 /* The standard name for a deb is 'deb'.. There are no seperate versions
182 of .deb to worry about.. */
183 bool debSystem::ArchiveSupported(const char *Type
)
185 if (strcmp(Type
,"deb") == 0)
190 // System::Score - Determine how 'Debiany' this sys is.. /*{{{*/
191 // ---------------------------------------------------------------------
192 /* We check some files that are sure tell signs of this being a Debian
194 signed debSystem::Score(Configuration
const &Cnf
)
197 if (FileExists(Cnf
.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
199 if (FileExists(Cnf
.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
201 if (FileExists("/etc/debian_version") == true)
206 // System::AddStatusFiles - Register the status files /*{{{*/
207 // ---------------------------------------------------------------------
209 bool debSystem::AddStatusFiles(vector
<pkgIndexFile
*> &List
)
212 StatusFile
= new debStatusIndex(_config
->FindFile("Dir::State::status"));
213 List
.push_back(StatusFile
);
217 // System::FindIndex - Get an index file for status files /*{{{*/
218 // ---------------------------------------------------------------------
220 bool debSystem::FindIndex(pkgCache::PkgFileIterator File
,
221 pkgIndexFile
*&Found
) const
225 if (StatusFile
->FindInCache(*File
.Cache()) == File
)