Simplified some path writes

This commit is contained in:
emeric
2025-01-06 22:29:46 +01:00
parent 06a4db51f7
commit 10d900faf2
25 changed files with 59 additions and 65 deletions
+4 -4
View File
@@ -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 };
}
@@ -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 "";
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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 };
+1 -1
View File
@@ -32,7 +32,7 @@ namespace lms::core
{
try
{
_config.readFile(p.string().c_str());
_config.readFile(p.c_str());
}
catch (libconfig::FileIOException& e)
{
+4 -4
View File
@@ -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 {};
}
@@ -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");
@@ -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 {};
}
+5 -5
View File
@@ -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
@@ -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() + "'");
}
@@ -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);
@@ -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;
}
}
@@ -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));
}
+2 -2
View File
@@ -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");
-5
View File
@@ -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
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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" };
+1 -1
View File
@@ -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");
@@ -54,7 +54,7 @@ namespace lms::image::GraphicsMagick
{
try
{
_image.read(p.string().c_str());
_image.read(p.c_str());
}
catch (Magick::WarningCoder& e)
{
-2
View File
@@ -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)
+1 -1
View File
@@ -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{};
}
}
+3 -3
View File
@@ -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) };
}
@@ -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{};
}
@@ -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
@@ -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;
@@ -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;
@@ -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);
}
}
@@ -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);
}
@@ -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)
{
@@ -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)
@@ -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++;
}
}
@@ -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());
}
}
@@ -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;
@@ -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++;
}
}
@@ -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());
}
}
@@ -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++;
}
}
@@ -66,15 +66,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
_parsedPlayList = metadata::parsePlayList(ifs);
}
catch (const metadata::Exception& e)
{
LMS_LOG(DBUPDATER, ERROR, "Cannot read playlist in file '" << _file.string() << "': " << e.what());
LMS_LOG(DBUPDATER, ERROR, "Cannot read playlist in file " << _file << ": " << e.what());
}
}
@@ -120,13 +120,12 @@ namespace lms::scanner
if (added)
{
LMS_LOG(DBUPDATER, DEBUG, "Added playlist file '" << _file.string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "db playlist file = '" << playList->getAbsoluteFilePath().string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Added playlist file " << _file);
stats.additions++;
}
else
{
LMS_LOG(DBUPDATER, DEBUG, "Updated playlist file '" << _file.string() << "'");
LMS_LOG(DBUPDATER, DEBUG, "Updated playlist file '" << _file);
stats.updates++;
}
}
@@ -53,7 +53,7 @@ namespace lms::scanner
{
{
LMS_SCOPED_TRACE_OVERVIEW("Scanner", operation->getName());
LMS_LOG(DBUPDATER, DEBUG, operation->getName() << ": scanning file '" << operation->getFile().string() << "'");
LMS_LOG(DBUPDATER, DEBUG, operation->getName() << ": scanning file " << operation->getFile());
operation->scan();
}
@@ -57,7 +57,7 @@ namespace lms::scanner
{
[[maybe_unused]] auto [it, inserted]{ _scannerByExtension.emplace(extension, scanner) };
assert(inserted);
LMS_LOG(DBUPDATER, INFO, "Registered extension '" << extension.string() << "' for '" << scanner->getName() << "'");
LMS_LOG(DBUPDATER, INFO, "Registered extension " << extension << " for " << scanner->getName());
}
}
@@ -88,12 +88,12 @@ namespace lms::scanner
if (ec)
{
LMS_LOG(DBUPDATER, ERROR, "Cannot scan file '" << path.string() << "': " << ec.message());
LMS_LOG(DBUPDATER, ERROR, "Cannot scan file " << path << ": " << ec.message());
context.stats.errors.emplace_back(ScanError{ path, ScanErrorType::CannotReadFile, ec.message() });
}
else
{
auto itScanner{ _scannerByExtension.find(core::stringUtils::stringToLower(path.extension().string())) };
auto itScanner{ _scannerByExtension.find(core::stringUtils::stringToLower(path.extension().c_str())) };
if (itScanner != std::cend(_scannerByExtension))
{
IFileScanner& scanner{ *itScanner->second };
@@ -140,7 +140,7 @@ namespace lms::scanner
if (_abortScan)
return;
LMS_LOG(DBUPDATER, DEBUG, scanOperation->getName() << ": processing result for '" << scanOperation->getFile().string() << "'");
LMS_LOG(DBUPDATER, DEBUG, scanOperation->getName() << ": processing result for " << scanOperation->getFile());
scanOperation->processResult(context);
context.stats.scans++;
}
+1 -1
View File
@@ -178,7 +178,7 @@ namespace lms
}
{
std::ofstream oss{ wtConfigPath.string().c_str(), std::ios::out };
std::ofstream oss{ wtConfigPath, std::ios::out };
if (!oss)
throw core::LmsException{ "Can't open '" + wtConfigPath.string() + "' for writing!" };
+2 -2
View File
@@ -365,14 +365,14 @@ int main(int argc, char* argv[])
{
std::cout << "Using Lyrics:" << std::endl;
std::ifstream ifs{ file.string() };
std::ifstream ifs{ file };
if (ifs)
{
const metadata::Lyrics lyrics{ metadata::parseLyrics(ifs) };
std::cout << lyrics << std::endl;
}
else
std::cerr << "Cannot open file '" << file.string() << "'";
std::cerr << "Cannot open file " << file;
}
catch (metadata::Exception& e)
{