Skip to content

Commit

Permalink
clang-tidy: no else after return
Browse files Browse the repository at this point in the history
Found with llvm-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Jan 22, 2024
1 parent 7868f0c commit 319905a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 73 deletions.
34 changes: 16 additions & 18 deletions src/content/content_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,27 +474,25 @@ std::shared_ptr<CdsObject> ContentManager::_addFile(const fs::directory_entry& d
getImportService(asSetting.adir)->doImport(dirEnt.path(), asSetting, currentContent, task);

return getImportService(asSetting.adir)->getObject(dirEnt.path());
} else {
// checkDatabase, don't process existing
std::shared_ptr<CdsContainer> parent;
auto parentObject = database->findObjectByPath(dirEnt.path().parent_path(), DbFileType::Directory);
if (parentObject && parentObject->isContainer())
parent = std::dynamic_pointer_cast<CdsContainer>(parentObject);
auto obj = createSingleItem(dirEnt, parent, rootPath, asSetting.followSymlinks, true, false, false, asSetting.adir, task);
if (!obj) // object ignored
return obj;

if (asSetting.recursive && obj->isContainer()) {
addRecursive(asSetting.adir, dirEnt, std::dynamic_pointer_cast<CdsContainer>(obj), asSetting.followSymlinks, asSetting.hidden, task);
}
}
// checkDatabase, don't process existing
std::shared_ptr<CdsContainer> parent;
auto parentObject = database->findObjectByPath(dirEnt.path().parent_path(), DbFileType::Directory);
if (parentObject && parentObject->isContainer())
parent = std::dynamic_pointer_cast<CdsContainer>(parentObject);
auto obj = createSingleItem(dirEnt, parent, rootPath, asSetting.followSymlinks, true, false, false, asSetting.adir, task);
if (!obj) // object ignored
return obj;

if (asSetting.rescanResource && obj->hasResource(ContentHandler::RESOURCE)) {
std::string parentPath = dirEnt.path().parent_path();
updateAttachedResources(asSetting.adir, obj, parentPath, true);
}
if (asSetting.recursive && obj->isContainer())
addRecursive(asSetting.adir, dirEnt, std::dynamic_pointer_cast<CdsContainer>(obj), asSetting.followSymlinks, asSetting.hidden, task);

return obj;
if (asSetting.rescanResource && obj->hasResource(ContentHandler::RESOURCE)) {
std::string parentPath = dirEnt.path().parent_path();
updateAttachedResources(asSetting.adir, obj, parentPath, true);
}

return obj;
}

bool ContentManager::updateAttachedResources(const std::shared_ptr<AutoscanDirectory>& adir, const std::shared_ptr<CdsObject>& obj, const fs::path& parentPath, bool all)
Expand Down
13 changes: 6 additions & 7 deletions src/content/import_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,13 @@ bool ImportService::isHiddenFile(const fs::path& entryPath, bool isDirectory, co
auto noMediaFile = (isDirectory) ? entryPath / noMediaName : entryPath.parent_path() / noMediaName;
if (contentStateCache.find(noMediaFile) != contentStateCache.end()) {
return contentStateCache[entryPath]->getState() != ImportState::Broken; // broken means: file not found
}
auto noMediaEntry = fs::directory_entry(noMediaFile, ec);
if (!noMediaEntry.exists(ec) || ec) {
cacheState(noMediaEntry, noMediaEntry, ImportState::Broken, toSeconds(dirEntry.last_write_time(ec)));
} else {
auto noMediaEntry = fs::directory_entry(noMediaFile, ec);
if (!noMediaEntry.exists(ec) || ec) {
cacheState(noMediaEntry, noMediaEntry, ImportState::Broken, toSeconds(dirEntry.last_write_time(ec)));
} else {
// if file exists it will be automatically created
return true;
}
// if file exists it will be automatically created
return true;
}
}
return false;
Expand Down
72 changes: 26 additions & 46 deletions src/database/sqlite3/sqlite_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,15 @@ std::shared_ptr<SQLResult> Sqlite3Database::select(const std::string& query)
stask->waitForTask();
return stask->getResult();
} catch (const std::runtime_error& e) {
if (!shutdownFlag) {
if (dbInitDone) {
log_error("Prematurely shutting down.\n{}", e.what());
rollback("");
shutdown();
}
if (!dbInitDone)
throw_std_runtime_error(e.what());
} else {
if (dbInitDone) {
log_error("Already shutting down.\n{}", e.what());
return {};
} else
throw_std_runtime_error(e.what());
if (!shutdownFlag) {
log_error("Prematurely shutting down.\n{}", e.what());
rollback("");
shutdown();
}
log_error("Already shutting down.\n{}", e.what());
return {};
}
}

Expand All @@ -278,19 +273,14 @@ void Sqlite3Database::del(std::string_view tableName, const std::string& clause,
addTask(etask);
etask->waitForTask();
} catch (const std::runtime_error& e) {
if (!shutdownFlag) {
if (dbInitDone) {
log_error("Prematurely shutting down.\n{}", e.what());
rollback("");
shutdown();
}
if (!dbInitDone)
throw_std_runtime_error(e.what());
} else {
if (dbInitDone)
log_error("Already shutting down.\n{}", e.what());
else
throw_std_runtime_error(e.what());
if (!shutdownFlag) {
log_error("Prematurely shutting down.\n{}", e.what());
rollback("");
shutdown();
}
log_error("Already shutting down.\n{}", e.what());
}
}

Expand All @@ -303,19 +293,14 @@ void Sqlite3Database::exec(std::string_view tableName, const std::string& query,
addTask(etask);
etask->waitForTask();
} catch (const std::runtime_error& e) {
if (!shutdownFlag) {
if (dbInitDone) {
log_error("Prematurely shutting down.\n{}", e.what());
rollback("");
shutdown();
}
if (!dbInitDone)
throw_std_runtime_error(e.what());
} else {
if (dbInitDone)
log_error("Already shutting down.\n{}", e.what());
else
throw_std_runtime_error(e.what());
if (!shutdownFlag) {
log_error("Prematurely shutting down.\n{}", e.what());
rollback("");
shutdown();
}
log_error("Already shutting down.\n{}", e.what());
}
}

Expand All @@ -328,20 +313,15 @@ int Sqlite3Database::exec(const std::string& query, bool getLastInsertId)
etask->waitForTask();
return getLastInsertId ? etask->getLastInsertId() : -1;
} catch (const std::runtime_error& e) {
if (!shutdownFlag) {
if (dbInitDone) {
log_error("Prematurely shutting down.\n{}", e.what());
rollback("");
shutdown();
}
if (!dbInitDone)
throw_std_runtime_error(e.what());
} else {
if (dbInitDone) {
log_error("Already shutting down.\n{}", e.what());
return -1;
} else
throw_std_runtime_error(e.what());
if (!shutdownFlag) {
log_error("Prematurely shutting down.\n{}", e.what());
rollback("");
shutdown();
}
log_error("Already shutting down.\n{}", e.what());
return -1;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ void Server::run()
for (auto&& name : static_cast<Server*>(cookie)->validHosts) {
if (hostStr.find(name) != std::string::npos) {
return UPNP_E_SUCCESS;
} else if (name.find(hostStr) != std::string::npos) {
}
if (name.find(hostStr) != std::string::npos) {
return UPNP_E_SUCCESS;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/util/grb_net.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ std::string GrbNet::renderWebUri(std::string_view ip, in_port_t port)
return fmt::format("[{}]", ip);
}
return fmt::format("{}", ip);
} else if (ip.find(':') != std::string_view::npos) {
}
if (ip.find(':') != std::string_view::npos) {
return fmt::format("[{}]:{}", ip, port);
}
return fmt::format("{}:{}", ip, port);
Expand Down

0 comments on commit 319905a

Please sign in to comment.