13
0

fix up condition where a MIDI filesource is marked empty, not found, and its _path member is not set correctly

This commit is contained in:
Paul Davis 2014-09-15 12:38:54 -04:00
parent 34c5aaf326
commit 68d362fd27

View File

@ -99,16 +99,15 @@ SMFSource::SMFSource (Session& s, const string& path)
{ {
/* note that origin remains empty */ /* note that origin remains empty */
if (init (_path, false)) { if (init (_path, true)) {
throw failed_constructor (); throw failed_constructor ();
} }
assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)); assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
existence_check (); existence_check ();
/* file is not opened until write */
if (_flags & Writable) { if (_flags & Writable) {
/* file is not opened until write */
return; return;
} }
@ -138,8 +137,30 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
require it to exist if it was marked Empty. require it to exist if it was marked Empty.
*/ */
if (init (_path, !(_flags & Source::Empty))) { try {
throw failed_constructor ();
if (init (_path, true)) {
throw failed_constructor ();
}
} catch (MissingSource& err) {
if (_flags & Source::Empty) {
/* we don't care that the file was not found, because
it was empty. But FileSource::init() will have
failed to set our _path correctly, so we have to do
this ourselves. Use the first entry in the search
path for MIDI files, which is assumed to be the
correct "main" location.
*/
std::vector<string> sdirs = s.source_search_path (DataType::MIDI);
_path = Glib::build_filename (sdirs.front(), _path);
/* This might be important, too */
_file_is_new = true;
} else {
/* pass it on */
throw;
}
} }
if (!(_flags & Source::Empty)) { if (!(_flags & Source::Empty)) {
@ -704,6 +725,10 @@ SMFSource::set_path (const string& p)
void void
SMFSource::ensure_disk_file () SMFSource::ensure_disk_file ()
{ {
if (!writable()) {
return;
}
if (_model) { if (_model) {
/* We have a model, so write it to disk; see MidiSource::session_saved /* We have a model, so write it to disk; see MidiSource::session_saved
for an explanation of what we are doing here. for an explanation of what we are doing here.