From f2eddd404bda347a05ce6e74ad791268bbd3b70f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 26 Sep 2022 01:09:52 -0600 Subject: [PATCH] downloader: create destdir if it does not already exist, throw exception if this fails --- libs/pbd/downloader.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libs/pbd/downloader.cc b/libs/pbd/downloader.cc index 1d561acaf4..57ff9e5ca7 100644 --- a/libs/pbd/downloader.cc +++ b/libs/pbd/downloader.cc @@ -16,11 +16,16 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include +#include + #include #include #include +#include "pbd/compose.h" +#include "pbd/failed_constructor.h" #include "pbd/downloader.h" #include "pbd/error.h" #include "pbd/i18n.h" @@ -64,6 +69,17 @@ Downloader::Downloader (string const & u, string const & dir) , _download_size (0) , _downloaded (0) { + if (!Glib::file_test (destdir, Glib::FILE_TEST_EXISTS)) { + if (g_mkdir_with_parents (destdir.c_str(), 0700) != 0) { + error << string_compose (_("Could not create clip library dir %1 (%2)"), destdir, strerror(errno)) << endmsg; + throw failed_constructor(); + } + } else { + if (!Glib::file_test (destdir, Glib::FILE_TEST_IS_DIR)) { + error << string_compose (_("Clip library dir (%1) is not a directory"), destdir) << endmsg; + throw failed_constructor(); + } + } } Downloader::~Downloader ()