Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/backgroundparser/parsejob.cpp
Show All 19 Lines | |||||
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "parsejob.h" | 23 | #include "parsejob.h" | ||
24 | 24 | | |||
25 | #include <QFile> | 25 | #include <QFile> | ||
26 | #include <QMutex> | 26 | #include <QMutex> | ||
27 | #include <QMutexLocker> | 27 | #include <QMutexLocker> | ||
28 | #include <QStandardPaths> | ||||
28 | 29 | | |||
29 | #include <KLocalizedString> | 30 | #include <KLocalizedString> | ||
30 | #include <KFormat> | 31 | #include <KFormat> | ||
31 | #include <ktexteditor/movinginterface.h> | 32 | #include <ktexteditor/movinginterface.h> | ||
32 | 33 | | |||
33 | #include "backgroundparser.h" | 34 | #include "backgroundparser.h" | ||
34 | #include <debug.h> | 35 | #include <debug.h> | ||
35 | #include "duchain/topducontext.h" | 36 | #include "duchain/topducontext.h" | ||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Line(s) | 255 | { | |||
265 | hadTracker = true; | 266 | hadTracker = true; | ||
266 | } | 267 | } | ||
267 | } | 268 | } | ||
268 | if (!hadTracker) { | 269 | if (!hadTracker) { | ||
269 | // We have to load the file from disk | 270 | // We have to load the file from disk | ||
270 | 271 | | |||
271 | static const int maximumFileSize = 5 * 1024 * 1024; // 5 MB | 272 | static const int maximumFileSize = 5 * 1024 * 1024; // 5 MB | ||
272 | if (fileInfo.size() > maximumFileSize) { | 273 | if (fileInfo.size() > maximumFileSize) { | ||
274 | QStringList paths = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::GenericDataLocation); | ||||
275 | | ||||
276 | bool internalFile = false; | ||||
277 | | ||||
278 | foreach (const QString path, paths) { | ||||
279 | if (fileInfo.absolutePath().startsWith(path + QStringLiteral("/kdev"))) { | ||||
brauch: I think you need to compare two canonical paths here, not this. This will break if there are… | |||||
280 | qCInfo(LANGUAGE) << "Found internal file " << fileInfo.absoluteFilePath() << " in " << path << ". Ignoring file size limit!"; | ||||
281 | internalFile = true; | ||||
282 | break; | ||||
283 | } | ||||
284 | } | ||||
285 | | ||||
286 | if (!internalFile) { | ||||
273 | KFormat f; | 287 | KFormat f; | ||
274 | 288 | | |||
275 | KDevelop::ProblemPointer p(new Problem()); | 289 | KDevelop::ProblemPointer p(new Problem()); | ||
276 | p->setSource(IProblem::Disk); | 290 | p->setSource(IProblem::Disk); | ||
277 | p->setDescription(i18nc("%1: filename", "Skipped file that is too large: '%1'", localFile )); | 291 | p->setDescription(i18nc("%1: filename", "Skipped file that is too large: '%1'", localFile )); | ||
278 | p->setExplanation(i18nc("%1: file size, %2: limit file size", | 292 | p->setExplanation(i18nc("%1: file size, %2: limit file size", | ||
279 | "The file is %1 and exceeds the limit of %2.", | 293 | "The file is %1 and exceeds the limit of %2.", | ||
280 | f.formatByteSize(fileInfo.size()), | 294 | f.formatByteSize(fileInfo.size()), | ||
281 | f.formatByteSize(maximumFileSize))); | 295 | f.formatByteSize(maximumFileSize))); | ||
282 | p->setFinalLocation(DocumentRange(document(), KTextEditor::Range::invalid())); | 296 | p->setFinalLocation(DocumentRange(document(), KTextEditor::Range::invalid())); | ||
283 | qCWarning(LANGUAGE) << p->description() << p->explanation(); | 297 | qCWarning(LANGUAGE) << p->description() << p->explanation(); | ||
284 | return p; | 298 | return p; | ||
285 | } | 299 | } | ||
300 | } | ||||
286 | QFile file( localFile ); | 301 | QFile file( localFile ); | ||
287 | 302 | | |||
288 | if ( !file.open( QIODevice::ReadOnly ) ) | 303 | if ( !file.open( QIODevice::ReadOnly ) ) | ||
289 | { | 304 | { | ||
290 | KDevelop::ProblemPointer p(new Problem()); | 305 | KDevelop::ProblemPointer p(new Problem()); | ||
291 | p->setSource(IProblem::Disk); | 306 | p->setSource(IProblem::Disk); | ||
292 | p->setDescription(i18n( "Could not open file '%1'", localFile )); | 307 | p->setDescription(i18n( "Could not open file '%1'", localFile )); | ||
293 | switch (file.error()) { | 308 | switch (file.error()) { | ||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |
I think you need to compare two canonical paths here, not this. This will break if there are symlinks in the path(s), or something changes about leading or trailing slashes, or e.g. when the user configures his XDG_DATA_DIRS with ../ segments in it or whatever ...