modernize: unindent else after return

This commit is contained in:
Valient Gough 2017-08-03 22:43:14 -07:00
parent c37ab8e671
commit f9d22c4f18
No known key found for this signature in database
GPG Key ID: 33C65E29813C14DF
15 changed files with 148 additions and 190 deletions

View File

@ -73,7 +73,7 @@ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const {
if (_cache.dataLen < len) len = _cache.dataLen; // Don't read past EOF
memcpy(req.data, _cache.data, len);
return len;
} else {
}
if (_cache.dataLen > 0) clearCache(_cache, _blockSize);
// cache results of read -- issue reads for full blocks
@ -92,7 +92,6 @@ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const {
}
return result;
}
}
bool BlockFileIO::cacheWriteOneBlock(const IORequest &req) {
// cache results of write (before pass-thru, because it may be modified
@ -123,7 +122,7 @@ ssize_t BlockFileIO::read(const IORequest &req) const {
// read completely within a single block -- can be handled as-is by
// readOneBlock().
return cacheReadOneBlock(req);
} else {
}
size_t size = req.dataLen;
// if the request is larger then a block, then request each block
@ -167,7 +166,6 @@ ssize_t BlockFileIO::read(const IORequest &req) const {
}
if (mb.data != nullptr) MemoryPool::release(mb);
}
return result;
}

View File

@ -91,9 +91,8 @@ Interface BlockNameIO::CurrentInterface(bool caseInsensitive) {
// implement major version 4 plus support for two prior versions
if (caseInsensitive) {
return Interface("nameio/block32", 4, 0, 2);
} else {
return Interface("nameio/block", 4, 0, 2);
}
return Interface("nameio/block", 4, 0, 2);
}
BlockNameIO::BlockNameIO(const Interface &iface, std::shared_ptr<Cipher> cipher,
@ -121,9 +120,8 @@ int BlockNameIO::maxEncodedNameLen(int plaintextNameLen) const {
int encodedNameLen = numBlocks * _bs + 2; // 2 checksum bytes
if (_caseInsensitive) {
return B256ToB32Bytes(encodedNameLen);
} else {
return B256ToB64Bytes(encodedNameLen);
}
return B256ToB64Bytes(encodedNameLen);
}
int BlockNameIO::maxDecodedNameLen(int encodedNameLen) const {

View File

@ -105,11 +105,10 @@ bool CipherFileIO::setIV(uint64_t iv) {
// duh -- there are no file headers for directories!
externalIV = iv;
return base->setIV(iv);
} else {
}
VLOG(1) << "writeHeader failed to re-open for write";
return false;
}
}
initHeader();
}
@ -391,9 +390,8 @@ bool CipherFileIO::blockWrite(unsigned char *buf, int size,
VLOG(1) << "Called blockWrite";
if (!fsConfig->reverseEncryption) {
return cipher->blockEncode(buf, size, _iv64, key);
} else {
return cipher->blockDecode(buf, size, _iv64, key);
}
return cipher->blockDecode(buf, size, _iv64, key);
}
bool CipherFileIO::streamWrite(unsigned char *buf, int size,
@ -401,16 +399,15 @@ bool CipherFileIO::streamWrite(unsigned char *buf, int size,
VLOG(1) << "Called streamWrite";
if (!fsConfig->reverseEncryption) {
return cipher->streamEncode(buf, size, _iv64, key);
} else {
return cipher->streamDecode(buf, size, _iv64, key);
}
return cipher->streamDecode(buf, size, _iv64, key);
}
bool CipherFileIO::blockRead(unsigned char *buf, int size,
uint64_t _iv64) const {
if (fsConfig->reverseEncryption) {
return cipher->blockEncode(buf, size, _iv64, key);
} else {
}
if (_allowHoles) {
// special case - leave all 0's alone
for (int i = 0; i < size; ++i) {
@ -418,19 +415,16 @@ bool CipherFileIO::blockRead(unsigned char *buf, int size,
}
return true;
} else {
}
return cipher->blockDecode(buf, size, _iv64, key);
}
}
}
bool CipherFileIO::streamRead(unsigned char *buf, int size,
uint64_t _iv64) const {
if (fsConfig->reverseEncryption) {
return cipher->streamEncode(buf, size, _iv64, key);
} else {
return cipher->streamDecode(buf, size, _iv64, key);
}
return cipher->streamDecode(buf, size, _iv64, key);
}
int CipherFileIO::truncate(off_t size) {
@ -519,12 +513,11 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const {
VLOG(1) << "read " << readBytes << " bytes from backing file";
if (readBytes < 0) {
return readBytes; // Return error code
} else {
}
ssize_t sum = headerBytes + readBytes;
VLOG(1) << "returning sum=" << sum;
return sum;
}
}
bool CipherFileIO::isWritable() const { return base->isWritable(); }

View File

@ -129,9 +129,8 @@ ConfigVar ConfigReader::operator[](const std::string &varName) const {
auto it = vars.find(varName);
if (it == vars.end()) {
return ConfigVar();
} else {
return it->second;
}
return it->second;
}
ConfigVar &ConfigReader::operator[](const std::string &varName) {

View File

@ -45,9 +45,8 @@ ConfigVar::~ConfigVar() { pd.reset(); }
ConfigVar &ConfigVar::operator=(const ConfigVar &src) {
if (src.pd == pd) {
return *this;
} else {
pd = src.pd;
}
pd = src.pd;
return *this;
}
@ -142,9 +141,8 @@ int ConfigVar::readInt(int defaultValue) const {
if (offset >= bytes) {
return defaultValue;
} else {
return readInt();
}
return readInt();
}
bool ConfigVar::readBool(bool defaultValue) const {

View File

@ -81,11 +81,10 @@ static bool _nextName(struct dirent *&de, const std::shared_ptr<DIR> &dir,
}
if (inode != nullptr) *inode = de->d_ino;
return true;
} else {
}
if (fileType != nullptr) *fileType = 0;
return false;
}
}
std::string DirTraverse::nextPlaintextName(int *fileType, ino_t *inode) {
struct dirent *de = nullptr;
@ -350,7 +349,7 @@ DirTraverse DirNode::openDir(const char *plaintextPath) {
if (dir == nullptr) {
VLOG(1) << "opendir error " << strerror(errno);
return DirTraverse(shared_ptr<DIR>(), 0, std::shared_ptr<NameIO>());
} else {
}
std::shared_ptr<DIR> dp(dir, DirDeleter());
uint64_t iv = 0;
@ -363,7 +362,6 @@ DirTraverse DirNode::openDir(const char *plaintextPath) {
}
return DirTraverse(dp, iv, naming);
}
}
bool DirNode::genRenameList(list<RenameEl> &renameList, const char *fromP,
const char *toP) {
@ -477,9 +475,8 @@ std::shared_ptr<RenameOp> DirNode::newRenameOp(const char *fromP,
if (!genRenameList(*renameList.get(), fromP, toP)) {
RLOG(WARNING) << "Error during generation of recursive rename list";
return std::shared_ptr<RenameOp>();
} else {
return std::make_shared<RenameOp>(this, renameList);
}
return std::make_shared<RenameOp>(this, renameList);
}
int DirNode::mkdir(const char *plaintextPath, mode_t mode, uid_t uid,
@ -679,9 +676,8 @@ std::shared_ptr<FileNode> DirNode::openNode(const char *plainName,
if (node && (*result = node->open(flags)) >= 0) {
return node;
} else {
return std::shared_ptr<FileNode>();
}
return std::shared_ptr<FileNode>();
}
int DirNode::unlink(const char *plaintextName) {

View File

@ -102,9 +102,8 @@ static bool setIV(const std::shared_ptr<FileIO> &io, uint64_t iv) {
struct stat stbuf;
if ((io->getAttr(&stbuf) < 0) || S_ISREG(stbuf.st_mode)) {
return io->setIV(iv);
} else {
return true;
}
return true;
}
bool FileNode::setName(const char *plaintextName_, const char *cipherName_,
@ -261,9 +260,8 @@ int FileNode::sync(bool datasync) {
if (res == -1) res = -errno;
return res;
} else {
return fh;
}
return fh;
}
} // namespace encfs

View File

@ -127,27 +127,24 @@ bool fileExists(const char *fileName) {
struct stat buf;
if (lstat(fileName, &buf) == 0) {
return true;
} else {
}
// XXX show perror?
return false;
}
}
bool isDirectory(const char *fileName) {
struct stat buf;
if (lstat(fileName, &buf) == 0) {
return S_ISDIR(buf.st_mode);
} else {
return false;
}
return false;
}
bool isAbsolutePath(const char *fileName) {
if ((fileName != nullptr) && fileName[0] != '\0' && fileName[0] == '/') {
return true;
} else {
return false;
}
return false;
}
const char *lastPathElement(const char *name) {
@ -159,9 +156,8 @@ std::string parentDirectory(const std::string &path) {
size_t last = path.find_last_of('/');
if (last == string::npos) {
return string("");
} else {
return path.substr(0, last);
}
return path.substr(0, last);
}
bool userAllowMkdir(const char *path, mode_t mode) {
@ -196,15 +192,13 @@ bool userAllowMkdir(int promptno, const char *path, mode_t mode) {
if (result < 0) {
perror(_("Unable to create directory: "));
return false;
} else {
}
return true;
}
} else {
// Directory not created, by user request
cerr << _("Directory not created.") << "\n";
return false;
}
}
/**
* Load config file by calling the load function on the filename
@ -842,10 +836,12 @@ static bool boolDefault(const char *prompt, bool defaultValue) {
if (cin.fail() || response == "") {
value = defaultValue;
break;
} else if (response == "y") {
}
if (response == "y") {
value = true;
break;
} else if (response == "n") {
}
if (response == "n") {
value = false;
break;
}
@ -1119,10 +1115,9 @@ RootPtr createV6Config(EncFS_Context *ctx,
_("Unable to instanciate cipher %s, key size %i, block size %i"),
alg.name.c_str(), keySize, blockSize);
return rootInfo;
} else {
}
VLOG(1) << "Using cipher " << alg.name << ", key size " << keySize
<< ", block size " << blockSize;
}
std::shared_ptr<EncFSConfig> config(new EncFSConfig);
@ -1672,10 +1667,9 @@ int remountFS(EncFS_Context *ctx) {
if (rootInfo) {
ctx->setRoot(rootInfo->root);
return 0;
} else {
}
RLOG(WARNING) << "Remount failed";
return -EACCES;
}
}
} // namespace encfs

View File

@ -85,11 +85,11 @@ static int sign( int a, int b )
static int sign(int a, int b) {
if (a < b) {
return 0;
} else if (a == b) {
return 1;
} else {
return 2;
}
if (a == b) {
return 1;
}
return 2;
}
#endif
@ -117,33 +117,29 @@ bool Interface::implements(const Interface &B) const {
bool operator<(const Interface &A, const Interface &B) {
if (A.name() == B.name()) {
return (diffSum(A, B) < EqualVersion);
} else {
return A.name() < B.name();
}
return A.name() < B.name();
}
bool operator>(const Interface &A, const Interface &B) {
if (A.name() == B.name()) {
return (diffSum(A, B) > EqualVersion);
} else {
return A.name() < B.name();
}
return A.name() < B.name();
}
bool operator<=(const Interface &A, const Interface &B) {
if (A.name() == B.name()) {
return (diffSum(A, B) <= EqualVersion);
} else {
return A.name() < B.name();
}
return A.name() < B.name();
}
bool operator>=(const Interface &A, const Interface &B) {
if (A.name() == B.name()) {
return (diffSum(A, B) >= EqualVersion);
} else {
return A.name() < B.name();
}
return A.name() < B.name();
}
ConfigVar &operator<<(ConfigVar &dst, const Interface &iface) {

View File

@ -185,14 +185,12 @@ off_t RawFileIO::getSize() const {
const_cast<RawFileIO *>(this)->fileSize = stbuf.st_size;
const_cast<RawFileIO *>(this)->knownSize = true;
return fileSize;
} else {
}
RLOG(ERROR) << "getSize on " << name << " failed: " << strerror(errno);
return -1;
}
} else {
return fileSize;
}
}
ssize_t RawFileIO::read(const IORequest &req) const {
rAssert(fd >= 0);
@ -237,7 +235,7 @@ bool RawFileIO::write(const IORequest &req) {
<< req.dataLen << ", max retries reached";
knownSize = false;
return false;
} else {
}
if (knownSize) {
off_t last = req.offset + req.dataLen;
if (last > fileSize) fileSize = last;
@ -245,7 +243,6 @@ bool RawFileIO::write(const IORequest &req) {
return true;
}
}
int RawFileIO::truncate(off_t size) {
int res;

View File

@ -368,9 +368,9 @@ CipherKey SSL_Cipher::newKey(const char *password, int passwdLength,
if (res <= 0) {
RLOG(WARNING) << "openssl error, PBKDF2 failed";
return CipherKey();
} else {
iterationCount = res;
}
iterationCount = res;
} else {
// known iteration length
if (PKCS5_PBKDF2_HMAC_SHA1(
@ -510,9 +510,8 @@ bool SSL_Cipher::randomize(unsigned char *buf, int len,
}
return false;
} else {
return true;
}
return true;
}
uint64_t SSL_Cipher::MAC_64(const unsigned char *data, int len,
@ -599,9 +598,8 @@ bool SSL_Cipher::compareKey(const CipherKey &A, const CipherKey &B) const {
if (memcmp(key1->buffer, key2->buffer, _keySize + _ivLength) != 0) {
return false;
} else {
return true;
}
return true;
}
int SSL_Cipher::encodedKeySize() const {

View File

@ -146,18 +146,15 @@ class XmlNode : virtual public XmlValue {
const char *value = element->Attribute(name + 1);
if (value != nullptr) {
return std::make_shared<encfs::XmlValue>(value);
} else {
}
return XmlValuePtr();
}
} else {
const tinyxml2::XMLElement *el = element->FirstChildElement(name);
if (el != nullptr) {
return XmlValuePtr(new XmlNode(el));
} else {
}
return XmlValuePtr();
}
}
}
};
struct XmlReader::XmlReaderData {

View File

@ -57,9 +57,8 @@ autosprintf::operator char *() const {
auto *copy = new char[length];
memcpy(copy, str, length);
return copy;
} else {
return nullptr;
}
return nullptr;
}
autosprintf::operator std::string() const {
return std::string(str != nullptr ? str : "(error in autosprintf)");

View File

@ -397,11 +397,10 @@ int _do_readlink(EncFS_Context *ctx, const string &cyName, char *buf,
buf[size - 1] = '\0';
return ESUCCESS;
} else {
}
RLOG(WARNING) << "Error decoding link";
return -1;
}
}
int encfs_readlink(const char *path, char *buf, size_t size) {
return withCipherPath("readlink", path,
@ -655,9 +654,8 @@ int encfs_fsync(const char *path, int dataSync, struct fuse_file_info *file) {
int _do_write(FileNode *fnode, unsigned char *ptr, size_t size, off_t offset) {
if (fnode->write(offset, ptr, size)) {
return size;
} else {
return -EIO;
}
return -EIO;
}
int encfs_write(const char *path, const char *buf, size_t size, off_t offset,

View File

@ -785,7 +785,7 @@ static bool unmountFS(EncFS_Context *ctx) {
ctx->setRoot(std::shared_ptr<DirNode>());
return false;
} else {
}
// Time to unmount!
#if FUSE_USE_VERSION < 30
fuse_unmount(arg->opts->mountPoint.c_str(), nullptr);
@ -796,4 +796,3 @@ static bool unmountFS(EncFS_Context *ctx) {
RLOG(INFO) << "Filesystem inactive, unmounted: " << arg->opts->mountPoint;
return true;
}
}