Skip to content
Snippets Groups Projects
Commit f680064f authored by Adrien Béraud's avatar Adrien Béraud
Browse files

fileutils: avoid throwing exception if file doesn't exist

Preserve pre-std::filesystem behavior of returning null if operation fails.

Change-Id: I76414a73f8aa0a74640b92c27c753f0311d86380
parent 74916fa3
No related branches found
No related tags found
No related merge requests found
...@@ -811,9 +811,13 @@ accessFile(const std::string& file, int mode) ...@@ -811,9 +811,13 @@ accessFile(const std::string& file, int mode)
uint64_t uint64_t
lastWriteTimeInSeconds(const std::filesystem::path& filePath) lastWriteTimeInSeconds(const std::filesystem::path& filePath)
{ {
return std::chrono::duration_cast<std::chrono::seconds>( std::error_code ec;
std::filesystem::last_write_time(filePath).time_since_epoch()) auto lastWrite = std::filesystem::last_write_time(filePath, ec);
.count(); if (ec) {
JAMI_WARNING("Unable to get last write time of {}: {}", filePath, ec.message());
return 0;
}
return std::chrono::duration_cast<std::chrono::seconds>(lastWrite.time_since_epoch()).count();
} }
} // namespace fileutils } // namespace fileutils
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment