This file is indexed.

/usr/include/ept/apt/apt.h is in libept-dev 1.1+nmu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// -*- C++ -*-
#ifndef EPT_APT_APT_H
#define EPT_APT_APT_H

/** \file
 * High-level front-end to libapt-pkg, as a data provider for the ept framework.
 */

/*
 * Copyright (C) 2007,2008  Enrico Zini <enrico@enricozini.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */

#include <ept/apt/version.h>
#include <iterator>
#include <stdexcept>

class pkgCache;

namespace ept {
namespace apt {

class Exception : public std::runtime_error
{
public:
    Exception(const std::string& message);
    ~Exception() noexcept override;
};

class Apt;
class AptImplementation;
class RecordIteratorImpl;

struct PackageState {
    enum Query {
        Install = 1 << 0,
        Upgrade = 1 << 1,
        Keep = 1 << 2,
        Remove = 1 << 3,
        Installed = 1 << 4,
        Upgradable = 1 << 5,
        NowBroken = 1 << 6,
        WillBreak = 1 << 7,
        ReInstall = 1 << 8,
        Purge = 1 << 9,
        Hold = 1 << 10,
        Valid = 1 << 11
    };

    typedef unsigned state;
    
    operator unsigned() { return m_state; };
    
    PackageState &operator=( unsigned i ) {
        m_state = i;
        return *this;
    }
    
    PackageState &operator|=( const PackageState &s ) {
        m_state |= s.m_state;
        return *this;
    }
    
    PackageState( unsigned a ) {
        m_state = a;
    }
    
    PackageState() : m_state( 0 ) {}

    // FIXME this probably needs to be used consistently in core and out of core
    bool isValid() const { return m_state & Valid; }
    // FIXME compatibility API for non-core apt
    bool isInstalled() const { return installed(); }

    bool install() const { return m_state & Install; }
    // reinstall() implies install()
    bool reinstall() const { return m_state & ReInstall; }
    bool remove() const { return m_state & Remove; }
    // purge() implies remove()
    bool purge() const { return m_state & Purge; }
    bool keep() const { return m_state & Keep; }
    bool willBreak() const { return m_state & WillBreak; }
    // upgrade() implies install()
    bool upgrade() const { return hasNewVersion() && install(); }
    // newInsstal() implies install()
    bool newInstall() const { return !installed() && install(); }
    bool hold() const { return m_state & Hold; }

    bool installed() const { return m_state & Installed; }
    bool hasNewVersion() const { return m_state & Upgradable; }
    bool upgradable() const { return hasNewVersion() && !hold(); }
    bool held() const { return hasNewVersion() && hold(); }
    bool nowBroken() const { return m_state & NowBroken; }

    bool modify() const { return install() || remove(); }
    
protected:
    unsigned m_state;
};

/**
 * High-level access to the Apt cache, as a data provider for the ept
 * framework.
 *
 * This class wraps the Apt cache and allows to query it in various ways.
 */
class Apt
{
protected:
	AptImplementation* impl;

public:
	// Iterate Packages in the Apt cache
	class Iterator : public std::iterator<std::input_iterator_tag, std::string, void, void, void>
	{
		void* cur;

	protected:
		// Construct a valid iterator
		Iterator(void* cur) : cur(cur) {}

		// Construct and end iterator
		Iterator() : cur(0) {}

	public:
		// Copy constructor
		Iterator(const Iterator&);
		~Iterator();
		std::string operator*();
		Iterator& operator++();
		Iterator& operator=(const Iterator&);
		bool operator==(const Iterator&) const;
		bool operator!=(const Iterator&) const;

		// FIXME: Iterator operator++(int); cannot be easily implemented
		// because of how Apt's pkgIterator works

		friend class Apt;
	};

	// Iterate Package records in the Apt cache
	class RecordIterator : public std::iterator<std::input_iterator_tag, std::string, void, void, void>
	{
		RecordIteratorImpl* impl;
		size_t pos;
		std::string cur;
		size_t cur_pos;

	protected:
		// Construct a valid iterator
		RecordIterator(RecordIteratorImpl* cur, size_t pos = 0);

		// Construct and end iterator
		RecordIterator() : impl(0), pos(0), cur_pos(0) {}

	public:
		// Copy constructor
		RecordIterator(const RecordIterator& r);

		~RecordIterator();
		std::string operator*();
		std::string* operator->();
		RecordIterator& operator++();
		RecordIterator& operator=(const RecordIterator& r);
		bool operator==(const RecordIterator&) const;
		bool operator!=(const RecordIterator&) const;

		// FIXME: Iterator operator++(int); cannot be easily implemented
		// because of how Apt's pkgIterator works

		friend class Apt;
	};

	typedef Iterator iterator;
	typedef RecordIterator record_iterator;

	/**
	 * Create the Apt data provider
	 */
	Apt();
	~Apt();


	iterator begin() const;
	iterator end() const;

	record_iterator recordBegin() const;
	record_iterator recordEnd() const;


	/// Return the number of packages in the archive
	size_t size() const;

	/**
	 * Validate a package name, returning trye if it exists in the APT database,
	 * or false if it does not.
	 */
	bool isValid(const std::string& pkg) const;

	/// Validate a package name, returning it if it exists in the APT database,
	/// or returning the empty string if it does not.
	std::string validate(const std::string& pkg) const
	{
		if (isValid(pkg))
			return pkg;
		return std::string();
	}

	/// Validate a Version, returning it if it exists in the APT database, or
	/// returning the invalid version if it does not.
	Version validate(const Version& ver) const;

	/// Return the installed version for a package
	Version installedVersion(const std::string& pkg) const;

	/// Return the candidate version for a package
	Version candidateVersion(const std::string& pkg) const;

	/**
	 * Return the candidate version for a package, if available, or the
	 * installed version otherwise
	 */
	Version anyVersion(const std::string& pkg) const;

	/// Return state information on a package
	PackageState state(const std::string& pkg) const;

	/**
	 * Perform a package search.
	 *
	 * All packages for which the functor filter returns true, are passed to
	 * the functor out.
	 */
	//template<typename FILTER, typename OUT>
	//void search(const FILTER& filter, OUT& out);

	/// Get the raw package record for the given Version
	std::string rawRecord(const std::string& pkg) const;

	/// Get the raw package record for the given Version
	std::string rawRecord(const Version& ver) const;

	/// Returns the pointer to the internal libapt pkgCache object used.
	const pkgCache* aptPkgCache() const;

	
	
	/// Timestamp of when the apt index was last modified
	time_t timestamp();

	/**
	 * Check if the cache has been changed by another process, and reopen it if
	 * that is the case.
	 *
	 * Note that this method can invalidate all existing iterators.
	 */
	void checkCacheUpdates();

	/**
	 * Invalidate the cache timestamp used to track cache updates.
	 *
	 * @warning Do not use this method: it is here only to support the test
	 * cases, and may disappear in any future version.
	 */
	void invalidateTimestamp();
};

}
}

// vim:set ts=4 sw=4:
#endif