}
FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist*/)
- : Source(session, node)
+ : Source (session, node)
, _file_is_new (false)
{
/* this setting of _path is temporary - we expect derived classes
{
/* if this file already exists, it cannot be removed, ever
*/
-
+
if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)) {
if (!(_flags & Destructive)) {
mark_immutable ();
FileSource::removable () const
{
bool r = ((_flags & Removable)
- && ((_flags & RemoveAtDestroy) ||
+ && ((_flags & RemoveAtDestroy) ||
((_flags & RemovableIfEmpty) && empty() == 0)));
-
+
return r;
}
*/
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;
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);
}
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);
-
+
+ /* 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.
+ */
+
+ 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()) {
+
+ struct stat bufA;
+ int const rA = stat (i->c_str(), &bufA);
+ struct stat bufB;
+ int const rB = stat (j->c_str(), &bufB);
+
+ if (rA == 0 && rB == 0 && bufA.st_ino == bufB.st_ino) {
+ /* *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) {
+
+ /* 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(
_("Filesource: cannot find required file (%1): while searching %2"),
} else {
isnew = true;
}
- }
+ } else {
+
+ /* only one match: happy days */
+
+ keeppath = de_duped_hits[0];
+ }
+
} else {
keeppath = path;
}
-
+
/* Current find() is unable to parse relative path names to yet non-existant
- sources. QuickFix(tm)
+ sources. QuickFix(tm)
*/
if (keeppath == "") {
if (must_exist) {
keeppath = path;
}
}
-
+
found_path = keeppath;
-
+
ret = true;
-
+
out:
return ret;
}
cnt = 0;
for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
-
+
fullpath = Glib::build_filename (*i, pathstr);
/* i (paul) made a nasty design error by using ':' as a special character in
error << string_compose (_("Programming error! %1 tried to rename a file over another file! It's safe to continue working, but please report this to the developers."), PROGRAM_NAME) << endmsg;
return -1;
}
-
+
if (::rename (oldpath.c_str(), newpath.c_str()) != 0) {
error << string_compose (_("cannot rename file %1 to %2 (%3)"), oldpath, newpath, strerror(errno)) << endmsg;
return -1;
_path = newpath;
}
-void
+void
FileSource::inc_use_count ()
{
Source::inc_use_count ();
}
-
+