From b79ffc3d42db7d8277b505e9c22b551d99eb138f Mon Sep 17 00:00:00 2001 From: Alex Spataru Date: Mon, 26 Jan 2015 01:02:53 -0600 Subject: [PATCH] Avoid race conditions when saving downloaded files --- .../src/dialogs/download_dialog.cpp | 7 ++++++- QSimpleUpdater/src/qsimpleupdater.cpp | 2 +- bin/autostyle.cmd | 21 ------------------- bin/autostyle.sh | 19 ----------------- bin/readme.txt | 1 - 5 files changed, 7 insertions(+), 43 deletions(-) delete mode 100644 bin/autostyle.cmd delete mode 100644 bin/autostyle.sh delete mode 100644 bin/readme.txt diff --git a/QSimpleUpdater/src/dialogs/download_dialog.cpp b/QSimpleUpdater/src/dialogs/download_dialog.cpp index dc42271..3100d03 100644 --- a/QSimpleUpdater/src/dialogs/download_dialog.cpp +++ b/QSimpleUpdater/src/dialogs/download_dialog.cpp @@ -16,6 +16,8 @@ #include "download_dialog.h" #include "ui_download_dialog.h" +#include + DownloadDialog::DownloadDialog (QWidget *parent) : QWidget (parent) , ui (new Ui::DownloadDialog) @@ -150,14 +152,17 @@ void DownloadDialog::downloadFinished (void) { QStringList list = m_reply->url().toString().split ("/"); QFile file (QDir::tempPath() + "/" + list.at (list.count() - 1)); + QMutex _mutex; if (file.open (QIODevice::WriteOnly)) { + _mutex.lock(); file.write (data); m_path = file.fileName(); + file.close(); + _mutex.unlock(); } - file.close(); installUpdate(); } } diff --git a/QSimpleUpdater/src/qsimpleupdater.cpp b/QSimpleUpdater/src/qsimpleupdater.cpp index 882c5a2..67b5b50 100644 --- a/QSimpleUpdater/src/qsimpleupdater.cpp +++ b/QSimpleUpdater/src/qsimpleupdater.cpp @@ -102,7 +102,7 @@ QSimpleUpdater::QSimpleUpdater (QObject *parent) connect (m_progressDialog, SIGNAL (cancelClicked()), this, SLOT (cancel())); connect (this, SIGNAL (checkingFinished()), this, SLOT (onCheckingFinished())); - + setApplicationVersion (qApp->applicationVersion()); } diff --git a/bin/autostyle.cmd b/bin/autostyle.cmd deleted file mode 100644 index afcfdc4..0000000 --- a/bin/autostyle.cmd +++ /dev/null @@ -1,21 +0,0 @@ -:: Description: This script changes the style format of -:: all the source code of the project. - -:: Setup the command line -@echo off -title Autostyle - -:: Go to the directory where the script is run -cd /d %~dp0 - -:: Style and format the source code recursively -astyle --style=allman -C -S -xG -Y -XW -w -f -F -p -xd -k3 -y -xj -c -K -L --suffix=none --recursive ../*.cpp ../*.h ../*.hxx ../*.cxx - -:: Notify the user that we have finished -echo. -echo Code styling complete! -echo. - -:: Let the user see the output -pause - diff --git a/bin/autostyle.sh b/bin/autostyle.sh deleted file mode 100644 index c6d83f9..0000000 --- a/bin/autostyle.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Description: This script changes the style format of -# all the source code of the project. - -# Run only on the directory of the script -cd "$(dirname ${BASH_SOURCE[0]})" - -# Style and format recursively -astyle --style=allman -C -S -xG -Y -XW -w -f -F -p -xd -k3 -y -xj -c -K -L --suffix=none --recursive ../*.cpp ../*.h ../*.hxx ../*.cxx - -# Notify the user that we are done -echo -echo "Code styling complete!" -echo - -# Let the user see the output -read -n1 -r -p "Press any key to continue..." key -clear diff --git a/bin/readme.txt b/bin/readme.txt deleted file mode 100644 index b8cd6bf..0000000 --- a/bin/readme.txt +++ /dev/null @@ -1 +0,0 @@ -The scripts contained in this folder will require you to install the [astyle](http://astyle.sf.net) source code styler. \ No newline at end of file