~ubuntu-branches/ubuntu/warty/synaptic/warty

« back to all changes in this revision

Viewing changes to common/rpackagecache.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2002-04-04 12:23:30 UTC
  • Revision ID: james.westby@ubuntu.com-20020404122330-il87fkpjajirckb2
Tags: upstream-0.16
ImportĀ upstreamĀ versionĀ 0.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* rpackagecache.cc - package cache wrapper
 
2
 * 
 
3
 * Copyright (c) 2000, 2001 Conectiva S/A 
 
4
 * 
 
5
 * Author: Alfredo K. Kojima <kojima@conectiva.com.br>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or 
 
8
 * modify it under the terms of the GNU General Public License as 
 
9
 * published by the Free Software Foundation; either version 2 of the
 
10
 * License, or (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
20
 * USA
 
21
 */
 
22
 
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include "rpackagecache.h"
 
27
 
 
28
#include "i18n.h"
 
29
 
 
30
#include <apt-pkg/error.h>
 
31
#include <apt-pkg/sourcelist.h>
 
32
#include <apt-pkg/pkgcachegen.h>
 
33
#include <apt-pkg/configuration.h>
 
34
#ifdef HAVE_RPM
 
35
# include <apt-pkg/systemfactory.h>
 
36
#else
 
37
# include <apt-pkg/pkgsystem.h>
 
38
# include <apt-pkg/policy.h>
 
39
#endif
 
40
 
 
41
 
 
42
 
 
43
bool RPackageCache::open(OpProgress &progress)
 
44
{
 
45
#ifdef HAVE_RPM
 
46
    _lock = new pkgRpmLock(true);
 
47
#else
 
48
    _system->Lock();
 
49
#endif
 
50
 
 
51
    if (_error->PendingError())
 
52
        return false;
 
53
    
 
54
    // Read the source list
 
55
    pkgSourceList list;
 
56
    if (!list.ReadMainList())
 
57
       return _error->Error(_("The list of sources could not be read."));
 
58
    
 
59
#ifdef HAVE_RPM
 
60
    _system->makeStatusCache(list, progress);
 
61
    progress.Done();
 
62
#else
 
63
    pkgMakeStatusCache(list, progress);
 
64
#endif
 
65
 
 
66
    if (_error->PendingError())
 
67
        return _error->Error(_("The package lists or status file could not be parsed or opened."));
 
68
 
 
69
    // Open the cache file
 
70
    FileFd File(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
 
71
    if (_error->PendingError())
 
72
        return false;
 
73
 
 
74
    _map = new MMap(File,MMap::Public | MMap::ReadOnly);
 
75
    if (_error->PendingError())
 
76
        return false;
 
77
    
 
78
    // Create the dependency cache
 
79
#ifdef HAVE_RPM
 
80
    _dcache = new pkgDepCache(*_map, progress);
 
81
#else
 
82
    _cache = new pkgCache(_map);
 
83
    if (_error->PendingError())
 
84
       return false;
 
85
    
 
86
    // The policy engine
 
87
    _policy = new pkgPolicy(_cache);
 
88
    if (_error->PendingError() == true)
 
89
       return false;
 
90
    if (ReadPinFile(*_policy) == false)
 
91
       return false;
 
92
    
 
93
    _dcache = new pkgDepCache(_cache, _policy);
 
94
    
 
95
    _dcache->Init(&progress);
 
96
#endif
 
97
 
 
98
    progress.Done();
 
99
    if (_error->PendingError())
 
100
        return false;
 
101
 
 
102
    // Check that the system is OK
 
103
    if (_dcache->DelCount() != 0 || _dcache->InstCount() != 0)
 
104
        return _error->Error("Internal Error, non-zero counts");
 
105
 
 
106
    _locked = true;
 
107
 
 
108
    return true;
 
109
}
 
110
 
 
111
 
 
112
 
 
113
bool RPackageCache::reset(OpProgress &progress)
 
114
{
 
115
    delete _dcache;
 
116
    delete _map;
 
117
 
 
118
    releaseLock();
 
119
 
 
120
#ifdef HAVE_RPM
 
121
    if (_lock) {
 
122
        delete _lock;
 
123
        _lock = 0;
 
124
    }
 
125
#endif
 
126
    return open(progress);
 
127
}
 
128
 
 
129
 
 
130
 
 
131
bool RPackageCache::lock()
 
132
{
 
133
    if (_locked)
 
134
       return true;
 
135
 
 
136
#ifdef HAVE_RPM
 
137
    if (_lock) {
 
138
        _lock->GetLock(true);
 
139
    }
 
140
#else    
 
141
    _system->Lock();
 
142
#endif
 
143
    _locked = true;
 
144
}
 
145
 
 
146
 
 
147
void RPackageCache::releaseLock()
 
148
{
 
149
    if (!_locked)
 
150
        return;
 
151
 
 
152
#ifdef HAVE_RPM
 
153
    if (_lock) {
 
154
        _lock->Close();
 
155
    }
 
156
#else    
 
157
    _system->UnLock();
 
158
#endif
 
159
    _locked = false;
 
160
}