Skip to content

Commit

Permalink
Simplified some path writes
Browse files Browse the repository at this point in the history
  • Loading branch information
epoupon committed Jan 6, 2025
1 parent 06a4db5 commit 10d900f
Show file tree
Hide file tree
Showing 25 changed files with 59 additions and 65 deletions.
8 changes: 4 additions & 4 deletions src/libs/av/impl/AudioFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ namespace lms::av
AudioFile::AudioFile(const std::filesystem::path& p)
: _p{ p }
{
int error{ avformat_open_input(&_context, _p.string().c_str(), nullptr, nullptr) };
int error{ avformat_open_input(&_context, _p.c_str(), nullptr, nullptr) };
if (error < 0)
{
LMS_LOG(AV, ERROR, "Cannot open " << _p.string() << ": " << averror_to_string(error));
LMS_LOG(AV, ERROR, "Cannot open " << _p << ": " << averror_to_string(error));
throw AudioFileException{ error };
}

error = avformat_find_stream_info(_context, nullptr);
if (error < 0)
{
LMS_LOG(AV, ERROR, "Cannot find stream information on " << _p.string() << ": " << averror_to_string(error));
LMS_LOG(AV, ERROR, "Cannot find stream information on " << _p << ": " << averror_to_string(error));
avformat_close_input(&_context);
throw AudioFileException{ error };
}
Expand Down Expand Up @@ -353,7 +353,7 @@ namespace lms::av
{ ".mka", "audio/x-matroska" },
};

auto it{ entries.find(core::stringUtils::stringToLower(fileExtension.string())) };
auto it{ entries.find(core::stringUtils::stringToLower(fileExtension.c_str())) };
if (it == std::cend(entries))
return "";

Expand Down
2 changes: 1 addition & 1 deletion src/libs/av/impl/Transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace lms::av::transcoding
throw Exception{ "File error '" + _inputParameters.trackPath.string() + "': " + e.what() };
}

LOG(INFO, "Transcoding file '" << _inputParameters.trackPath.string() << "'");
LOG(INFO, "Transcoding file " << _inputParameters.trackPath);

std::vector<std::string> args;

Expand Down
2 changes: 1 addition & 1 deletion src/libs/core/impl/ArchiveZipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ namespace lms::zip
{
assert(_currentEntry != std::cend(_entries));

std::ifstream ifs{ _currentEntry->filePath.c_str(), std::ios_base::binary };
std::ifstream ifs{ _currentEntry->filePath, std::ios_base::binary };
if (!ifs)
throw FileException{ _currentEntry->filePath, "cannot open file", errno };

Expand Down
2 changes: 1 addition & 1 deletion src/libs/core/impl/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace lms::core
{
try
{
_config.readFile(p.string().c_str());
_config.readFile(p.c_str());
}
catch (libconfig::FileIOException& e)
{
Expand Down
8 changes: 4 additions & 4 deletions src/libs/core/impl/FileResourceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ namespace lms
Wt::Http::ResponseContinuation* FileResourceHandler::processRequest(const Wt::Http::Request& request, Wt::Http::Response& response)
{
::uint64_t startByte{ _offset };
std::ifstream ifs{ _path.string().c_str(), std::ios::in | std::ios::binary };
std::ifstream ifs{ _path, std::ios::in | std::ios::binary };

if (startByte == 0)
{
if (!ifs)
{
LMS_LOG(UTILS, ERROR, "Cannot open file stream for '" << _path.string() << "'");
LMS_LOG(UTILS, ERROR, "Cannot open file stream for " << _path);
response.setStatus(404);
return {};
}
Expand All @@ -54,7 +54,7 @@ namespace lms
const ::uint64_t fileSize{ static_cast<::uint64_t>(ifs.tellg()) };
ifs.seekg(0, std::ios::beg);

LMS_LOG(UTILS, DEBUG, "File '" << _path.string() << "', fileSize = " << fileSize);
LMS_LOG(UTILS, DEBUG, "File " << _path << ", fileSize = " << fileSize);

response.addHeader("Accept-Ranges", "bytes");

Expand Down Expand Up @@ -99,7 +99,7 @@ namespace lms
}
else if (!ifs)
{
LMS_LOG(UTILS, ERROR, "Cannot reopen file stream for '" << _path.string() << "'");
LMS_LOG(UTILS, ERROR, "Cannot reopen file stream for " << _path);
return {};
}

Expand Down
10 changes: 5 additions & 5 deletions src/libs/core/impl/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace lms::core::pathUtils
{
core::Crc32Calculator crc32;

std::ifstream ifs{ p.string().c_str(), std::ios_base::binary };
std::ifstream ifs{ p, std::ios_base::binary };
if (ifs)
{
do
Expand All @@ -51,7 +51,7 @@ namespace lms::core::pathUtils
}
else
{
LMS_LOG(DBUPDATER, ERROR, "Failed to open file '" << p.string() << "'");
LMS_LOG(DBUPDATER, ERROR, "Failed to open file " << p);
throw LmsException("Failed to open file '" + p.string() + "'");
}

Expand All @@ -72,7 +72,7 @@ namespace lms::core::pathUtils
{
};

if (stat(file.string().c_str(), &sb) == -1)
if (stat(file.c_str(), &sb) == -1)
throw LmsException("Failed to get stats on file '" + file.string() + "'");

return Wt::WDateTime::fromTime_t(sb.st_mtime);
Expand All @@ -95,7 +95,7 @@ namespace lms::core::pathUtils

if (std::filesystem::exists(excludePath, ec))
{
LMS_LOG(DBUPDATER, DEBUG, "Found '" << excludePath.string() << "': skipping directory");
LMS_LOG(DBUPDATER, DEBUG, "Found " << excludePath << ": skipping directory");
return true;
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace lms::core::pathUtils

bool hasFileAnyExtension(const std::filesystem::path& file, std::span<const std::filesystem::path> supportedExtensions)
{
const std::filesystem::path extension{ stringUtils::stringToLower(file.extension().string()) };
const std::filesystem::path extension{ stringUtils::stringToLower(file.extension().c_str()) };

return (std::find(std::cbegin(supportedExtensions), std::cend(supportedExtensions), extension) != std::cend(supportedExtensions));
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/database/impl/Db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ namespace lms::db
// Session living class handling the database and the login
Db::Db(const std::filesystem::path& dbPath, std::size_t connectionCount)
{
LMS_LOG(DB, INFO, "Creating connection pool on file " << dbPath.string());
LMS_LOG(DB, INFO, "Creating connection pool on file " << dbPath);

auto connection{ std::make_unique<Connection>(dbPath.string()) };
auto connection{ std::make_unique<Connection>(dbPath) };
if (core::IConfig * config{ core::Service<core::IConfig>::get() }) // may not be here on testU
connection->setProperty("show-queries", config->getBool("db-show-queries", false) ? "true" : "false");

Expand Down
5 changes: 0 additions & 5 deletions src/libs/database/impl/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,12 @@ namespace lms::db
if (path.empty())
return path;

// Convert the path to string
std::string pathStr{ path.string() };

// Check if the last character is a directory separator
if (pathStr.back() != std::filesystem::path::preferred_separator)
{
// If not, add the preferred separator
pathStr += std::filesystem::path::preferred_separator;
}

// Return the new path
return std::filesystem::path{ pathStr };
}
} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/libs/database/impl/PlayListFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace lms::db
{
session.checkReadTransaction();

return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<PlayListFile>>("SELECT pl_f from playlist_file pl_f").where("pl_f.absolute_file_path = ?").bind(p.string()));
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<PlayListFile>>("SELECT pl_f from playlist_file pl_f").where("pl_f.absolute_file_path = ?").bind(p));
}

void PlayListFile::find(Session& session, PlayListFileId& lastRetrievedId, std::size_t count, const std::function<void(const pointer&)>& func)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/database/impl/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ namespace lms::db
{
session.checkReadTransaction();

return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Track>>("SELECT t from track t").where("t.absolute_file_path = ?").bind(p.string()));
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Track>>("SELECT t from track t").where("t.absolute_file_path = ?").bind(p));
}

Track::pointer Track::find(Session& session, TrackId id)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/image/impl/EncodedImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace lms::image
{
LMS_SCOPED_TRACE_DETAILED("Image", "ReadFile");

std::ifstream ifs{ p.string(), std::ios::binary };
std::ifstream ifs{ p, std::ios::binary };
if (!ifs.is_open())
throw Exception{ "Cannot open file '" + p.string() + "' for reading purpose" };

Expand Down
2 changes: 1 addition & 1 deletion src/libs/image/impl/graphicsmagick/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace lms::image
{
void init(const std::filesystem::path& path)
{
Magick::InitializeMagick(path.string().c_str());
Magick::InitializeMagick(path.c_str());

if (auto nbThreads{ MagickLib::GetMagickResourceLimit(MagickLib::ThreadsResource) }; nbThreads != 1)
LMS_LOG(COVER, WARNING, "Consider setting env var OMP_NUM_THREADS=1 to save resources");
Expand Down
2 changes: 1 addition & 1 deletion src/libs/image/impl/graphicsmagick/RawImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace lms::image::GraphicsMagick
{
try
{
_image.read(p.string().c_str());
_image.read(p.c_str());
}
catch (Magick::WarningCoder& e)
{
Expand Down
2 changes: 0 additions & 2 deletions src/libs/image/impl/stb/RawImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ namespace lms::image::STB
int n{};
_data = UniquePtrFree{ stbi_load(p.c_str(), &_width, &_height, &n, 3), std::free };
if (!_data)
{
throw StbiException{ "Cannot load image from file" };
}
}

void RawImage::resize(ImageSize width)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/metadata/impl/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ namespace lms::metadata
}
catch (const Exception& e)
{
LMS_LOG(METADATA, ERROR, "File '" << p.string() << "': parsing failed");
LMS_LOG(METADATA, ERROR, "File " << p << ": parsing failed");
throw ParseException{};
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libs/metadata/impl/TagLibTagReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace lms::metadata
{
LMS_SCOPED_TRACE_DETAILED("MetaData", "TagLibParseFile");

return TagLib::FileRef{ p.string().c_str(), true // read audio properties
return TagLib::FileRef{ p.c_str(), true // read audio properties
,
readStyleToTagLibReadStyle(parserReadStyle) };
}
Expand All @@ -199,13 +199,13 @@ namespace lms::metadata
{
if (_file.isNull())
{
LMS_LOG(METADATA, ERROR, "File '" << p.string() << "': parsing failed");
LMS_LOG(METADATA, ERROR, "File " << p << ": parsing failed");
throw ParsingFailedException{};
}

if (!_file.audioProperties())
{
LMS_LOG(METADATA, ERROR, "File '" << p.string() << "': no audio properties");
LMS_LOG(METADATA, ERROR, "File " << p << ": no audio properties");
throw ParsingFailedException{};
}

Expand Down
6 changes: 3 additions & 3 deletions src/libs/services/artwork/impl/ArtworkService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace lms::cover
{
setJpegQuality(core::Service<core::IConfig>::get()->getULong("cover-jpeg-quality", 75));

LMS_LOG(COVER, INFO, "Default release cover path = '" << defaultReleaseCoverSvgPath.string() << "'");
LMS_LOG(COVER, INFO, "Default release cover path = " << defaultReleaseCoverSvgPath);
LMS_LOG(COVER, INFO, "Max cache size = " << _cache.getMaxCacheSize());

_defaultReleaseCover = image::readImage(defaultReleaseCoverSvgPath); // may throw
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace lms::cover
}
catch (const image::Exception& e)
{
LMS_LOG(COVER, ERROR, "Cannot read cover in file '" << p.string() << "': " << e.what());
LMS_LOG(COVER, ERROR, "Cannot read cover in file " << p << ": " << e.what());
}

return image;
Expand Down Expand Up @@ -183,7 +183,7 @@ namespace lms::cover
}
catch (av::Exception& e)
{
LMS_LOG(COVER, ERROR, "Cannot get covers from track " << p.string() << ": " << e.what());
LMS_LOG(COVER, ERROR, "Cannot get covers from track " << p << ": " << e.what());
}

return image;
Expand Down
12 changes: 6 additions & 6 deletions src/libs/services/scanner/impl/scanners/AudioFileScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ namespace lms::scanner
}
catch (const metadata::Exception& e)
{
LMS_LOG(DBUPDATER, INFO, "Failed to parse audio file '" << _file.string() << "'");
LMS_LOG(DBUPDATER, ERROR, "Failed to parse audio file " << _file);
}
}

Expand Down Expand Up @@ -391,7 +391,7 @@ namespace lms::scanner
std::error_code ec;
if (!std::filesystem::exists(otherTrack->getAbsoluteFilePath(), ec))
{
LMS_LOG(DBUPDATER, DEBUG, "Considering track '" << _file.string() << "' moved from '" << otherTrack->getAbsoluteFilePath() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Considering track " << _file << " moved from " << otherTrack->getAbsoluteFilePath());
track = otherTrack;
track.modify()->setAbsoluteFilePath(_file);
}
Expand All @@ -415,7 +415,7 @@ namespace lms::scanner
continue;
}

LMS_LOG(DBUPDATER, DEBUG, "Skipped '" << _file.string() << "' (similar MBID in '" << otherTrack->getAbsoluteFilePath().string() << "')");
LMS_LOG(DBUPDATER, DEBUG, "Skipped " << _file << " (similar MBID in " << otherTrack->getAbsoluteFilePath() << ")");
// As this MBID already exists, just remove what we just scanned
if (track)
{
Expand All @@ -430,7 +430,7 @@ namespace lms::scanner
// We estimate this is an audio file if the duration is not null
if (_parsedTrack->audioProperties.duration == std::chrono::milliseconds::zero())
{
LMS_LOG(DBUPDATER, DEBUG, "Skipped '" << _file.string() << "' (duration is 0)");
LMS_LOG(DBUPDATER, DEBUG, "Skipped " << _file << " (duration is 0)");

// If Track exists here, delete it!
if (track)
Expand Down Expand Up @@ -565,12 +565,12 @@ namespace lms::scanner

if (added)
{
LMS_LOG(DBUPDATER, DEBUG, "Added audio file '" << _file.string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Added audio file " << _file);
stats.additions++;
}
else
{
LMS_LOG(DBUPDATER, DEBUG, "Updated audio file '" << _file.string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Updated audio file " << _file);
stats.updates++;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/libs/services/scanner/impl/scanners/ImageFileScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ namespace lms::scanner
}
catch (const image::Exception& e)
{
LMS_LOG(DBUPDATER, ERROR, "Cannot read image in file '" << _file.c_str() << "': " << e.what());
_parsedImageInfo.reset();
LMS_LOG(DBUPDATER, ERROR, "Cannot read image in file " << _file << ": " << e.what());
}
}

Expand All @@ -101,6 +102,7 @@ namespace lms::scanner
{
image.remove();
stats.deletions++;
LMS_LOG(DBUPDATER, DEBUG, "Removed image " << _file);
}
context.stats.errors.emplace_back(_file, ScanErrorType::CannotReadImageFile);
return;
Expand All @@ -119,12 +121,12 @@ namespace lms::scanner

if (added)
{
LMS_LOG(DBUPDATER, DEBUG, "Added image '" << _file.string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Added image " << _file);
stats.additions++;
}
else
{
LMS_LOG(DBUPDATER, DEBUG, "Updated image '" << _file.string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Updated image " << _file);
stats.updates++;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/libs/services/scanner/impl/scanners/LyricsFileScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ namespace lms::scanner
{
try
{
std::ifstream ifs{ _file.string() };
std::ifstream ifs{ _file };
if (!ifs)
LMS_LOG(DBUPDATER, ERROR, "Cannot open file '" << _file.string() << "'");
LMS_LOG(DBUPDATER, ERROR, "Cannot open file " << _file);
else
_parsedLyrics = metadata::parseLyrics(ifs);
}
catch (const metadata::Exception& e)
{
LMS_LOG(DBUPDATER, ERROR, "Cannot read lyrics in file '" << _file.string() << "': " << e.what());
LMS_LOG(DBUPDATER, ERROR, "Cannot read lyrics in file " << _file << ": " << e.what());
}
}

Expand Down Expand Up @@ -122,12 +122,12 @@ namespace lms::scanner

if (added)
{
LMS_LOG(DBUPDATER, DEBUG, "Added external lyrics '" << _file.string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Added external lyrics " << _file);
stats.additions++;
}
else
{
LMS_LOG(DBUPDATER, DEBUG, "Updated external lyrics '" << _file.string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Updated external lyrics " << _file);
stats.updates++;
}
}
Expand Down
Loading

0 comments on commit 10d900f

Please sign in to comment.