From 9fc5568e3235d130821ced862d931e14b3493209 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Tue, 5 Jan 2016 16:43:41 +0000 Subject: [PATCH] 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 --- Configuration.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Configuration.cpp b/Configuration.cpp index 4595266c0..74caa6548 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -145,6 +145,7 @@ #include #include #include +#include #include #include #include @@ -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); } {