fix minor problem with recent cherry-picking from cairocanvas
[ardour.git] / libs / ardour / file_source.cc
index 0aa0a4ade82bfc78841e3181433ea27de5c34768..de2783a1acc5cb908074b182f49f28ee220cf1cb 100644 (file)
@@ -62,8 +62,6 @@ FileSource::FileSource (Session& session, DataType type, const string& path, con
         , _open (false)
 {
        set_within_session_from_path (path);
-
-        prevent_deletion ();
 }
 
 FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist*/)
@@ -77,23 +75,28 @@ FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist
 
        _path = _name;
        _within_session = true;
+}
 
-        prevent_deletion ();
+FileSource::~FileSource()
+{
 }
 
 void
-FileSource::prevent_deletion ()
+FileSource::existence_check ()
 {
-        /* if this file already exists, it cannot be removed, ever
-         */
-
         if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)) {
-                if (!(_flags & Destructive)) {
-                        mark_immutable ();
-                } else {
-                        _flags = Flag (_flags & ~(Removable|RemovableIfEmpty|RemoveAtDestroy));
-                }
-        }
+               prevent_deletion ();
+       }
+}
+
+void
+FileSource::prevent_deletion ()
+{
+       if (!(_flags & Destructive)) {
+               mark_immutable ();
+       } else {
+               _flags = Flag (_flags & ~(Removable|RemovableIfEmpty|RemoveAtDestroy));
+       }
 }
 
 bool
@@ -101,7 +104,7 @@ FileSource::removable () const
 {
         bool r = ((_flags & Removable)
                   && ((_flags & RemoveAtDestroy) ||
-                      ((_flags & RemovableIfEmpty) && empty() == 0)));
+                      ((_flags & RemovableIfEmpty) && empty())));
 
         return r;
 }
@@ -111,8 +114,6 @@ FileSource::init (const string& pathstr, bool must_exist)
 {
        _timeline_position = 0;
 
-       cerr << "FileSource looking for " << pathstr << endl;
-       
        if (Stateful::loading_state_version < 3000) {
                if (!find_2X (_session, _type, pathstr, must_exist, _file_is_new, _channel, _path)) {
                        throw MissingSource (pathstr, _type);
@@ -520,35 +521,6 @@ out:
        return ret;
 }
 
-int
-FileSource::set_source_name (const string& newname, bool destructive)
-{
-       Glib::Threads::Mutex::Lock lm (_lock);
-       string oldpath = _path;
-       string newpath = _session.change_source_path_by_name (oldpath, _name, newname, destructive);
-
-       if (newpath.empty()) {
-               error << string_compose (_("programming error: %1"), "cannot generate a changed file path") << endmsg;
-               return -1;
-       }
-
-       // Test whether newpath exists, if yes notify the user but continue.
-       if (Glib::file_test (newpath, Glib::FILE_TEST_EXISTS)) {
-               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;
-        }
-
-       _name = Glib::path_get_basename (newpath);
-       _path = newpath;
-
-       return 0;
-}
-
 void
 FileSource::mark_immutable ()
 {
@@ -591,3 +563,21 @@ FileSource::inc_use_count ()
         Source::inc_use_count ();
 }
 
+bool
+FileSource::is_stub () const
+{
+       if (!empty()) {
+               return false;
+       }
+       
+       if (!removable()) {
+               return false;
+       }
+
+       if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)) {
+               return false;
+       }
+
+       return true;
+}
+