Write back DirBlob when baseBlob is released

This commit is contained in:
Sebastian Messmer 2015-10-05 18:54:51 +02:00
parent e5fcf6a9bc
commit e890222c77
3 changed files with 11 additions and 3 deletions

View File

@ -35,10 +35,12 @@ DirBlob::DirBlob(unique_ref<Blob> blob, std::function<off_t (const blockstore::K
}
DirBlob::~DirBlob() {
std::unique_lock<std::mutex> lock(_mutex);
_writeEntriesToBlob();
}
void DirBlob::flush() {
std::unique_lock<std::mutex> lock(_mutex);
_writeEntriesToBlob();
baseBlob().flush();
}
@ -76,7 +78,6 @@ void DirBlob::_serializeEntry(const DirBlob::Entry & entry, uint8_t *dest) {
}
void DirBlob::_writeEntriesToBlob() {
std::unique_lock<std::mutex> lock(_mutex);
if (_changed) {
size_t serializedSize = 0;
for (const auto &entry : _entries) {
@ -258,5 +259,10 @@ void DirBlob::setLstatSizeGetter(std::function<off_t(const blockstore::Key&)> ge
_getLstatSize = getLstatSize;
}
cpputils::unique_ref<blobstore::Blob> DirBlob::releaseBaseBlob() {
std::unique_lock<std::mutex> lock(_mutex);
_writeEntriesToBlob();
}
}
}

View File

@ -93,6 +93,8 @@ namespace cryfs {
static size_t _serializedSizeOfEntry(const DirBlob::Entry &entry);
static void _serializeEntry(const DirBlob::Entry &entry, uint8_t *dest);
cpputils::unique_ref<blobstore::Blob> releaseBaseBlob() override;
std::vector<DirBlob::Entry>::iterator _findChild(const blockstore::Key &key);
std::function<off_t (const blockstore::Key&)> _getLstatSize;

View File

@ -26,14 +26,14 @@ namespace cryfs {
private:
friend class FsBlobStore;
cpputils::unique_ref<blobstore::Blob> releaseBaseBlob();
virtual cpputils::unique_ref<blobstore::Blob> releaseBaseBlob();
cpputils::unique_ref<blobstore::Blob> _baseBlob;
DISALLOW_COPY_AND_ASSIGN(FsBlob);
};
// ---------------------------
// Inline function definitions
// ---------------------------