Eliminated use of stat() instead using Gio::FileInfo to get file modification date

This commit is contained in:
Scott Gilbertson
2024-02-19 11:35:46 -05:00
parent 547ac41ad4
commit b39ab15659

View File

@@ -18,7 +18,6 @@
*/ */
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <sys/stat.h>
#include <cstring> #include <cstring>
#include <functional> #include <functional>
#include "../rtengine/imagedata.h" #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 // 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. // 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)'"'; constexpr unsigned int quoteMark = (unsigned int)'"';
if ((ix + 1) < templateText.size() && templateText[ix] == quoteMark) { if ((ix + 1) < templateText.size() && templateText[ix] == quoteMark) {
@@ -1030,12 +1029,16 @@ Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileNam
break; break;
case 'F': // time when file was last saved case 'F': // time when file was last saved
{ {
struct stat fileStat; dateTimeIsValid = false; // becomes true below if no errors
if (stat(origFileName.c_str(), &fileStat) == 0) { Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(origFileName);
time_t timestamp = fileStat.st_mtime; if (file) {
dateTime = Glib::DateTime::create_now_local(timestamp); Glib::RefPtr<Gio::FileInfo> info = file->query_info("time::modified");
} else { if (info) {
dateTimeIsValid = false; // file not found, access denied, etc. dateTime = info->get_modification_date_time();
if (dateTime) {
dateTimeIsValid = true;
}
}
} }
} }
break; break;