Use std::filesystem for fileExist

This commit is contained in:
Luis Díaz Más 2022-02-16 18:01:38 +01:00
parent f1ff3aaa4c
commit 6f762b4e66
5 changed files with 40 additions and 42 deletions

View File

@ -268,7 +268,7 @@ namespace Action {
int Print::printSummary()
{
if (!Exiv2::fileExists(path_, true)) {
if (!Exiv2::fileExists(path_)) {
std::cerr << path_ << ": " << _("Failed to open the file\n");
return -1;
}
@ -402,7 +402,7 @@ namespace Action {
int Print::printList()
{
if (!Exiv2::fileExists(path_, true)) {
if (!Exiv2::fileExists(path_)) {
std::cerr << path_ << ": " << _("Failed to open the file\n");
return -1;
}
@ -607,7 +607,7 @@ namespace Action {
int Print::printComment()
{
if (!Exiv2::fileExists(path_, true)) {
if (!Exiv2::fileExists(path_)) {
std::cerr << path_ << ": " << _("Failed to open the file\n");
return -1;
}
@ -624,7 +624,7 @@ namespace Action {
int Print::printPreviewList()
{
if (!Exiv2::fileExists(path_, true)) {
if (!Exiv2::fileExists(path_)) {
std::cerr << path_ << ": " << _("Failed to open the file\n");
return -1;
}
@ -658,7 +658,7 @@ namespace Action {
int Rename::run(const std::string& path)
{
try {
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path << ": " << _("Failed to open the file\n");
return -1;
}
@ -740,7 +740,7 @@ namespace Action {
try {
path_ = path;
if (!Exiv2::fileExists(path_, true)) {
if (!Exiv2::fileExists(path_)) {
std::cerr << path_ << ": " << _("Failed to open the file\n");
return -1;
}
@ -900,7 +900,7 @@ namespace Action {
int Extract::writeThumbnail() const
{
if (!Exiv2::fileExists(path_, true)) {
if (!Exiv2::fileExists(path_)) {
std::cerr << path_ << ": " << _("Failed to open the file\n");
return -1;
}
@ -947,7 +947,7 @@ namespace Action {
int Extract::writePreviews() const
{
if (!Exiv2::fileExists(path_, true)) {
if (!Exiv2::fileExists(path_)) {
std::cerr << path_ << ": " << _("Failed to open the file\n");
return -1;
}
@ -983,7 +983,7 @@ namespace Action {
int Extract::writeIccProfile(const std::string& target) const
{
int rc = 0;
if (!Exiv2::fileExists(path_, true)) {
if (!Exiv2::fileExists(path_)) {
std::cerr << path_ << ": " << _("Failed to open the file\n");
rc = -1;
}
@ -1049,7 +1049,7 @@ namespace Action {
// -i{tgt}- reading from stdin?
bool bStdin = (Params::instance().target_ & Params::ctStdInOut) != 0;
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path
<< ": " << _("Failed to open the file\n");
return -1;
@ -1106,12 +1106,12 @@ namespace Action {
Params::instance().getStdin(xmpBlob);
rc = insertXmpPacket(path,xmpBlob,true);
} else {
if (!Exiv2::fileExists(xmpPath, true)) {
if (!Exiv2::fileExists(xmpPath)) {
std::cerr << xmpPath
<< ": " << _("Failed to open the file\n");
rc = -1;
}
if (rc == 0 && !Exiv2::fileExists(path, true)) {
if (rc == 0 && !Exiv2::fileExists(path)) {
std::cerr << path
<< ": " << _("Failed to open the file\n");
rc = -1;
@ -1152,7 +1152,7 @@ namespace Action {
Params::instance().getStdin(iccProfile);
rc = insertIccProfile(path,std::move(iccProfile));
} else {
if (!Exiv2::fileExists(iccProfilePath, true)) {
if (!Exiv2::fileExists(iccProfilePath)) {
std::cerr << iccProfilePath
<< ": " << _("Failed to open the file\n");
rc = -1;
@ -1168,7 +1168,7 @@ namespace Action {
{
int rc = 0;
// test path exists
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path << ": " << _("Failed to open the file\n");
rc=-1;
}
@ -1192,12 +1192,12 @@ namespace Action {
int Insert::insertThumbnail(const std::string& path)
{
std::string thumbPath = newFilePath(path, "-thumb.jpg");
if (!Exiv2::fileExists(thumbPath, true)) {
if (!Exiv2::fileExists(thumbPath)) {
std::cerr << thumbPath
<< ": " << _("Failed to open the file\n");
return -1;
}
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path
<< ": " << _("Failed to open the file\n");
return -1;
@ -1220,7 +1220,7 @@ namespace Action {
int Modify::run(const std::string& path)
{
try {
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path << ": " << _("Failed to open the file\n");
return -1;
}
@ -1452,7 +1452,7 @@ namespace Action {
monthAdjustment_ = Params::instance().yodAdjust_[Params::yodMonth].adjustment_;
dayAdjustment_ = Params::instance().yodAdjust_[Params::yodDay].adjustment_;
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path << ": " << _("Failed to open the file\n");
return -1;
}
@ -1579,7 +1579,7 @@ namespace Action {
int FixIso::run(const std::string& path)
{
try {
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path << ": " <<_("Failed to open the file\n");
return -1;
}
@ -1632,7 +1632,7 @@ namespace Action {
int FixCom::run(const std::string& path)
{
try {
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path << ": " <<_("Failed to open the file\n");
return -1;
}
@ -1821,7 +1821,7 @@ namespace {
// read the source metadata
int rc = -1 ;
if (!Exiv2::fileExists(source, true)) {
if (!Exiv2::fileExists(source)) {
std::cerr << source << ": " << _("Failed to open the file\n");
return rc;
}
@ -2096,7 +2096,7 @@ namespace {
int printStructure(std::ostream& out, Exiv2::PrintStructureOption option, const std::string &path)
{
if (!Exiv2::fileExists(path, true)) {
if (!Exiv2::fileExists(path)) {
std::cerr << path << ": "
<< _("Failed to open the file\n");
return -1;

View File

@ -114,7 +114,7 @@ namespace Exiv2
and its type, see stat(2). <b>errno</b> is left unchanged
in case of an error.
*/
EXIV2API bool fileExists(const std::string& path, bool ct = false);
EXIV2API bool fileExists(const std::string& path);
/*!
@brief Get the path of file URL.

View File

@ -27,19 +27,23 @@
#include "image_int.hpp"
// + standard includes
#include <sys/types.h>
#include <sys/stat.h>
#include <array>
#include <cstdio>
#include <cerrno>
#include <sstream>
#include <cstring>
#include <sys/types.h>
#include <algorithm>
#include <array>
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <sstream>
#include <stdexcept>
#ifdef EXV_HAVE_UNISTD_H
#include <unistd.h> // for stat()
#ifdef EXV_HAVE_UNISTD_H
#include <unistd.h> // for stat()
#endif
namespace fs = std::filesystem;
#if defined(WIN32)
#include <windows.h>
#include <psapi.h> // For access to GetModuleFileNameEx
@ -243,19 +247,13 @@ namespace Exiv2 {
return result;
} // fileProtocol
bool fileExists(const std::string& path, bool ct)
bool fileExists(const std::string& path)
{
// special case: accept "-" (means stdin)
if (path == "-" || fileProtocol(path) != pFile) {
if (fileProtocol(path) != pFile) {
return true;
}
struct stat buf;
int ret = ::stat(path.c_str(), &buf);
if (0 != ret) return false;
if (ct && !S_ISREG(buf.st_mode)) return false;
return true;
} // fileExists
return fs::exists(path);
}
std::string pathOfFileUrl(const std::string& url) {
std::string path = url.substr(7);

View File

@ -139,7 +139,7 @@ static void output(std::ostream& os,const std::vector<std::regex>& greps,const c
static bool pushPath(std::string& path,std::vector<std::string>& libs,std::set<std::string>& paths)
{
bool result = Exiv2::fileExists(path,true) && paths.find(path) == paths.end() && path != "/" ;
bool result = Exiv2::fileExists(path) && paths.find(path) == paths.end() && path != "/" ;
if ( result ) {
paths.insert(path);
libs.push_back(path);

Binary file not shown.