, _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*/)
_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;
}
}
}
- 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;
_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)
{