Skip to content

Commit

Permalink
convert string to fs::path
Browse files Browse the repository at this point in the history
Avoids conversions

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Dec 1, 2021
1 parent 770d7d0 commit f745f48
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/content/scripting/script.cc
Expand Up @@ -360,7 +360,7 @@ void Script::defineFunctions(const duk_function_list_entry* functions)
duk_pop(ctx);
}

void Script::_load(const std::string& scriptPath)
void Script::_load(const fs::path& scriptPath)
{
std::string scriptText = GrbFile(scriptPath).readTextFile();

Expand All @@ -377,11 +377,11 @@ void Script::_load(const std::string& scriptPath)
duk_push_string(ctx, scriptPath.c_str());
if (duk_pcompile_lstring_filename(ctx, 0, scriptText.c_str(), scriptText.length()) != 0) {
log_error("Failed to load script: {}", duk_safe_to_string(ctx, -1));
throw_std_runtime_error("Scripting: failed to compile {}", scriptPath);
throw_std_runtime_error("Scripting: failed to compile {}", scriptPath.c_str());
}
}

void Script::load(const std::string& scriptPath)
void Script::load(const fs::path& scriptPath)
{
ScriptingRuntime::AutoLock lock(runtime->getMutex());
duk_push_thread_stash(ctx, ctx);
Expand Down
5 changes: 3 additions & 2 deletions src/content/scripting/script.h
Expand Up @@ -37,6 +37,7 @@

#include "common.h"
#include "context.h"
#include "util/grb_fs.h"

// forward declaration
class CdsObject;
Expand Down Expand Up @@ -78,7 +79,7 @@ class Script {

void defineFunction(const std::string& name, duk_c_function function, std::uint32_t numParams);
void defineFunctions(const duk_function_list_entry* functions);
void load(const std::string& scriptPath);
void load(const fs::path& scriptPath);

std::shared_ptr<CdsObject> dukObject2cdsObject(const std::shared_ptr<CdsObject>& pcd);
void cdsObject2dukObject(const std::shared_ptr<CdsObject>& obj);
Expand Down Expand Up @@ -116,7 +117,7 @@ class Script {
private:
std::string entrySeparator;
std::string name;
void _load(const std::string& scriptPath);
void _load(const fs::path& scriptPath);
void _execute();
std::unique_ptr<StringConverter> _p2i;
std::unique_ptr<StringConverter> _j2i;
Expand Down
6 changes: 3 additions & 3 deletions src/database/mysql/mysql_database.cc
Expand Up @@ -150,9 +150,9 @@ void MySQLDatabase::init()

if (dbVersion.empty()) {
log_info("Database doesn't seem to exist. Creating database...");
auto sqlFilePath = config->getOption(CFG_SERVER_STORAGE_MYSQL_INIT_SQL_FILE);
log_debug("Loading initialisation SQL from: {}", sqlFilePath);
auto sql = GrbFile(sqlFilePath).readTextFile();
auto sqlFilePath = fs::path(config->getOption(CFG_SERVER_STORAGE_MYSQL_INIT_SQL_FILE));
log_debug("Loading initialisation SQL from: {}", sqlFilePath.c_str());
auto sql = GrbFile(std::move(sqlFilePath)).readTextFile();
auto&& myHash = stringHash(sql);

if (myHash == hashies[0]) {
Expand Down
2 changes: 1 addition & 1 deletion src/database/sql_database.cc
Expand Up @@ -2043,7 +2043,7 @@ void SQLDatabase::updateAutoscanList(ScanMode scanmode, const std::shared_ptr<Au
// the scanmode should match the given parameter
assert(ad->getScanMode() == scanmode);

std::string location = ad->getLocation();
fs::path location = ad->getLocation();
if (location.empty())
throw_std_runtime_error("AutoscanDirectoy with illegal location given to SQLDatabase::updateAutoscanPersistentList");

Expand Down
6 changes: 3 additions & 3 deletions src/database/sqlite3/sqlite_database.cc
Expand Up @@ -424,9 +424,9 @@ void SLInitTask::run(sqlite3*& db, Sqlite3Database* sl)
if (res != SQLITE_OK)
throw DatabaseException("", "SQLite: Failed to create new database");

auto sqlFilePath = config->getOption(CFG_SERVER_STORAGE_SQLITE_INIT_SQL_FILE);
log_debug("Loading initialisation SQL from: {}", sqlFilePath);
auto sql = GrbFile(sqlFilePath).readTextFile();
auto sqlFilePath = fs::path(config->getOption(CFG_SERVER_STORAGE_SQLITE_INIT_SQL_FILE));
log_debug("Loading initialisation SQL from: {}", sqlFilePath.c_str());
auto sql = GrbFile(std::move(sqlFilePath)).readTextFile();
auto&& myHash = stringHash(sql);

if (myHash == hashie) {
Expand Down
4 changes: 2 additions & 2 deletions src/server.cc
Expand Up @@ -269,7 +269,7 @@ void Server::writeBookmark(const std::string& addr)

fs::path path = config->getOption(CFG_SERVER_BOOKMARK_FILE);
log_debug("Writing bookmark file to: {}", path.c_str());
GrbFile(path).writeTextFile(data);
GrbFile(std::move(path)).writeTextFile(data);
}

void Server::emptyBookmark()
Expand All @@ -278,7 +278,7 @@ void Server::emptyBookmark()

fs::path path = config->getOption(CFG_SERVER_BOOKMARK_FILE);
log_debug("Clearing bookmark file at: {}", path.c_str());
GrbFile(path).writeTextFile(data);
GrbFile(std::move(path)).writeTextFile(data);
}

std::string Server::getVirtualUrl() const
Expand Down
4 changes: 2 additions & 2 deletions src/transcoding/transcode_dispatcher.cc
Expand Up @@ -37,12 +37,12 @@
#include "transcoding.h"

std::unique_ptr<IOHandler> TranscodeDispatcher::serveContent(const std::shared_ptr<TranscodingProfile>& profile,
std::string location,
fs::path location,
const std::shared_ptr<CdsObject>& obj,
const std::string& range)
{
if (!profile)
throw_std_runtime_error("Transcoding of file {} requested but no profile given ", location);
throw_std_runtime_error("Transcoding of file {} requested but no profile given ", location.c_str());

if (profile->getType() == TR_External) {
auto trExt = std::make_unique<TranscodeExternalHandler>(std::move(content));
Expand Down
2 changes: 1 addition & 1 deletion src/transcoding/transcode_dispatcher.h
Expand Up @@ -40,7 +40,7 @@ class TranscodeDispatcher : public TranscodeHandler {

public:
std::unique_ptr<IOHandler> serveContent(const std::shared_ptr<TranscodingProfile>& profile,
std::string location,
fs::path location,
const std::shared_ptr<CdsObject>& obj,
const std::string& range) override;
};
Expand Down
8 changes: 4 additions & 4 deletions src/transcoding/transcode_ext_handler.cc
Expand Up @@ -51,11 +51,11 @@
#endif

std::unique_ptr<IOHandler> TranscodeExternalHandler::serveContent(const std::shared_ptr<TranscodingProfile>& profile,
std::string location, const std::shared_ptr<CdsObject>& obj, const std::string& range)
fs::path location, const std::shared_ptr<CdsObject>& obj, const std::string& range)
{
log_debug("Start transcoding file: {}", location);
log_debug("Start transcoding file: {}", location.c_str());
if (!profile)
throw_std_runtime_error("Transcoding of file {} requested but no profile given", location);
throw_std_runtime_error("Transcoding of file {} requested but no profile given", location.c_str());

#if 0
std::string mimeType = profile->getTargetMimeType();
Expand Down Expand Up @@ -147,7 +147,7 @@ void TranscodeExternalHandler::checkTranscoder(const std::shared_ptr<Transcoding
}

#ifdef HAVE_CURL
void TranscodeExternalHandler::openCurlFifo(std::string& location, std::vector<std::shared_ptr<ProcListItem>>& procList)
void TranscodeExternalHandler::openCurlFifo(fs::path& location, std::vector<std::shared_ptr<ProcListItem>>& procList)
{
std::string url = location;
log_debug("creating reader fifo: {}", location.c_str());
Expand Down
4 changes: 2 additions & 2 deletions src/transcoding/transcode_ext_handler.h
Expand Up @@ -45,15 +45,15 @@ class TranscodeExternalHandler : public TranscodeHandler {

public:
std::unique_ptr<IOHandler> serveContent(const std::shared_ptr<TranscodingProfile>& profile,
std::string location,
fs::path location,
const std::shared_ptr<CdsObject>& obj,
const std::string& range) override;

private:
fs::path makeFifo();
static void checkTranscoder(const std::shared_ptr<TranscodingProfile>& profile);
#ifdef HAVE_CURL
void openCurlFifo(std::string& location, std::vector<std::shared_ptr<ProcListItem>>& procList);
void openCurlFifo(fs::path& location, std::vector<std::shared_ptr<ProcListItem>>& procList);
#endif
};

Expand Down
3 changes: 2 additions & 1 deletion src/transcoding/transcode_handler.h
Expand Up @@ -37,6 +37,7 @@
#include <upnp.h>

#include "common.h"
#include "util/grb_fs.h"

// forward declaration
class CdsObject;
Expand All @@ -51,7 +52,7 @@ class TranscodeHandler {
virtual ~TranscodeHandler() = default;

virtual std::unique_ptr<IOHandler> serveContent(const std::shared_ptr<TranscodingProfile>& profile,
std::string location,
fs::path location,
const std::shared_ptr<CdsObject>& obj,
const std::string& range)
= 0;
Expand Down

0 comments on commit f745f48

Please sign in to comment.