From e51541e5f02bf10f930afea171ca4966025e09a7 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 14 Feb 2011 15:58:17 +0000 Subject: [PATCH] prevent ardour from ever, EVER, EVAH removing an existing source file git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@8841 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/audiofilesource.h | 1 + libs/ardour/audiofilesource.cc | 23 ++++++++++++++++++++++- libs/ardour/sndfilesource.cc | 4 ++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libs/ardour/ardour/audiofilesource.h b/libs/ardour/ardour/audiofilesource.h index a3cebd1b35..b91ce79079 100644 --- a/libs/ardour/ardour/audiofilesource.h +++ b/libs/ardour/ardour/audiofilesource.h @@ -178,6 +178,7 @@ class AudioFileSource : public AudioSource { Glib::ustring broken_peak_path (Glib::ustring audio_path); void fix_writable_flags (); + void prevent_deletion (); }; } // namespace ARDOUR diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc index 9141456e22..ba5ab8a793 100644 --- a/libs/ardour/audiofilesource.cc +++ b/libs/ardour/audiofilesource.cc @@ -96,6 +96,7 @@ AudioFileSource::AudioFileSource (Session& s, ustring path, Flag flags) throw failed_constructor (); } + prevent_deletion (); fix_writable_flags (); } @@ -110,6 +111,7 @@ AudioFileSource::AudioFileSource (Session& s, ustring path, Flag flags, SampleFo throw failed_constructor (); } + prevent_deletion (); fix_writable_flags (); } @@ -129,6 +131,7 @@ AudioFileSource::AudioFileSource (Session& s, const XMLNode& node, bool must_exi throw failed_constructor (); } + prevent_deletion (); fix_writable_flags (); } @@ -140,9 +143,26 @@ AudioFileSource::~AudioFileSource () } } +void +AudioFileSource::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)); + } + } +} + void AudioFileSource::fix_writable_flags () { + /* if the session is not writable, neither is this file + */ if (!_session.writable()) { _flags = Flag (_flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy|CanRename)); } @@ -354,6 +374,7 @@ AudioFileSource::mark_for_remove () } _flags = Flag (_flags | Removable | RemoveAtDestroy); + } void @@ -466,6 +487,7 @@ AudioFileSource::move_to_trash (const ustring& trash_dir_name) _flags = Flag (_flags & ~(RemoveAtDestroy|Removable|RemovableIfEmpty)); + return 0; } @@ -775,7 +797,6 @@ AudioFileSource::mark_immutable () } } - Sample* AudioFileSource::get_interleave_buffer (nframes_t size) { diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc index 1759b4a6c1..2fa16d920d 100644 --- a/libs/ardour/sndfilesource.cc +++ b/libs/ardour/sndfilesource.cc @@ -633,7 +633,7 @@ bool SndFileSource::set_destructive (bool yn) { if (yn) { - _flags = Flag (_flags | Destructive); + _flags = Flag (_flags | Writable | Destructive); if (!xfade_buf) { xfade_buf = new Sample[xfade_frames]; } @@ -644,7 +644,7 @@ SndFileSource::set_destructive (bool yn) timeline_position = 0; /* leave xfade buf alone in case we need it again later */ } - + return true; }