This file is indexed.

/usr/include/libktorrent/diskio/cache.h is in libktorrent-dev 1.3.1-5.

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
/***************************************************************************
 *   Copyright (C) 2005 by Joris Guisson                                   *
 *   joris.guisson@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#ifndef BTCACHE_H
#define BTCACHE_H

#include <ktorrent_export.h>
#include <util/constants.h>
#include <torrent/torrent.h>
#include <diskio/piecedata.h>
#include <QString>
#include <QMultiMap>
#include <QSet>


class QStringList;

namespace bt
{
	class TorrentFile;
	class Chunk;
	class PreallocationThread;
	class TorrentFileInterface;
	class Job;

	/**
	 * @author Joris Guisson
	 * @brief Manages the temporary data
	 *
	 * Interface for a class which manages downloaded data.
	 * Subclasses should implement the load and save methods.
	 */
	class KTORRENT_EXPORT Cache
	{
	public:
		Cache(Torrent & tor,const QString & tmpdir,const QString & datadir);
		virtual ~Cache();

		/**
		 * Load the file map of a torrent.
		 * If it doesn't exist, it needs to be created.
		 */
		virtual void loadFileMap() = 0;
		
		/**
		 * Save the file map of a torrent
		 */
		virtual void saveFileMap() = 0;
		
		/// Get the datadir
		QString getDataDir() const {return datadir;}
		
		/**
		 * Get the actual output path.
		 * @return The output path
		 */
		virtual QString getOutputPath() const = 0;
		
		/**
		 * Changes the tmp dir. All data files should already been moved.
		 * This just modifies the tmpdir variable.
		 * @param ndir The new tmpdir
		 */
		virtual void changeTmpDir(const QString & ndir);
		
		/**
		 * Changes output path. All data files should already been moved.
		 * This just modifies the datadir variable.
		 * @param outputpath New output path
		 */
		virtual void changeOutputPath(const QString & outputpath) = 0;
		
		/**
		 * Move the data files to a new directory.
		 * @param ndir The directory
		 * @return The job doing the move
		 */
		virtual Job* moveDataFiles(const QString & ndir) = 0;
		
		/**
		 * A move of a bunch of data files has finished
		 * @param job The job doing the move
		 */
		virtual void moveDataFilesFinished(Job* job) = 0;
		
		/**
		 * Load a piece into memory. If something goes wrong,
		 * an Error should be thrown.
		 * @param c The Chunk
		 * @param off The offset of the piece
		 * @param length The length of the piece
		 * @return Pointer to the data
		 */
		virtual PieceData::Ptr loadPiece(Chunk* c,Uint32 off,Uint32 length) = 0;
		
		/**
		 * Prepare a piece for writing. If something goes wrong,
		 * an Error should be thrown.
		 * @param c The Chunk
		 * @param off The offset of the piece
		 * @param length The length of the piece
		 * @return Pointer to the data
		 */
		virtual PieceData::Ptr preparePiece(Chunk* c,Uint32 off,Uint32 length) = 0;
		
		/**
		 * Save a piece to disk, will only actually save in buffered mode
		 * @param piece The piece
		 */
		virtual void savePiece(PieceData::Ptr piece) = 0;
		
		/**
		 * Create all the data files to store the data.
		 */
		virtual void create() = 0;
		
		/**
		 * Close the cache file(s).
		 */
		virtual void close() = 0;
		
		/**
		 * Open the cache file(s)
		 */
		virtual void open() = 0;
		
		/// Does nothing, can be overridden to be alerted of download status changes of a TorrentFile
		virtual void downloadStatusChanged(TorrentFile*, bool) {};
		
		/**
		 * Prepare disksapce preallocation
		 * @param prealloc The thread going to do the preallocation
		 */
		virtual void preparePreallocation(PreallocationThread* prealloc) = 0;
		
		/// See if the download has existing files
		bool hasExistingFiles() const {return preexisting_files;}
		
		/**
		 * Test all files and see if they are not missing.
		 * If so put them in a list
		 */
		virtual bool hasMissingFiles(QStringList & sl) = 0;

		/**
		 * Delete all data files, in case of multi file torrents
		 * empty directories should also be deleted.
		 * @return The job doing the delete
		 */
		virtual Job* deleteDataFiles() = 0;
		
		/**
		 * Move some files to a new location
		 * @param files Map of files to move and their new location
		 * @return Job The job doing the move
		 */
		virtual Job* moveDataFiles(const QMap<TorrentFileInterface*,QString> & files);
		
		/**
		 * The job doing moveDataFiles (with the map parameter) has finished
		 * @param files The files map with all the moves
		 * @param job The job doing the move
		 */
		virtual void moveDataFilesFinished(const QMap<TorrentFileInterface*,QString> & files,Job* job);
		
		/** 
		 * See if we are allowed to use mmap, when loading chunks.
		 * This will return false if we are close to system limits.
		 */
		static bool mappedModeAllowed();
		
		/**
		 * Get the number of bytes all the files of this torrent are currently using on disk.
		 * */
		virtual Uint64 diskUsage() = 0;
		
		/**
		 * Determine the mount points of all the files in this torrent
		 * @return bool True if we can, false if not
		 **/
		virtual bool getMountPoints(QSet<QString> & mps) = 0;
		
		/**
		 * Enable or disable diskspace preallocation
		 * @param on 
		 */
		static void setPreallocationEnabled(bool on) {preallocate_files = on;}
		
		/**
		 * Check if diskspace preallocation is enabled
		 * @return true if it is
		 */
		static bool preallocationEnabled() {return preallocate_files;}
		
		/**
		 * Enable or disable full diskspace preallocation 
		 * @param on 
		 */
		static void setPreallocateFully(bool on) {preallocate_fully = on;}
		
		/**
		 * Check if full diskspace preallocation is enabled.
		 * @return true if it is
		 */
		static bool preallocateFully() {return preallocate_fully;}
		
		/**
		 * Check memory usage and free all PieceData objects which are no longer needed.
		 */
		void checkMemoryUsage();

		/**
		 * Clear all pieces of a chunk
		 * @param c The chunk
		 * */
		void clearPieces(Chunk* c);
		
		/**
		 * Load the mount points of this torrent
		 **/
		void loadMountPoints();
		
		/// Is the storage mounted ?
		bool isStorageMounted(QStringList & missing);
		
	protected:
		PieceData::Ptr findPiece(Chunk* c,Uint32 off,Uint32 len,bool read_only);
		void insertPiece(Chunk* c,PieceData::Ptr p);
		void clearPieceCache();
		void cleanupPieceCache();
		void saveMountPoints(const QSet<QString> & mp);
		
	protected:
		Torrent & tor;
		QString tmpdir;
		QString datadir;
		bool preexisting_files;
		Uint32 mmap_failures;
		
		typedef QMultiMap<Chunk*,PieceData::Ptr> PieceCache;
		PieceCache piece_cache;
		
		QSet<QString> mount_points;
	private:
		static bool preallocate_files;
		static bool preallocate_fully;
	};

}

#endif