Replace connection cerr dumping with DEBUG_TRACE.
[ardour.git] / libs / ardour / file_source.cc
index 264d6482b46b7988083056cb09d93c89e9418ed9..5522031d691d6438db88fc9f513adc311bca9635 100644 (file)
@@ -60,8 +60,11 @@ FileSource::FileSource (Session& session, DataType type, const string& path, con
        , _file_is_new(true)
        , _channel (0)
         , _origin (origin)
+        , _open (false)
 {
        set_within_session_from_path (path);
+
+        prevent_deletion ();
 }
 
 FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist*/)
@@ -75,16 +78,32 @@ FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist
 
        _path = _name;
        _within_session = true;
+
+        prevent_deletion ();
+}
+
+void
+FileSource::prevent_deletion ()
+{
+        /* 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));
+                }
+        }
 }
 
 bool
 FileSource::removable () const
 {
-        bool r = (_path.find (stub_dir_name) != string::npos) ||
-                ((_flags & Removable)
-                 && ((_flags & RemoveAtDestroy) || 
-                     ((_flags & RemovableIfEmpty) && empty() == 0)));
-
+        bool r = ((_flags & Removable)
+                  && ((_flags & RemoveAtDestroy) || 
+                      ((_flags & RemovableIfEmpty) && empty() == 0)));
+        
         return r;
 }
 
@@ -103,13 +122,13 @@ FileSource::init (const string& pathstr, bool must_exist)
                 }
         }
 
-       set_within_session_from_path (pathstr);
+       set_within_session_from_path (_path);
 
         if (!within_session()) {
-                _session.ensure_search_path_includes (Glib::path_get_dirname (pathstr), _type);
+                _session.ensure_search_path_includes (Glib::path_get_dirname (_path), _type);
         }
 
-        _name = Glib::path_get_basename (pathstr);
+        _name = Glib::path_get_basename (_path);
 
        if (_file_is_new && must_exist) {
                return -1;
@@ -518,32 +537,6 @@ FileSource::set_within_session_from_path (const std::string& path)
        _within_session = _session.path_is_within_session (path);
 }
 
-int
-FileSource::unstubify ()
-{
-        string::size_type pos = _path.find (stub_dir_name);
-
-        if (pos == string::npos || (_flags & Destructive)) {
-                return 0;
-        }
-
-        vector<string> v;
-
-        v.push_back (Glib::path_get_dirname (Glib::path_get_dirname (_path)));
-       v.push_back (Glib::path_get_basename(_path));
-        
-        string newpath = Glib::build_filename (v);
-
-        if (::rename (_path.c_str(), newpath.c_str()) != 0) {
-                error << string_compose (_("rename from %1 to %2 failed: %3)"), _path, newpath, strerror (errno)) << endmsg;
-                return -1;
-        }
-
-        set_path (newpath);
-
-        return 0;
-}
-
 void
 FileSource::set_path (const std::string& newpath)
 {