Fix permission problems on Windows (closes #1020227)

This commit is contained in:
Christophe Dumez
2012-07-05 19:10:13 +03:00
parent a85ddada25
commit 90373897d6
9 changed files with 59 additions and 57 deletions

View File

@@ -244,8 +244,8 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
if (QFile::exists(dest_path)) {
// Backup in case install fails
QFile::copy(dest_path, dest_path+".bak");
QFile::remove(dest_path);
QFile::remove(dest_path+"c");
fsutils::forceRemove(dest_path);
fsutils::forceRemove(dest_path+"c");
update = true;
}
// Copy the plugin
@@ -256,22 +256,22 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
if (!supported_engines->contains(plugin_name)) {
if (update) {
// Remove broken file
QFile::remove(dest_path);
fsutils::forceRemove(dest_path);
// restore backup
QFile::copy(dest_path+".bak", dest_path);
QFile::remove(dest_path+".bak");
fsutils::forceRemove(dest_path+".bak");
QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be updated, keeping old version.", "%1 is the name of the search engine").arg(plugin_name));
return;
} else {
// Remove broken file
QFile::remove(dest_path);
fsutils::forceRemove(dest_path);
QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin could not be installed.", "%1 is the name of the search engine").arg(plugin_name));
return;
}
}
// Install was successful, remove backup
if (update) {
QFile::remove(dest_path+".bak");
fsutils::forceRemove(dest_path+".bak");
}
if (update) {
QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name));
@@ -389,7 +389,7 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) {
// Close file
versions.close();
// Clean up tmp file
QFile::remove(versions_file);
fsutils::forceRemove(versions_file);
if (file_correct && !updated) {
QMessageBox::information(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("All your plugins are already up to date."));
}
@@ -419,21 +419,21 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
}
}
// Delete tmp file
QFile::remove(filePath);
fsutils::forceRemove(filePath);
return;
}
if (url.endsWith("versions.txt")) {
if (!parseVersionsFile(filePath)) {
QMessageBox::warning(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("Sorry, update server is temporarily unavailable."));
}
QFile::remove(filePath);
fsutils::forceRemove(filePath);
return;
}
if (url.endsWith(".py", Qt::CaseInsensitive)) {
QString plugin_name = fsutils::fileName(url);
plugin_name.chop(3); // Remove extension
installPlugin(filePath, plugin_name);
QFile::remove(filePath);
fsutils::forceRemove(filePath);
return;
}
}

View File

@@ -468,6 +468,12 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) {
delete downloadProcess;
}
static void removePythonScriptIfExists(const QString& script_path)
{
fsutils::forceRemove(script_path);
fsutils::forceRemove(script_path+"c");
}
// Update nova.py search plugin if necessary
void SearchEngine::updateNova() {
qDebug("Updating nova");
@@ -486,53 +492,35 @@ void SearchEngine::updateNova() {
// Copy search plugin files (if necessary)
QString filePath = search_dir.absoluteFilePath("nova2.py");
if (getPluginVersion(":/"+nova_folder+"/nova2.py") > getPluginVersion(filePath)) {
if (QFile::exists(filePath)) {
QFile::remove(filePath);
QFile::remove(filePath+"c");
}
removePythonScriptIfExists(filePath);
QFile::copy(":/"+nova_folder+"/nova2.py", filePath);
}
filePath = search_dir.absoluteFilePath("nova2dl.py");
if (getPluginVersion(":/"+nova_folder+"/nova2dl.py") > getPluginVersion(filePath)) {
if (QFile::exists(filePath)) {
QFile::remove(filePath);
QFile::remove(filePath+"c");
}
removePythonScriptIfExists(filePath);
QFile::copy(":/"+nova_folder+"/nova2dl.py", filePath);
}
filePath = search_dir.absoluteFilePath("novaprinter.py");
if (getPluginVersion(":/"+nova_folder+"/novaprinter.py") > getPluginVersion(filePath)) {
if (QFile::exists(filePath)) {
QFile::remove(filePath);
QFile::remove(filePath+"c");
}
removePythonScriptIfExists(filePath);
QFile::copy(":/"+nova_folder+"/novaprinter.py", filePath);
}
filePath = search_dir.absoluteFilePath("helpers.py");
if (getPluginVersion(":/"+nova_folder+"/helpers.py") > getPluginVersion(filePath)) {
if (QFile::exists(filePath)) {
QFile::remove(filePath);
QFile::remove(filePath+"c");
}
removePythonScriptIfExists(filePath);
QFile::copy(":/"+nova_folder+"/helpers.py", filePath);
}
filePath = search_dir.absoluteFilePath("socks.py");
if (QFile::exists(filePath)) {
QFile::remove(filePath);
QFile::remove(filePath+"c");
}
removePythonScriptIfExists(filePath);
QFile::copy(":/"+nova_folder+"/socks.py", filePath);
if (nova_folder == "nova3") {
filePath = search_dir.absoluteFilePath("sgmllib3.py");
if (QFile::exists(filePath)) {
QFile::remove(filePath);
QFile::remove(filePath+"c");
}
removePythonScriptIfExists(filePath);
QFile::copy(":/"+nova_folder+"/sgmllib3.py", filePath);
}
QDir destDir(QDir(fsutils::searchEngineLocation()).absoluteFilePath("engines"));
@@ -545,11 +533,7 @@ void SearchEngine::updateNova() {
const QString dest_file = destDir.absoluteFilePath(file);
if (getPluginVersion(shipped_file) > getPluginVersion(dest_file) ) {
qDebug("shipped %s is more recent then local plugin, updating...", qPrintable(file));
if (QFile::exists(dest_file)) {
qDebug("Removing old %s", qPrintable(dest_file));
QFile::remove(dest_file);
QFile::remove(dest_file+"c");
}
removePythonScriptIfExists(dest_file);
qDebug("%s copied to %s", qPrintable(shipped_file), qPrintable(dest_file));
QFile::copy(shipped_file, dest_file);
}