From 41e9ec6bc3d4494ba520144509f5f11e1e218de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Garramu=C3=B1o?= Date: Tue, 17 Dec 2024 16:42:37 -0300 Subject: [PATCH] Added more checking and verbose messages to image versioning. --- src/lib/mrvCore/mrvFile.cpp | 5 ++++ src/lib/mrvCore/mrvFile.h | 9 +++++++ src/lib/mrvFl/mrvVersioning.cpp | 45 ++++++++++++++++++++++++++++----- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/lib/mrvCore/mrvFile.cpp b/src/lib/mrvCore/mrvFile.cpp index 93d5f6ea8..264ebf7fd 100644 --- a/src/lib/mrvCore/mrvFile.cpp +++ b/src/lib/mrvCore/mrvFile.cpp @@ -137,6 +137,11 @@ namespace mrv return fs::is_directory(dir); } + bool exists(const fs::path& filePath) + { + return fs::exists(filePath); + } + bool isReadable(const fs::path& p) { const std::string& filePath = p.generic_string(); diff --git a/src/lib/mrvCore/mrvFile.h b/src/lib/mrvCore/mrvFile.h index f71a3522f..0ec8d07f1 100644 --- a/src/lib/mrvCore/mrvFile.h +++ b/src/lib/mrvCore/mrvFile.h @@ -125,6 +125,15 @@ namespace mrv */ bool isDirectory(const std::string& directory); + /** + * Return true if the file exists and is readable + * + * @param p std::filesystem path (or std::string). + * + * @return true if it exists and is readable, false if not. + */ + bool exists(const fs::path& path); + /** * Return true if the file exists and is readable * diff --git a/src/lib/mrvFl/mrvVersioning.cpp b/src/lib/mrvFl/mrvVersioning.cpp index c094a62c2..1d0033620 100644 --- a/src/lib/mrvFl/mrvVersioning.cpp +++ b/src/lib/mrvFl/mrvVersioning.cpp @@ -86,7 +86,6 @@ namespace mrv std::string msg; std::string file = path.get(); - replace_path(file); while ((first_or_last || found == false) && tries <= max_tries) @@ -146,12 +145,46 @@ namespace mrv newfile += suffix; - if (file::isReadable(newfile)) + + if (file::isNetwork(newfile)) + { + msg = tl::string::Format(_("File {0} is a network file. " + "Cannot do versioning.")) + .arg(newfile); + LOG_ERROR(msg); + return file; + } + + + if (file::exists(newfile)) + { + msg = tl::string::Format( + _("Found new versioned file {0}.")) + .arg(newfile); + LOG_INFO(msg); + + if (file::isReadable(newfile)) + { + loadfile = newfile; + found = true; + if (!first_or_last) + break; + } + else + { + msg = tl::string::Format( + _("File {0} found but is not readable.")) + .arg(newfile); + LOG_ERROR(msg); + return file; + } + } + else { - loadfile = newfile; - found = true; - if (!first_or_last) - break; + msg = tl::string::Format( + _("Did not find new versioned file {0}.")) + .arg(newfile); + LOG_INFO(msg); } file = newfile;