always store source names as relative paths; always add directories of embedded files to search path; never use hardlinks for embedding anymore

git-svn-id: svn://localhost/ardour2/branches/3.0@7984 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-11-09 17:24:17 +00:00
parent 5c6ba165f6
commit 7ae1a99d06
6 changed files with 98 additions and 95 deletions

View file

@ -606,7 +606,6 @@ Editor::embed_sndfiles (vector<string> paths, bool multifile,
string linked_path; string linked_path;
SoundFileInfo finfo; SoundFileInfo finfo;
int ret = 0; int ret = 0;
string path_to_use;
set_canvas_cursor (wait_cursor); set_canvas_cursor (wait_cursor);
gdk_flush (); gdk_flush ();
@ -614,48 +613,10 @@ Editor::embed_sndfiles (vector<string> paths, bool multifile,
for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) { for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
string path = *p; string path = *p;
string error_msg;
if (Config->get_try_link_for_embed()) {
/* lets see if we can link it into the session */
sys::path tmp = _session->session_directory().sound_path() / Glib::path_get_basename(path);
linked_path = tmp.to_string();
path_to_use = linked_path;
if (link (path.c_str(), linked_path.c_str()) == 0) {
/* there are many reasons why link(2) might have failed.
but if it succeeds, we now have a link in the
session sound dir that will protect against
unlinking of the original path. nice.
*/
path = linked_path;
path_to_use = Glib::path_get_basename (path);
} else {
/* one possible reason is that its already linked */
if (errno == EEXIST) {
struct stat sb;
if (stat (linked_path.c_str(), &sb) == 0) {
if (sb.st_nlink > 1) { // its a hard link, assume its the one we want
path = linked_path;
path_to_use = Glib::path_get_basename (path);
}
}
}
}
}
/* note that we temporarily truncated _id at the colon */ /* note that we temporarily truncated _id at the colon */
string error_msg;
if (!AudioFileSource::get_soundfile_info (path, finfo, error_msg)) { if (!AudioFileSource::get_soundfile_info (path, finfo, error_msg)) {
error << string_compose(_("Editor: cannot open file \"%1\", (%2)"), path, error_msg ) << endmsg; error << string_compose(_("Editor: cannot open file \"%1\", (%2)"), path, error_msg ) << endmsg;
goto out; goto out;
@ -732,7 +693,7 @@ Editor::embed_sndfiles (vector<string> paths, bool multifile,
source = boost::dynamic_pointer_cast<AudioFileSource> ( source = boost::dynamic_pointer_cast<AudioFileSource> (
SourceFactory::createReadable (DataType::AUDIO, *_session, SourceFactory::createReadable (DataType::AUDIO, *_session,
path_to_use, n, path, n,
(mode == ImportAsTapeTrack (mode == ImportAsTapeTrack
? Source::Destructive ? Source::Destructive
: Source::Flag (0)), : Source::Flag (0)),

View file

@ -786,6 +786,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
bool timecode_transmission_suspended () const; bool timecode_transmission_suspended () const;
std::string source_search_path(DataType) const; std::string source_search_path(DataType) const;
void ensure_search_path_includes (const std::string& path, DataType type);
/* handlers can return an integer value: /* handlers can return an integer value:
0: config.set_audio_search_path() or config.set_midi_search_path() was used 0: config.set_audio_search_path() or config.set_midi_search_path() was used

View file

@ -100,7 +100,7 @@ AudioFileSource::AudioFileSource (Session& s, const string& path, Source::Flag f
if (init (_path, true)) { if (init (_path, true)) {
throw failed_constructor (); throw failed_constructor ();
} }
cerr << "audiofile source created with path " << path << endl;
} }
/** Constructor used for new internal-to-session files. */ /** Constructor used for new internal-to-session files. */

View file

@ -104,9 +104,11 @@ FileSource::init (const string& pathstr, bool must_exist)
set_within_session_from_path (pathstr); set_within_session_from_path (pathstr);
if (_within_session) { if (!within_session()) {
_name = Glib::path_get_basename (_name); _session.ensure_search_path_includes (Glib::path_get_dirname (pathstr), _type);
} }
_name = Glib::path_get_basename (pathstr);
if (_file_is_new && must_exist) { if (_file_is_new && must_exist) {
return -1; return -1;
@ -211,64 +213,63 @@ bool
FileSource::find (Session& s, DataType type, const string& path, bool must_exist, FileSource::find (Session& s, DataType type, const string& path, bool must_exist,
bool& isnew, uint16_t& chan, string& found_path) bool& isnew, uint16_t& chan, string& found_path)
{ {
string search_path = s.source_search_path (type);
string pathstr = path;
bool ret = false; bool ret = false;
string keeppath;
cerr << "Searching along " << search_path << endl;
isnew = false; isnew = false;
if (!Glib::path_is_absolute (path)) {
vector<string> dirs;
vector<string> hits;
int cnt;
string fullpath;
vector<string> dirs; string search_path = s.source_search_path (type);
vector<string> hits;
int cnt;
string fullpath;
string keeppath;
if (search_path.length() == 0) {
error << _("FileSource: search path not set") << endmsg;
goto out;
}
split (search_path, dirs, ':');
cnt = 0;
hits.clear ();
for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
cerr << "Searching in " << *i << " for " << pathstr << endl;
fullpath = Glib::build_filename (*i, pathstr);
if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
keeppath = fullpath;
hits.push_back (fullpath);
++cnt;
}
}
if (cnt > 1) {
int which = FileSource::AmbiguousFileName (pathstr, search_path, hits).get_value_or (-1);
if (which < 0) { if (search_path.length() == 0) {
error << _("FileSource: search path not set") << endmsg;
goto out; goto out;
} else { }
keeppath = hits[which];
split (search_path, dirs, ':');
cnt = 0;
hits.clear ();
for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
fullpath = Glib::build_filename (*i, path);
if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
keeppath = fullpath;
hits.push_back (fullpath);
++cnt;
}
} }
} else if (cnt == 0) { if (cnt > 1) {
if (must_exist) { int which = FileSource::AmbiguousFileName (path, search_path, hits).get_value_or (-1);
error << string_compose(
_("Filesource: cannot find required file (%1): while searching %2"), if (which < 0) {
pathstr, search_path) << endmsg; goto out;
goto out; } else {
} else { keeppath = hits[which];
isnew = true; }
} else if (cnt == 0) {
if (must_exist) {
error << string_compose(
_("Filesource: cannot find required file (%1): while searching %2"),
path, search_path) << endmsg;
goto out;
} else {
isnew = true;
}
} }
} else {
keeppath = path;
} }
/* Current find() is unable to parse relative path names to yet non-existant /* Current find() is unable to parse relative path names to yet non-existant
@ -278,7 +279,7 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist
if (must_exist) { if (must_exist) {
error << "FileSource::find(), keeppath = \"\", but the file must exist" << endl; error << "FileSource::find(), keeppath = \"\", but the file must exist" << endl;
} else { } else {
keeppath = pathstr; keeppath = path;
} }
} }

View file

@ -4117,3 +4117,41 @@ Session::source_search_path (DataType type) const
return search_path; return search_path;
} }
void
Session::ensure_search_path_includes (const string& path, DataType type)
{
string search_path;
vector<string> dirs;
switch (type) {
case DataType::AUDIO:
search_path = config.get_audio_search_path ();
break;
case DataType::MIDI:
search_path = config.get_midi_search_path ();
break;
}
split (search_path, dirs, ':');
for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
if (*i == path) {
return;
}
}
if (!search_path.empty()) {
search_path += ':';
}
search_path += path;
switch (type) {
case DataType::AUDIO:
config.set_audio_search_path (search_path);
break;
case DataType::MIDI:
config.set_midi_search_path (search_path);
break;
}
}

View file

@ -217,6 +217,8 @@ SndFileSource::open ()
so we don't want to see this message. so we don't want to see this message.
*/ */
cerr << "failed to open " << _path << " with name " << _name << endl;
error << string_compose(_("SndFileSource: cannot open file \"%1\" for %2 (%3)"), error << string_compose(_("SndFileSource: cannot open file \"%1\" for %2 (%3)"),
_path, (writable() ? "read+write" : "reading"), errbuf) << endmsg; _path, (writable() ? "read+write" : "reading"), errbuf) << endmsg;
#endif #endif