#include "pbd/convert.h"
#include "pbd/basename.h"
-#include "pbd/mountpoint.h"
#include "pbd/stl_delete.h"
#include "pbd/strsplit.h"
#include "pbd/shortpath.h"
#include "pbd/enumwriter.h"
+#include "pbd/file_utils.h"
#include <glibmm/miscutils.h>
#include <glibmm/fileutils.h>
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
+#include "ardour/data_type.h"
#include "ardour/file_source.h"
-#include "ardour/directory_names.h"
#include "ardour/session.h"
-#include "ardour/session_directory.h"
-#include "ardour/source_factory.h"
-#include "ardour/filename_extensions.h"
+#include "ardour/source.h"
+#include "ardour/utils.h"
#include "i18n.h"
FileSource::FileSource (Session& session, DataType type, const string& path, const string& origin, Source::Flag flag)
: Source(session, type, path, flag)
- , _path(path)
- , _file_is_new(true)
+ , _path (path)
+ , _file_is_new (!origin.empty()) // origin empty => new file VS. origin !empty => new file
, _channel (0)
, _origin (origin)
, _open (false)
{
_timeline_position = 0;
- if (Stateful::loading_state_version < 3000) {
- if (!find_2X (_session, _type, pathstr, must_exist, _file_is_new, _channel, _path)) {
- throw MissingSource (pathstr, _type);
- }
- } else {
- if (!find (_session, _type, pathstr, must_exist, _file_is_new, _channel, _path)) {
- throw MissingSource (pathstr, _type);
- }
- }
+ if (Stateful::loading_state_version < 3000) {
+ if (!find_2X (_session, _type, pathstr, must_exist, _file_is_new, _channel, _path)) {
+ throw MissingSource (pathstr, _type);
+ }
+ } else {
+ if (!find (_session, _type, pathstr, must_exist, _file_is_new, _channel, _path)) {
+ throw MissingSource (pathstr, _type);
+ }
+ }
set_within_session_from_path (_path);
- if (!within_session()) {
- _session.ensure_search_path_includes (Glib::path_get_dirname (_path), _type);
- }
-
_name = Glib::path_get_basename (_path);
- if (_file_is_new && must_exist) {
- return -1;
+ if (must_exist) {
+ if (!Glib::file_test (_path, Glib::FILE_TEST_EXISTS)) {
+ throw MissingSource (pathstr, _type);
+ }
}
return 0;
*/
bool
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)
{
bool ret = false;
string keeppath;
if (!Glib::path_is_absolute (path)) {
vector<string> dirs;
vector<string> hits;
- int cnt;
string fullpath;
string search_path = s.source_search_path (type);
split (search_path, dirs, ':');
- cnt = 0;
hits.clear ();
for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
keeppath = fullpath;
hits.push_back (fullpath);
- ++cnt;
}
}
- if (cnt > 1) {
+ /* Remove duplicate inodes from the list of ambiguous files, since if there are symlinks
+ in the session path it is possible to arrive at the same file via more than one path.
+
+ I suppose this is not necessary on Windows.
+ */
+
+ vector<string> de_duped_hits;
+
+ for (vector<string>::iterator i = hits.begin(); i != hits.end(); ++i) {
+
+ vector<string>::iterator j = i;
+ ++j;
+
+ while (j != hits.end()) {
+ if (PBD::equivalent_paths (*i, *j)) {
+ /* *i and *j are the same file; break out of the loop early */
+ break;
+ }
+
+ ++j;
+ }
+
+ if (j == hits.end ()) {
+ de_duped_hits.push_back (*i);
+ }
+ }
+
+ if (de_duped_hits.size() > 1) {
- int which = FileSource::AmbiguousFileName (path, search_path, hits).get_value_or (-1);
+ /* more than one match: ask the user */
+
+ int which = FileSource::AmbiguousFileName (path, search_path, de_duped_hits).get_value_or (-1);
if (which < 0) {
goto out;
} else {
- keeppath = hits[which];
+ keeppath = de_duped_hits[which];
}
- } else if (cnt == 0) {
+ } else if (de_duped_hits.size() == 0) {
+
+ /* no match: error */
if (must_exist) {
error << string_compose(
} else {
isnew = true;
}
- }
+ } else {
+
+ /* only one match: happy days */
+
+ keeppath = de_duped_hits[0];
+ }
+
} else {
keeppath = path;
}
int
FileSource::set_source_name (const string& newname, bool destructive)
{
- Glib::Mutex::Lock lm (_lock);
+ Glib::Threads::Mutex::Lock lm (_lock);
string oldpath = _path;
string newpath = _session.change_source_path_by_name (oldpath, _name, newname, destructive);
}
}
+void
+FileSource::mark_immutable_except_write ()
+{
+ /* destructive sources stay writable, and their other flags don't change. */
+ if (!(_flags & Destructive)) {
+ _flags = Flag (_flags & ~(Removable|RemovableIfEmpty|RemoveAtDestroy|CanRename));
+ }
+}
+
void
FileSource::mark_nonremovable ()
{