diff --git a/src/geoip/geoipmanager.cpp b/src/geoip/geoipmanager.cpp index be3be6c3b..148b504f4 100644 --- a/src/geoip/geoipmanager.cpp +++ b/src/geoip/geoipmanager.cpp @@ -101,7 +101,7 @@ void GeoIPManager::exportEmbeddedDb() { } // Remove destination files if(QFile::exists(geoipDBpath(false))) - misc::safeRemove(geoipDBpath(false)); + QFile::remove(geoipDBpath(false)); // Copy from executable to hard disk qDebug("%s -> %s", qPrintable(geoipDBpath(true)), qPrintable(geoipDBpath(false))); if(!QFile::copy(geoipDBpath(true), geoipDBpath(false))) { diff --git a/src/misc.cpp b/src/misc.cpp index d2c67bfb1..34ecd44e4 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -509,7 +509,7 @@ void misc::copyDir(QString src_path, QString dst_path) { // Copy the file from src to dest QFile::copy(src_child_path, dest_child_path); // Remove source file - safeRemove(src_child_path); + QFile::remove(src_child_path); } // Remove source folder const QString dir_name = sourceDir.dirName(); diff --git a/src/misc.h b/src/misc.h index 3ee337d18..8bb6870c7 100644 --- a/src/misc.h +++ b/src/misc.h @@ -93,15 +93,6 @@ public: static void shutdownComputer(bool sleep=false); #endif - static bool safeRemove(QString file_path) { - QFile MyFile(file_path); - if(!MyFile.exists()) return true; - // Make sure the permissions are ok - MyFile.setPermissions(MyFile.permissions()|QFile::ReadOwner|QFile::WriteOwner|QFile::ReadUser|QFile::WriteUser); - // Actually remove the file - return MyFile.remove(); - } - static QString parseHtmlLinks(const QString &raw_text); static bool removeEmptyFolder(const QString &dirpath); diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 68366a19b..bbdf42769 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -793,7 +793,7 @@ void QBtSession::deleteTorrent(const QString &hash, bool delete_local_files) { // Remove unneeded and incomplete files foreach(const QString &uneeded_file, uneeded_files) { qDebug("Removing uneeded file: %s", qPrintable(uneeded_file)); - misc::safeRemove(uneeded_file); + QFile::remove(uneeded_file); const QString parent_folder = misc::branchPath(uneeded_file); qDebug("Attempt to remove parent folder (if empty): %s", qPrintable(parent_folder)); misc::removeEmptyFolder(parent_folder); @@ -805,7 +805,7 @@ void QBtSession::deleteTorrent(const QString &hash, bool delete_local_files) { filters << hash+".*"; const QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted); foreach(const QString &file, files) { - misc::safeRemove(torrentBackup.absoluteFilePath(file)); + QFile::remove(torrentBackup.absoluteFilePath(file)); } TorrentPersistentData::deletePersistentData(hash); // Remove tracker errors @@ -1005,7 +1005,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red")); addConsoleMessage(QString::fromLocal8Bit(e.what()), "red"); //emit invalidTorrent(from_url); - misc::safeRemove(path); + QFile::remove(path); }else{ #if defined(Q_WS_WIN) || defined(Q_OS_OS2) QString displayed_path = path; @@ -1019,7 +1019,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."),QString::fromUtf8("red")); if(fromScanDir) { // Remove file - misc::safeRemove(path); + QFile::remove(path); } return h; } @@ -1050,7 +1050,8 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr mergeTorrents(h_ex, t); // Delete file if temporary - if(!from_url.isNull() || fromScanDir) misc::safeRemove(path); + if(!from_url.isNull() || fromScanDir) + QFile::remove(path); return h; } @@ -1058,7 +1059,8 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr if(t->num_files() < 1) { addConsoleMessage(tr("Error: The torrent %1 does not contain any file.").arg(misc::toQStringU(t->name()))); // Delete file if temporary - if(!from_url.isNull() || fromScanDir) misc::safeRemove(path); + if(!from_url.isNull() || fromScanDir) + QFile::remove(path); return h; } @@ -1135,7 +1137,8 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr // Check if it worked if(!h.is_valid()) { qDebug("/!\\ Error: Invalid handle"); - if(!from_url.isNull()) misc::safeRemove(path); + if(!from_url.isNull()) + QFile::remove(path); return h; } // Remember root folder @@ -1180,7 +1183,8 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr } // If temporary file, remove it - if(!from_url.isNull() || fromScanDir) misc::safeRemove(path); + if(!from_url.isNull() || fromScanDir) + QFile::remove(path); // Display console message if(!from_url.isNull()) { @@ -1496,7 +1500,7 @@ void QBtSession::loadSessionState() { if(!QFile::exists(state_path)) return; if(QFile(state_path).size() == 0) { // Remove empty invalid state file - misc::safeRemove(state_path); + QFile::remove(state_path); return; } #if LIBTORRENT_VERSION_MINOR > 14 @@ -1700,7 +1704,7 @@ void QBtSession::saveFastResumeData() { const QString filepath = torrentBackup.absoluteFilePath(h.hash()+".fastresume"); QFile resume_file(filepath); if(resume_file.exists()) - misc::safeRemove(filepath); + QFile::remove(filepath); if(!out.empty() && resume_file.open(QIODevice::WriteOnly)) { resume_file.write(&out[0], out.size()); resume_file.close(); @@ -2302,7 +2306,7 @@ void QBtSession::readAlerts() { const QString filepath = torrentBackup.absoluteFilePath(h.hash()+".fastresume"); QFile resume_file(filepath); if(resume_file.exists()) - misc::safeRemove(filepath); + QFile::remove(filepath); qDebug("Saving fastresume data in %s", qPrintable(filepath)); vector out; bencode(back_inserter(out), *p->resume_data); diff --git a/src/rss/rssfeed.cpp b/src/rss/rssfeed.cpp index 35d23205f..aef0f94c0 100644 --- a/src/rss/rssfeed.cpp +++ b/src/rss/rssfeed.cpp @@ -60,7 +60,7 @@ RssFeed::~RssFeed(){ saveItemsToDisk(); } if(!m_icon.startsWith(":/") && QFile::exists(m_icon)) - misc::safeRemove(m_icon); + QFile::remove(m_icon); } void RssFeed::saveItemsToDisk() { diff --git a/src/searchengine/engineselectdlg.cpp b/src/searchengine/engineselectdlg.cpp index 7977dae92..815a57c0c 100644 --- a/src/searchengine/engineselectdlg.cpp +++ b/src/searchengine/engineselectdlg.cpp @@ -243,8 +243,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"); - misc::safeRemove(dest_path); - misc::safeRemove(dest_path+"c"); + QFile::remove(dest_path); + QFile::remove(dest_path+"c"); update = true; } // Copy the plugin @@ -255,22 +255,22 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) { if(!supported_engines->contains(plugin_name)) { if(update) { // Remove broken file - misc::safeRemove(dest_path); + QFile::remove(dest_path); // restore backup QFile::copy(dest_path+".bak", dest_path); - misc::safeRemove(dest_path+".bak"); + QFile::remove(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 - misc::safeRemove(dest_path); + QFile::remove(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) { - misc::safeRemove(dest_path+".bak"); + QFile::remove(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)); @@ -388,7 +388,7 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) { // Close file versions.close(); // Clean up tmp file - misc::safeRemove(versions_file); + QFile::remove(versions_file); if(file_correct && !updated) { QMessageBox::information(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("All your plugins are already up to date.")); } @@ -418,21 +418,21 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { } } // Delete tmp file - misc::safeRemove(filePath); + QFile::remove(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.")); } - misc::safeRemove(filePath); + QFile::remove(filePath); return; } if(url.endsWith(".py", Qt::CaseInsensitive)) { QString plugin_name = misc::fileName(url); plugin_name.chop(3); // Remove extension installPlugin(filePath, plugin_name); - misc::safeRemove(filePath); + QFile::remove(filePath); return; } } diff --git a/src/searchengine/searchengine.cpp b/src/searchengine/searchengine.cpp index 4c1ee8ec4..ce9d90a1b 100644 --- a/src/searchengine/searchengine.cpp +++ b/src/searchengine/searchengine.cpp @@ -168,7 +168,7 @@ void SearchEngine::pythonDownloadSuccess(QString url, QString file_path) { on_search_button_clicked(); } // Delete temp file - misc::safeRemove(file_path+".msi"); + QFile::remove(file_path+".msi"); } void SearchEngine::pythonDownloadFailure(QString url, QString error) { @@ -500,8 +500,8 @@ void SearchEngine::updateNova() { QString filePath = search_dir.absoluteFilePath("nova2.py"); if(getPluginVersion(":/"+nova_folder+"/nova2.py") > getPluginVersion(filePath)) { if(QFile::exists(filePath)) { - misc::safeRemove(filePath); - misc::safeRemove(filePath+"c"); + QFile::remove(filePath); + QFile::remove(filePath+"c"); } QFile::copy(":/"+nova_folder+"/nova2.py", filePath); } @@ -509,8 +509,8 @@ void SearchEngine::updateNova() { filePath = search_dir.absoluteFilePath("nova2dl.py"); if(getPluginVersion(":/"+nova_folder+"/nova2dl.py") > getPluginVersion(filePath)) { if(QFile::exists(filePath)){ - misc::safeRemove(filePath); - misc::safeRemove(filePath+"c"); + QFile::remove(filePath); + QFile::remove(filePath+"c"); } QFile::copy(":/"+nova_folder+"/nova2dl.py", filePath); } @@ -518,8 +518,8 @@ void SearchEngine::updateNova() { filePath = search_dir.absoluteFilePath("novaprinter.py"); if(getPluginVersion(":/"+nova_folder+"/novaprinter.py") > getPluginVersion(filePath)) { if(QFile::exists(filePath)){ - misc::safeRemove(filePath); - misc::safeRemove(filePath+"c"); + QFile::remove(filePath); + QFile::remove(filePath+"c"); } QFile::copy(":/"+nova_folder+"/novaprinter.py", filePath); } @@ -527,24 +527,24 @@ void SearchEngine::updateNova() { filePath = search_dir.absoluteFilePath("helpers.py"); if(getPluginVersion(":/"+nova_folder+"/helpers.py") > getPluginVersion(filePath)) { if(QFile::exists(filePath)){ - misc::safeRemove(filePath); - misc::safeRemove(filePath+"c"); + QFile::remove(filePath); + QFile::remove(filePath+"c"); } QFile::copy(":/"+nova_folder+"/helpers.py", filePath); } filePath = search_dir.absoluteFilePath("socks.py"); if(QFile::exists(filePath)){ - misc::safeRemove(filePath); - misc::safeRemove(filePath+"c"); + QFile::remove(filePath); + QFile::remove(filePath+"c"); } QFile::copy(":/"+nova_folder+"/socks.py", filePath); if (nova_folder == "nova3") { filePath = search_dir.absoluteFilePath("sgmllib3.py"); if(QFile::exists(filePath)){ - misc::safeRemove(filePath); - misc::safeRemove(filePath+"c"); + QFile::remove(filePath); + QFile::remove(filePath+"c"); } QFile::copy(":/"+nova_folder+"/sgmllib3.py", filePath); } @@ -560,8 +560,8 @@ void SearchEngine::updateNova() { qDebug("shipped %s is more recent then local plugin, updating...", qPrintable(file)); if(QFile::exists(dest_file)) { qDebug("Removing old %s", qPrintable(dest_file)); - misc::safeRemove(dest_file); - misc::safeRemove(dest_file+"c"); + QFile::remove(dest_file); + QFile::remove(dest_file+"c"); } qDebug("%s copied to %s", qPrintable(shipped_file), qPrintable(dest_file)); QFile::copy(shipped_file, dest_file); diff --git a/src/torrentadditiondlg.cpp b/src/torrentadditiondlg.cpp index 244725b94..8f181cbac 100644 --- a/src/torrentadditiondlg.cpp +++ b/src/torrentadditiondlg.cpp @@ -258,7 +258,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) { qDebug("Caught error loading torrent"); if(!from_url.isNull()){ QBtSession::instance()->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red")); - misc::safeRemove(filePath); + QFile::remove(filePath); }else{ QBtSession::instance()->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red")); } diff --git a/src/torrentcreator/torrentcreatorthread.cpp b/src/torrentcreator/torrentcreatorthread.cpp index ae3b65816..ff00746d7 100644 --- a/src/torrentcreator/torrentcreatorthread.cpp +++ b/src/torrentcreator/torrentcreatorthread.cpp @@ -76,7 +76,7 @@ void TorrentCreatorThread::create(QString _input_path, QString _save_path, QStri input_path = _input_path; save_path = _save_path; if(QFile(save_path).exists()) - misc::safeRemove(save_path); + QFile::remove(save_path); trackers = _trackers; url_seeds = _url_seeds; comment = _comment;