From b39ab15659ebc26701157731b6089b832a596ffd Mon Sep 17 00:00:00 2001 From: Scott Gilbertson Date: Mon, 19 Feb 2024 11:35:46 -0500 Subject: [PATCH] Eliminated use of stat() instead using Gio::FileInfo to get file modification date --- rtgui/batchqueue.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 622124be4..2d46d9766 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -18,7 +18,6 @@ */ #include #include -#include #include #include #include "../rtengine/imagedata.h" @@ -99,7 +98,7 @@ namespace // local helper functions // Look in templateText at index ix for quoted string containing a time format string, and // use that string to format dateTime. Append the formatted time to path. - void appendFormattedTime(Glib::ustring& path, unsigned int& ix, Glib::ustring& templateText, const Glib::DateTime& dateTime) + void appendFormattedTime(Glib::ustring& path, unsigned int& ix, const Glib::ustring& templateText, const Glib::DateTime& dateTime) { constexpr unsigned int quoteMark = (unsigned int)'"'; if ((ix + 1) < templateText.size() && templateText[ix] == quoteMark) { @@ -1030,12 +1029,16 @@ Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileNam break; case 'F': // time when file was last saved { - struct stat fileStat; - if (stat(origFileName.c_str(), &fileStat) == 0) { - time_t timestamp = fileStat.st_mtime; - dateTime = Glib::DateTime::create_now_local(timestamp); - } else { - dateTimeIsValid = false; // file not found, access denied, etc. + dateTimeIsValid = false; // becomes true below if no errors + Glib::RefPtr file = Gio::File::create_for_path(origFileName); + if (file) { + Glib::RefPtr info = file->query_info("time::modified"); + if (info) { + dateTime = info->get_modification_date_time(); + if (dateTime) { + dateTimeIsValid = true; + } + } } } break;