40 : value(
"this-hash-value-is-empty")
56 return (value == other.
value);
61 return (value < other.
value);
64 std::string DataStorage::Hash::hash(
const std::string &value)
67 for (std::string::const_iterator iter = value.begin(); iter != value.end(); ++iter)
69 ss << std::hex << std::setw( 2 ) << std::setfill(
'0' ) << (int)(*iter);
75 : ibrcommon::File(file), _stream(NULL), _lock(mutex)
78 _stream =
new std::ifstream(
getPath().c_str(), ios_base::in | ios_base::binary);
94 : _callback(callback), _path(path), _tasks(), _store_sem(write_buffer), _store_limited(write_buffer > 0), _faulty(false)
103 std::list<ibrcommon::File> files;
106 for (std::list<ibrcommon::File>::iterator iter = files.begin(); iter != files.end(); ++iter)
108 (*iter).remove(
true);
128 Task *t = _tasks.
getnpop(
false);
138 JoinableThread::reset();
148 std::list<ibrcommon::File> files;
151 for (std::list<ibrcommon::File>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
153 if (!(*iter).isSystem())
166 if (_store_limited) _store_sem.
wait();
169 _tasks.
push(
new StoreDataTask(hash, data) );
194 _tasks.
push(
new RemoveDataTask(hash) );
212 Task *t = _tasks.
get(
true);
215 StoreDataTask &
store =
dynamic_cast<StoreDataTask&
>(*t);
222 std::ofstream stream(destination.
getPath().c_str(), ios::out | ios::binary | ios::trunc);
225 if (!stream.good() || _faulty)
227 std::stringstream ss; ss <<
"unable to open filestream [" << std::strerror(errno) <<
"]";
231 store._container->serialize(stream);
236 if (_store_limited) _store_sem.
post();
242 if (_store_limited) _store_sem.
post();
247 }
catch (
const std::bad_cast&) {
251 RemoveDataTask &
remove =
dynamic_cast<RemoveDataTask&
>(*t);
257 if (!destination.
exists())
267 }
catch (
const std::bad_cast&) {
280 DataStorage::Task::~Task() {}
282 DataStorage::StoreDataTask::StoreDataTask(
const Hash &
h, Container *c)
283 : hash(h), _container(c)
286 DataStorage::StoreDataTask::~StoreDataTask()
290 DataStorage::RemoveDataTask::RemoveDataTask(
const Hash &
h) : hash(h)
293 DataStorage::RemoveDataTask::~RemoveDataTask()