From aac6a4526c5f29cfcdfbf77eca06bf4fd8944f62 Mon Sep 17 00:00:00 2001 From: DoumanAsh Date: Sat, 13 Jun 2015 08:46:52 +0300 Subject: [PATCH] 3_2_x mapping: [search engine] Remove python3 cache during updateNova() --- src/core/fs_utils.cpp | 21 +++++++++++++++++++++ src/core/fs_utils.h | 1 + src/searchengine/searchengine.cpp | 7 +++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/core/fs_utils.cpp b/src/core/fs_utils.cpp index 9cb37e963..11f94f67b 100644 --- a/src/core/fs_utils.cpp +++ b/src/core/fs_utils.cpp @@ -187,6 +187,27 @@ bool fsutils::forceRemove(const QString& file_path) { return f.remove(); } +/** +* Removes directory and its content recursively. +* +*/ +void fsutils::removeDirRecursive(const QString& dirName) { + QDir dir(dirName); + + if (!dir.exists()) return; + + Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | + QDir::System | + QDir::Hidden | + QDir::AllDirs | + QDir::Files, QDir::DirsFirst)) { + if (info.isDir()) removeDirRecursive(info.absoluteFilePath()); + else forceRemove(info.absoluteFilePath()); + } + + dir.rmdir(dirName); +} + /** * Returns the size of a file. * If the file is a folder, it will compute its size based on its content. diff --git a/src/core/fs_utils.h b/src/core/fs_utils.h index eeceec516..4e8b27cb9 100644 --- a/src/core/fs_utils.h +++ b/src/core/fs_utils.h @@ -57,6 +57,7 @@ namespace fsutils bool isValidTorrentFile(const QString& path); bool smartRemoveEmptyFolderTree(const QString& dir_path); bool forceRemove(const QString& file_path); + void removeDirRecursive(const QString& dirName); /* Ported from Qt4 to drop dependency on QtGui */ QString QDesktopServicesDataLocation(); diff --git a/src/searchengine/searchengine.cpp b/src/searchengine/searchengine.cpp index 4293a7d11..a9e24eaa5 100644 --- a/src/searchengine/searchengine.cpp +++ b/src/searchengine/searchengine.cpp @@ -335,6 +335,8 @@ void SearchEngine::updateNova() { if (!search_dir.exists("engines")) { search_dir.mkdir("engines"); } + fsutils::removeDirRecursive(search_dir.absoluteFilePath("__pycache__")); + QFile package_file2(search_dir.absolutePath() + "/engines/__init__.py"); package_file2.open(QIODevice::WriteOnly | QIODevice::Text); package_file2.close(); @@ -372,13 +374,14 @@ void SearchEngine::updateNova() { removePythonScriptIfExists(filePath); QFile::copy(":/"+nova_folder+"/fix_encoding.py", filePath); } - - if (nova_folder == "nova3") { + else if (nova_folder == "nova3") { filePath = search_dir.absoluteFilePath("sgmllib3.py"); removePythonScriptIfExists(filePath); QFile::copy(":/"+nova_folder+"/sgmllib3.py", filePath); } + QDir destDir(QDir(fsutils::searchEngineLocation()).absoluteFilePath("engines")); + fsutils::removeDirRecursive(destDir.absoluteFilePath("__pycache__")); QDir shipped_subDir(":/"+nova_folder+"/engines/"); QStringList files = shipped_subDir.entryList(); foreach (const QString &file, files) {