From: Mikko Rasa Date: Sat, 5 Jan 2013 11:03:59 +0000 (+0200) Subject: Use IO::Slice to constrain access to logical files X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e44432ecb5d2c0a288652ac6ed9d06f51a68d395;p=libs%2Fdatafile.git Use IO::Slice to constrain access to logical files --- diff --git a/source/packsource.cpp b/source/packsource.cpp index d054e1d..d22c7dc 100644 --- a/source/packsource.cpp +++ b/source/packsource.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "collection.h" @@ -5,6 +6,15 @@ using namespace std; +namespace { + +void delete_io(Msp::IO::Base *io) +{ + delete io; +} + +} + namespace Msp { namespace DataFile { @@ -120,9 +130,10 @@ PackSource::File::File(const Pack &p, const string &fn): RefPtr PackSource::File::open() const { - RefPtr io_file = new IO::BufferedFile(pack.get_filename()); - io_file->seek(pack.get_base_offset()+offset, IO::S_BEG); - return io_file; + IO::BufferedFile *io_file = new IO::BufferedFile(pack.get_filename()); + IO::Slice *io_slice = new IO::Slice(*io_file, pack.get_base_offset()+offset, length); + io_slice->signal_deleted.connect(sigc::bind(sigc::ptr_fun(delete_io), io_file)); + return io_slice; } string PackSource::File::get_full_name() const