Ensure that the temporary directory is usable

Cooperating applications that use file watchers can inadvertently lock
the  temporary  directory which  defers  deletion  of it  when  WSJT-X
exits.  This  is OK  until  WSJT-X  is  restarted  when it  finds  the
directory but  it is  locked for  all access  by the  operating system
since it  is pending deletion.  There is no  way around this  short of
closing the offending application so a message to that effect is given
with a retry option.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6347 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2016-01-05 16:43:41 +00:00
parent 59e093032e
commit 9fc5568e32

View File

@ -145,6 +145,7 @@
#include <QAction>
#include <QFileDialog>
#include <QDir>
#include <QTemporaryFile>
#include <QFormLayout>
#include <QString>
#include <QStringList>
@ -796,12 +797,29 @@ Configuration::impl::impl (Configuration * self, QSettings * settings, QWidget *
temp_dir_.setPath (temp_location);
}
bool ok {false};
QString unique_directory {QApplication::applicationName ()};
if (!temp_dir_.mkpath (unique_directory) || !temp_dir_.cd (unique_directory))
do
{
QMessageBox::critical (this, "WSJT-X", tr ("Create temporary directory error: ") + temp_dir_.absolutePath ());
throw std::runtime_error {"Failed to create usable temporary directory"};
if (!temp_dir_.mkpath (unique_directory)
|| !temp_dir_.cd (unique_directory))
{
QMessageBox::critical (this, "WSJT-X", tr ("Create temporary directory error: ") + temp_dir_.absolutePath ());
throw std::runtime_error {"Failed to create a temporary directory"};
}
if (!temp_dir_.isReadable () || !(ok = QTemporaryFile {temp_dir_.absoluteFilePath ("test")}.open ()))
{
if (QMessageBox::Cancel == QMessageBox::critical (this, "WSJT-X",
tr ("Create temporary directory error:\n%1\n"
"Another application may be locking the directory").arg (temp_dir_.absolutePath ()),
QMessageBox::Retry | QMessageBox::Cancel))
{
throw std::runtime_error {"Failed to create a usable temporary directory"};
}
temp_dir_.cdUp (); // revert to parent as this one is no good
}
}
while (!ok);
}
{