+ * If the source is within the session tree, \a filename should be a simple filename (no slashes).
+ * If the source is external, \a filename should be a full path.
+ * In either case, found_path is set to the complete absolute path of the source file.
+ * \return true iff the file was found.
+ */
+bool
+FileSource::find (Session& s, DataType type, const string& path, bool must_exist,
+ bool& isnew, uint16_t& chan, string& found_path)
+{
+ bool ret = false;
+ string keeppath;
+
+ isnew = false;
+
+ if (!Glib::path_is_absolute (path)) {
+ vector<string> dirs;
+ vector<string> hits;
+ int cnt;
+ string fullpath;
+
+ string search_path = s.source_search_path (type);
+
+ 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) {
+
+ 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;
+ }
+ }
+
+ if (cnt > 1) {
+
+ int which = FileSource::AmbiguousFileName (path, search_path, hits).get_value_or (-1);
+
+ if (which < 0) {
+ goto out;
+ } else {
+ keeppath = hits[which];
+ }
+
+ } 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
+ sources. QuickFix(tm)
+ */
+ if (keeppath == "") {
+ if (must_exist) {
+ error << "FileSource::find(), keeppath = \"\", but the file must exist" << endl;
+ } else {
+ keeppath = path;
+ }
+ }
+
+ found_path = keeppath;
+
+ ret = true;
+
+ out:
+ return ret;
+}
+
+/** Find the actual source file based on \a filename.
+ *
+ * If the source is within the session tree, \a filename should be a simple filename (no slashes).