- if (afs->within_session()) {
- filemap[from] = make_new_media_path (from, name, name);
+ /* copy files as-is */
+ if (!afs->within_session()) {
+ string to = Glib::path_get_basename (from);
+
+ /* avoid name collitions, see also new_audio_source_path_for_embedded ()
+ * - avoid conflict with files existing in interchange
+ * - avoid conflict with other embedded sources
+ */
+ if (audio_file_names.find (to) == audio_file_names.end ()) {
+ // we need a new name, add a '-<num>' before the '.<ext>'
+ string bn = to.substr (0, to.find_last_of ('.'));
+ string ext = to.find_last_of ('.') == string::npos ? "" : to.substr (to.find_last_of ('.'));
+ to = bn + "-1" + ext;
+ }
+ while (audio_file_names.find (to) == audio_file_names.end ()) {
+ to = bump_name_once (to, '-');
+ }
+
+ audio_file_names.insert (to);
+ filemap[from] = make_new_audio_path (to, name, name);
+
+ remove_dir_from_search_path (Glib::path_get_dirname (from), DataType::AUDIO);
+
+ orig_origin[afs] = afs->origin ();
+ afs->set_origin ("");
+