mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00:00
Clear python cache conditionally
Clear the cache artifacts on plugin install and plugin uninstall events.
This commit is contained in:
parent
77b71e392e
commit
8c32302377
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
#include <QDomElement>
|
#include <QDomElement>
|
||||||
#include <QDomNode>
|
#include <QDomNode>
|
||||||
@ -54,10 +55,29 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
void removePythonScript(const QString &path)
|
void clearPythonCache(const QString &path)
|
||||||
{
|
{
|
||||||
Utils::Fs::forceRemove(path);
|
// remove python cache artifacts in `path` and subdirs
|
||||||
Utils::Fs::forceRemove(path + 'c'); // python2 pyc files
|
|
||||||
|
QStringList dirs = {path};
|
||||||
|
QDirIterator iter {path, (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories};
|
||||||
|
while (iter.hasNext())
|
||||||
|
dirs += iter.next();
|
||||||
|
|
||||||
|
for (const QString &dir : qAsConst(dirs)) {
|
||||||
|
// python 3: remove "__pycache__" folders
|
||||||
|
if (dir.endsWith("/__pycache__")) {
|
||||||
|
Utils::Fs::removeDirRecursive(dir);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// python 2: remove "*.pyc" files
|
||||||
|
const QStringList files = QDir(dir).entryList(QDir::Files);
|
||||||
|
for (const QString file : files) {
|
||||||
|
if (file.endsWith(".pyc"))
|
||||||
|
Utils::Fs::forceRemove(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +189,8 @@ void SearchPluginManager::installPlugin(const QString &source)
|
|||||||
{
|
{
|
||||||
qDebug("Asked to install plugin at %s", qUtf8Printable(source));
|
qDebug("Asked to install plugin at %s", qUtf8Printable(source));
|
||||||
|
|
||||||
|
clearPythonCache(engineLocation());
|
||||||
|
|
||||||
if (Utils::Misc::isUrl(source)) {
|
if (Utils::Misc::isUrl(source)) {
|
||||||
using namespace Net;
|
using namespace Net;
|
||||||
DownloadHandler *handler = DownloadManager::instance()->downloadUrl(source, true);
|
DownloadHandler *handler = DownloadManager::instance()->downloadUrl(source, true);
|
||||||
@ -209,7 +231,7 @@ void SearchPluginManager::installPlugin_impl(const QString &name, const QString
|
|||||||
if (QFile::exists(destPath)) {
|
if (QFile::exists(destPath)) {
|
||||||
// Backup in case install fails
|
// Backup in case install fails
|
||||||
QFile::copy(destPath, destPath + ".bak");
|
QFile::copy(destPath, destPath + ".bak");
|
||||||
removePythonScript(destPath);
|
Utils::Fs::forceRemove(destPath);
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
// Copy the plugin
|
// Copy the plugin
|
||||||
@ -241,6 +263,8 @@ void SearchPluginManager::installPlugin_impl(const QString &name, const QString
|
|||||||
|
|
||||||
bool SearchPluginManager::uninstallPlugin(const QString &name)
|
bool SearchPluginManager::uninstallPlugin(const QString &name)
|
||||||
{
|
{
|
||||||
|
clearPythonCache(engineLocation());
|
||||||
|
|
||||||
// remove it from hard drive
|
// remove it from hard drive
|
||||||
QDir pluginsFolder(pluginsLocation());
|
QDir pluginsFolder(pluginsLocation());
|
||||||
QStringList filters;
|
QStringList filters;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user