]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/dpkginit.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: dpkginit.cc,v 1.3 1999/07/26 17:46:08 jgg Exp $
4 /* ######################################################################
6 DPKG init - Initialize the dpkg stuff
8 This class provides the locking mechanism used by dpkg for its
9 database area. It does the proper consistency checks and acquires the
12 ##################################################################### */
16 #pragma implementation "apt-pkg/dpkginit.h"
18 #include <apt-pkg/dpkginit.h>
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/configuration.h>
21 #include <apt-pkg/fileutl.h>
23 #include <sys/types.h>
28 // DpkgLock::pkgDpkgLock - Constructor /*{{{*/
29 // ---------------------------------------------------------------------
31 pkgDpkgLock::pkgDpkgLock(bool WithUpdates
)
37 // DpkgLock::~pkgDpkgLock - Destructor /*{{{*/
38 // ---------------------------------------------------------------------
40 pkgDpkgLock::~pkgDpkgLock()
45 // DpkgLock::GetLock - Get the lock /*{{{*/
46 // ---------------------------------------------------------------------
47 /* This mirrors the operations dpkg does when it starts up. Note the
48 checking of the updates directory. */
49 bool pkgDpkgLock::GetLock(bool WithUpdates
)
51 // Disable file locking
52 if (_config
->FindB("Debug::NoLocking",false) == true)
57 // Create the lockfile
58 string AdminDir
= flNotFile(_config
->Find("Dir::State::status"));
59 LockFD
= ::GetLock(AdminDir
+ "lock");
61 return _error
->Error("Unable to lock the administration directory, "
64 // See if we need to abort with a dirty journal
65 if (WithUpdates
== true && CheckUpdates() == false)
68 return _error
->Error("dpkg was interrupted, you must manually "
69 "run 'dpkg --configure -a' to correct the problem. ");
75 // DpkgLock::Close - Close the lock /*{{{*/
76 // ---------------------------------------------------------------------
78 void pkgDpkgLock::Close()
84 // DpkgLock::CheckUpdates - Check if the updates dir is dirty /*{{{*/
85 // ---------------------------------------------------------------------
86 /* This does a check of the updates directory to see if it has any entries
88 bool pkgDpkgLock::CheckUpdates()
90 // Check for updates.. (dirty)
91 string File
= flNotFile(_config
->Find("Dir::State::status")) + "updates/";
92 DIR *DirP
= opendir(File
.c_str());
96 /* We ignore any files that are not all digits, this skips .,.. and
97 some tmp files dpkg will leave behind.. */
99 for (struct dirent
*Ent
= readdir(DirP
); Ent
!= 0; Ent
= readdir(DirP
))
102 for (unsigned int I
= 0; Ent
->d_name
[I
] != 0; I
++)
104 // Check if its not a digit..
105 if (isdigit(Ent
->d_name
[I
]) == 0)