From 49afdb3db607139ec8f9e38282611049de69b1d6 Mon Sep 17 00:00:00 2001 From: emeric Date: Mon, 7 Jul 2025 13:44:50 +0200 Subject: [PATCH] Removed useless stat call --- src/libs/core/impl/Path.cpp | 10 ++++++---- src/libs/core/include/core/Path.hpp | 7 ++++++- .../services/scanner/impl/steps/ScanStepScanFiles.cpp | 10 ++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/libs/core/impl/Path.cpp b/src/libs/core/impl/Path.cpp index 248042c7..47f717a3 100644 --- a/src/libs/core/impl/Path.cpp +++ b/src/libs/core/impl/Path.cpp @@ -67,9 +67,9 @@ namespace lms::core::pathUtils return std::filesystem::create_directory(dir); } - Wt::WDateTime getLastWriteTime(const std::filesystem::path& file, std::error_code& ec) + FileInfo getFileInfo(const std::filesystem::path& file, std::error_code& ec) { - Wt::WDateTime res; + FileInfo fileInfo; struct stat sb { @@ -81,10 +81,11 @@ namespace lms::core::pathUtils else { ec = std::error_code{}; - res = Wt::WDateTime::fromTime_t(sb.st_mtime); + fileInfo.lastWriteTime = Wt::WDateTime::fromTime_t(sb.st_mtime); + fileInfo.fileSize = sb.st_size; } - return res; + return fileInfo; } bool exploreFilesRecursive(const std::filesystem::path& directory, std::function cb, const std::filesystem::path* excludeDirFileName) @@ -120,6 +121,7 @@ namespace lms::core::pathUtils } else { + // TODO get status once and then test regular file/directory if (std::filesystem::is_regular_file(*itPath, ec)) { continueExploring = cb(ec, *itPath); diff --git a/src/libs/core/include/core/Path.hpp b/src/libs/core/include/core/Path.hpp index 1d9688bd..704c5e77 100644 --- a/src/libs/core/include/core/Path.hpp +++ b/src/libs/core/include/core/Path.hpp @@ -34,8 +34,13 @@ namespace lms::core::pathUtils // Create it if needed bool ensureDirectory(const std::filesystem::path& dir); + struct FileInfo + { + Wt::WDateTime lastWriteTime; // Last write time of the file since Epoch + std::uint64_t fileSize{}; // Size of the file in bytes + }; // Get the last write time since Epoch - Wt::WDateTime getLastWriteTime(const std::filesystem::path& file, std::error_code& ec); + FileInfo getFileInfo(const std::filesystem::path& file, std::error_code& ec); // returns false if aborted by user bool exploreFilesRecursive(const std::filesystem::path& directory, std::function cb, const std::filesystem::path* excludeDirFileName = {}); diff --git a/src/libs/services/scanner/impl/steps/ScanStepScanFiles.cpp b/src/libs/services/scanner/impl/steps/ScanStepScanFiles.cpp index 19c4ed85..69128b98 100644 --- a/src/libs/services/scanner/impl/steps/ScanStepScanFiles.cpp +++ b/src/libs/services/scanner/impl/steps/ScanStepScanFiles.cpp @@ -71,16 +71,14 @@ namespace lms::scanner { FileToScan res; - res.lastWriteTime = core::pathUtils::getLastWriteTime(file, ec); - if (!ec) - res.relativePath = std::filesystem::relative(file, mediaLibrary.rootDirectory, ec); - if (!ec) - res.fileSize = std::filesystem::file_size(file, ec); - + const core::pathUtils::FileInfo fileInfo{ core::pathUtils::getFileInfo(file, ec) }; if (!ec) { res.filePath = file; res.mediaLibrary = mediaLibrary; + res.relativePath = std::filesystem::relative(file, mediaLibrary.rootDirectory, ec); + res.lastWriteTime = fileInfo.lastWriteTime; + res.fileSize = fileInfo.fileSize; } return res;