Use the new assert that doesn't crash the program in a release build

This commit is contained in:
Sebastian Messmer 2015-07-22 13:47:19 +02:00
parent 013d50d8b6
commit bfa07cba69
6 changed files with 7 additions and 9 deletions

View File

@ -67,7 +67,7 @@ CryDevice::~CryDevice() {
}
optional<unique_ref<fspp::Node>> CryDevice::Load(const bf::path &path) {
assert(path.is_absolute());
ASSERT(path.is_absolute(), "Non absolute path given");
if (path.parent_path().empty()) {
//We are asked to load the root directory '/'.

View File

@ -27,7 +27,7 @@ CryFile::~CryFile() {
unique_ref<fspp::OpenFile> CryFile::open(int flags) const {
auto blob = LoadBlob();
assert(blob != none);
ASSERT(blob != none, "Couldn't load blob");
return make_unique_ref<CryOpenFile>(make_unique_ref<FileBlob>(std::move(*blob)));
}

View File

@ -28,7 +28,7 @@ namespace cryfs {
DirBlob::DirBlob(unique_ref<Blob> blob, CryDevice *device) :
_device(device), _blob(std::move(blob)), _entries(), _changed(false) {
//TODO generally everywhere: asserts are bad, because they crash the filesystem. Rather return a fuse error!
assert(magicNumber() == MagicNumbers::DIR);
ASSERT(magicNumber() == MagicNumbers::DIR, "Loaded blob is not a directory");
_readEntriesFromBlob();
}
@ -224,7 +224,7 @@ void DirBlob::statChild(const Key &key, struct ::stat *result) const {
result->st_size = SymlinkBlob(std::move(*blob)).target().native().size();
}
} else {
assert(false);
ASSERT(false, "Unknown child type");
}
//TODO Move ceilDivision to general utils which can be used by cryfs as well
result->st_blocks = blobstore::onblocks::utils::ceilDivision(result->st_size, 512);
@ -233,7 +233,7 @@ void DirBlob::statChild(const Key &key, struct ::stat *result) const {
void DirBlob::chmodChild(const Key &key, mode_t mode) {
auto found = _findChild(key);
assert ((S_ISREG(mode) && S_ISREG(found->mode)) || (S_ISDIR(mode) && S_ISDIR(found->mode)) || (S_ISLNK(mode)));
ASSERT ((S_ISREG(mode) && S_ISREG(found->mode)) || (S_ISDIR(mode) && S_ISDIR(found->mode)) || (S_ISLNK(mode)), "Unknown mode in entry");
found->mode = mode;
_changed = true;
}

View File

@ -28,7 +28,7 @@ public:
mode |= S_IFLNK;
break;
}
assert((S_ISREG(mode) && type == fspp::Dir::EntryType::FILE) || (S_ISDIR(mode) && type == fspp::Dir::EntryType::DIR) || (S_ISLNK(mode) && type == fspp::Dir::EntryType::SYMLINK));
ASSERT((S_ISREG(mode) && type == fspp::Dir::EntryType::FILE) || (S_ISDIR(mode) && type == fspp::Dir::EntryType::DIR) || (S_ISLNK(mode) && type == fspp::Dir::EntryType::SYMLINK), "Unknown mode in entry");
}
fspp::Dir::EntryType type;

View File

@ -18,7 +18,6 @@ FileBlob::~FileBlob() {
}
unique_ref<FileBlob> FileBlob::InitializeEmptyFile(unique_ref<Blob> blob) {
assert(blob.get() != nullptr);
blob->resize(1);
unsigned char magicNumber = MagicNumbers::FILE;
blob->write(&magicNumber, 0, 1);

View File

@ -24,7 +24,6 @@ SymlinkBlob::~SymlinkBlob() {
}
unique_ref<SymlinkBlob> SymlinkBlob::InitializeSymlink(unique_ref<Blob> blob, const bf::path &target) {
assert(blob.get() != nullptr);
string targetStr = target.native();
blob->resize(1 + targetStr.size());
unsigned char magicNumber = MagicNumbers::SYMLINK;
@ -36,7 +35,7 @@ unique_ref<SymlinkBlob> SymlinkBlob::InitializeSymlink(unique_ref<Blob> blob, co
void SymlinkBlob::_checkMagicNumber(const Blob &blob) {
unsigned char value;
blob.read(&value, 0, 1);
assert(value == MagicNumbers::SYMLINK);
ASSERT(value == MagicNumbers::SYMLINK, "Blob is not a symlink blob");
}
bf::path SymlinkBlob::_readTargetFromBlob(const blobstore::Blob &blob) {