]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/dpkginit.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: dpkginit.cc,v 1.1 1998/11/23 07:03:10 jgg Exp $
4 /* ######################################################################
6 DPKG init - Initialize the dpkg stuff
8 ##################################################################### */
12 #pragma implementation "apt-pkg/dpkginit.h"
14 #include <apt-pkg/dpkginit.h>
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/configuration.h>
17 #include <apt-pkg/fileutl.h>
19 #include <sys/types.h>
24 // DpkgLock::pkgDpkgLock - Constructor /*{{{*/
25 // ---------------------------------------------------------------------
27 pkgDpkgLock::pkgDpkgLock()
33 // DpkgLock::~pkgDpkgLock - Destructor /*{{{*/
34 // ---------------------------------------------------------------------
36 pkgDpkgLock::~pkgDpkgLock()
41 // DpkgLock::GetLock - Get the lock /*{{{*/
42 // ---------------------------------------------------------------------
43 /* This mirrors the operations dpkg does when it starts up. Note the
44 checking of the updates directory. */
45 bool pkgDpkgLock::GetLock()
47 // Disable file locking
48 if (_config
->FindB("Debug::NoLocking",false) == true)
53 // Create the lockfile
54 string AdminDir
= flNotFile(_config
->Find("Dir::State::status"));
55 LockFD
= ::GetLock(AdminDir
+ "lock");
57 return _error
->Errno("Open","Unable to lock the administration directory "
58 "%s, are you root?",AdminDir
.c_str());
60 // Check for updates.. (dirty)
61 string File
= AdminDir
+ "updates/";
62 DIR *DirP
= opendir(File
.c_str());
65 /* We ignore any files that are not all digits, this skips .,.. and
66 some tmp files dpkg will leave behind.. */
68 for (struct dirent
*Ent
= readdir(DirP
); Ent
!= 0; Ent
= readdir(DirP
))
71 for (unsigned int I
= 0; Ent
->d_name
[I
] != 0; I
++)
73 // Check if its not a digit..
74 if (isdigit(Ent
->d_name
[I
]) == 0)
85 // Woops, we have to run dpkg to rewrite the status file
89 return _error
->Error("dpkg was interrupted, you must manually "
90 "run 'dpkg --configure -a' to correct the problem. ");
97 // DpkgLock::Close - Close the lock /*{{{*/
98 // ---------------------------------------------------------------------
100 void pkgDpkgLock::Close()